江苏开放大学NET平台与C#程序设计第四次形考作业

实验名称:

一、实验目的及要求

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());

}

}

}

五、实验结果(程序运行结果等,可附截图)

1604972876(1)

1604972943(1)

1604972981(1)

1604972995(1)

1604973011(1)

1604973061(1)

六、实验小结

1. 掌握了使用文本框、按钮、标签、复选框、单选按钮等控件

2. 学会了查找和修正语法错误

评阅意见:

 

评阅得分:

 

评阅教师:

评阅时间:

资源下载
下载价格15
点点赞赏,手留余香 给TA打赏

评论2

请先
  1. 代码不全,只有一半作业
    已购买 2024-05-12 0
    • 我們核對一下再重新補一下哈
      zx 2024-05-13 0
支持多种货币
支持多种货币付款,满足您的付款需求
7天无忧退换
安心无忧购物,售后有保障
专业客服服务
百名资深客服7*24h在线服务
发货超时赔付
交易成功极速发货,专业水准保证时效性

站点公告

开放大学课程作业代写,有需要扫码加微信

显示验证码

社交账号快速登录

微信扫一扫关注
扫码关注后会自动登录