网站建设分为哪几种类型,优秀校园网站建设汇报,家里电脑做网站,系统下载网站源码实验四#xff1a;C#实现商品信息的显示异常处理
任务要求#xff1a;
在进销存管理系统中#xff0c;商品的库存信息有很多种类#xff0c;比如商品型号、商品名称、商品库存量等。在面向对象编程中#xff0c;这些商品的信息可以存储到属性中#xff0c;然后当需要使…
实验四C#实现商品信息的显示异常处理
任务要求
在进销存管理系统中商品的库存信息有很多种类比如商品型号、商品名称、商品库存量等。在面向对象编程中这些商品的信息可以存储到属性中然后当需要使用这些信息时再从对应的属性中读取出来。这里要求定义库存商品结构并输出库存商品的信息。 整体框架 实现步骤
第一步创建cstockInfo类并设置如下变量 第二步按照如下内容定义商品的13个属性。 第三步创建cstockInfo类构造函数并对商品属性进行初始化 第四步创建显示商品信息函数 第五步Main函数中输出标题 第六步创建商品对象从键盘输入商品编号、单位全称、商品型号、库存数量四个数据并显示商品信息(自行补充) 第九步实现对商品输入内容的约束并进行异常处理。(自行补充)
1、库存数量数字区间范围1-1000
2、商品规格“字符”“-”“数字”组成。如TYPE-3
第九步实现对商品信息多次输入并进行判断输入“q”退出程序。(自行补充)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApp1
{class Program{static void Main(string[] args){Console.WriteLine(库存盘点信息如下:);cStockInfo csi1 new cStockInfo();csi1.TradeCode TJRA001;csi1.FullName 空调;csi1.TradeType TYPE-1;csi1.Standard 2匹;csi1.Unit 台;csi1.Produce 天津;csi1.Qty 200;csi1.Price 2000;csi1.AveragePrice 2500;csi1.SalePrice 3000;csi1.Check 200;csi1.UpperLimit 800;csi1.LowerLimit 200;csi1.ShowInfo();cStockInfo csi2 new cStockInfo();csi2.TradeCode TJRA002;csi2.FullName 空调;csi2.TradeType TYPE-2;csi2.Standard 1.5匹;csi2.Unit 台;csi2.Produce 天津;csi2.Qty 300;csi2.Price 3000;csi2.AveragePrice 3500;csi2.SalePrice 4000;csi2.Check 290;csi2.ShowInfo();cStockInfo csi3 new cStockInfo();csi3.TradeCode TJRA003;csi3.TradeType TYPE-3;csi3.ShowInfo();Console.ReadLine(); ConsoleKey Key;do{Key Console.ReadKey().Key;} while (Key ! ConsoleKey.Q);}}public class cStockInfo{private string tradecode ;private string fullname ;private string tradetype ;private string standard ;private string tradeunit ;private string produce ;private float qty 0;private float price 0;private float averageprice 0;private float saleprice 0;private float check 0;private float upperlimit 0;private float lowerlimit 0;public string TradeCode{get { return tradecode; }set { tradecode value; }}public string FullName{get { return fullname; }set { fullname value; }}public string TradeType{get { return tradetype; }set { tradetype value; }}public string Standard{get { return standard; }set { standard value; }}public string Unit{get { return tradeunit; }set { tradeunit value; }}public string Produce{get { return produce; }set { produce value; }}public float Qty{get { return qty; }set { qty value; }}public float Price{get { return price; }set { price value; }}public float AveragePrice{get { return averageprice; }set { averageprice value; }}public float SalePrice{get { return saleprice; }set { saleprice value; }}public float Check{get { return check; }set { check value; }}public float UpperLimit{get { return upperlimit; }set { upperlimit value; }}public float LowerLimit{get { return lowerlimit; }set { lowerlimit value; }}public cStockInfo(){this.TradeCode TJRA001;this.FullName 空调;this.TradeType TYPE-2;this.Standard 2匹;this.Unit 台;this.Produce 天津;this.Qty 200;this.Price 2000;this.AveragePrice 2500;this.SalePrice 3000;this.Check 200;this.UpperLimit 900;this.LowerLimit 100;}public void ShowInfo(){Console.WriteLine(------------------------------------------);Console.WriteLine(显示商品信息);Console.WriteLine();Console.Write(商品编号{0,-15}, TradeCode);Console.Write(单位全称{0,-15}, FullName);Console.Write(商品型号{0,-15}, TradeType);Console.WriteLine();Console.Write(商品规格{0,-15}, Standard);Console.Write(商品单位{0,-15}, Unit);Console.Write(商品产地{0,-15}, Produce);Console.Write(库存数量{0,-15}, Qty);Console.WriteLine();Console.Write(最后一次价格{0,-15:C}, Price);Console.Write(加权平均价格{0,-15:C}, AveragePrice);Console.Write(最后一次销售{0,-15:C}, SalePrice);Console.WriteLine();Console.Write(盘点数量{0,-15}, Check);Console.Write(库存报警上限{0,-15}, UpperLimit);Console.Write(库存报警下限{0,-15}, LowerLimit);Console.WriteLine();Console.WriteLine(商品信息显示完毕);Console.WriteLine(------------------------------------------);}}}