实验名称:
一、实验目的及要求
1. 使用文本框、按钮、标签、复选框、单选按钮等控件
2. 查找和修正语法错误
二、实验内容
1. 设计与演示普通自助用餐费用预算功能的实现
2. 设计与演示宴会用餐费用预算功能的实现
三、实验设备及环境
1.安装visual studio2010软件
四、实验步骤(功能实现的核心代码及说明)
本实验以综合实验讲义中的案例作为本次形考作业,
任务一:实现启动“订餐小精灵”的设计设计与开发,实现普通自助用餐费用预算功能,程序运行默认状态图、改变选项值后的效果图、用餐人数为50的程序运行效果图、当前输入用餐人数超过40人时的程序运行效果图
把实验的相关代码复制到word文档中,并把代码运行的相关运行结果图截屏存放在代码的下面。
using System;
public class Customer
{
public string customerName;//姓名
public bool memberOption;//是否会员
public string phoneNumber;//联系电话
public void SetMemberOption(bool option)
{
memberOption = option;
}
}
using System;
using System.Windows.Forms;
public class Dinner
{
public const string type = “自助用餐”;//用餐类型
public const int costOfFoodPerPerson = 35;//人均食品费用
public decimal costOfBeveragesPerPerson;//人均饮料费用
public Customer customer;//客户
public DateTime date;//日期时间
private decimal cost;//总费用
public decimal Cost
{
get { return cost; }
set { cost = value; }
}
private int numberOfPeople;//用餐人数
public int NumberOfPeople
{
get { return numberOfPeople; }
set
{
if(value>40)
{
MessageBox.Show(“超过40人,无法下订单”);
return;
}
else
{
numberOfPeople = value;
}
}
}
public Dinner(int numberOfPecple)
{
customer = new Customer();
this.numberOfPeople = numberOfPecple;//初始化人数为5
}
public void SetWineOption(bool wineOption)
{//人均饮料费
if (wineOption)
{
costOfBeveragesPerPerson = 40.00M;
}
else
{
costOfBeveragesPerPerson = 15.00M;
}
}
public decimal CalculateCost()//返回总费用
{
decimal totalCost = (costOfFoodPerPerson + costOfBeveragesPerPerson) * numberOfPeople;
if (customer.memberOption)
{
this.cost = totalCost * 0.85M;
return totalCost * 0.85M;
}
else
{
this.cost = totalCost;
return totalCost;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpiritKitchen
{
public partial class SpiritKitchen : Form
{
Dinner dinner;
public SpiritKitchen()
{
InitializeComponent();
dinner = new Dinner((int)dinnerNumericUpDown.Value);
dinner.SetWineOption(dinnerWinerCheckBox.Checked);//人均饮料费用
DisplayDinnerCost();//总费用
}
private void DisplayDinnerCost()
{
decimal Cost = dinner.CalculateCost();
CostLabel.Text = Cost.ToString(“c”);
}
private void dinnerNumericUpDown_ValueChanged(object sender, EventArgs e)
{
dinner.NumberOfPeople = (int)dinnerNumericUpDown.Value;//设置用餐人数
DisplayDinnerCost();//总费用
}
private void dinnerMemberCheckBox_CheckedChanged(object sender, EventArgs e)
{
dinner.customer.SetMemberOption(dinnerMemberCheckBox.Checked);//设置客户是否为会员
DisplayDinnerCost();//总费用
}
private void dinnerWinerCheckBox_CheckedChanged(object sender, EventArgs e)
{
dinner.SetWineOption(dinnerWinerCheckBox.Checked);//设置是否饮用酒水
DisplayDinnerCost();//总费用
}
private void cancaBbutton_Click(object sender, EventArgs e)
{
Close();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpiritKitchen
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SpiritKitchen());
}
}
}
五、实验结果(程序运行结果等,可附截图)
六、实验小结
1. 掌握了使用文本框、按钮、标签、复选框、单选按钮等控件
2. 学会了查找和修正语法错误
评阅意见:
评阅得分:
评阅教师:
评阅时间:
评论2