C#编写快递运费计算小程序 您所在的位置:网站首页 鸿泰物流运费计算 C#编写快递运费计算小程序

C#编写快递运费计算小程序

2023-06-28 23:55| 来源: 网络整理| 查看: 265

我们寄快递时,针对普通货物快递公司都会根据所寄货物的重量和目的地来计算运费,因此设计一个“快递运费计算程序”,使程序的操作人员(如收费员等)可以通过菜单提示完成对不同种类快递货物的数据录入、运费计算、信息查询及快递信息统计并能自动产生快递单号。

 

 程序中需设置的变量有:

当天能处理的最大快递总数(常量):MAX

当天已经处理的快递个数:number

操作密码(常变量):Password=1234

操作员密码:password

操作员密码输入次数:n

用户选择的菜单项目:choice

目的地区域 area

存放快递信息的数组 cargo[MAX+1]

数组下标变量:i

快递总重量:totalweight

快递总运费:totalcharge

临时变量:num,name

通对操作人员的身分进行验证(密码认证) 提示操作员输入密码,判断密码是否正确,如果不正确退出程序。如果正确,显示“欢迎进入” 

显示系统功能菜单: 在屏幕上显示如下信息:

根据快递收费标准,货物所在的区域不同,首重续重的金额是不同的,但运费都可用以下公式进行计算: 运费=(int)(重量+(double)首重单价/续重单价-0.01)*续重单价 所以我们可以根据区域和重量分段计算货物的运费,可采用if-else if语句或switch语句实现。 

本通过switch循环来进行主界面相关操作的执行

 本程序主要由三部分——主函数、相关数据与计算、主界面组成

主函数:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ExpressFreightCalculation { internal class Program { static void Main(string[] args) { if (Test.Pass())//调用登录方法 { Console.WriteLine("密码正确,欢迎进入!"); Console.ReadKey(); } else { Console.WriteLine("你是非法用户,程序退出!"); Console.ReadKey(); return; } while (true) { switch (Test.Menu()) { case 0: Test.Exit();//返回操作系统(退出程序) break; case 1: Test.Input();//录入数据 break; case 2: Test.Search();//查询快递 break; case 3: Test.Count();//计算当日总的重量和价格 break; case 4: Test.Output();//具体显示每个快递相关内容 break; } } } } }

 快递字段与快递重量、价格:

using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Security.Policy; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace ExpressFreightCalculation { public class Cargo { public static int num = 0; long no;//编号 string name;//姓名 long phone;//电话号码 string address;//地址 int area;//地区编码 string getname;//收件人名字 long getphone;//收件人电话号码 double weight;//重量 double charge;//价格 public long No { get { return no; } } public string Name { get { return name; } set { name = value; } } public long Phone { get { return phone; } set { phone = value; } } public string Address { get { return address; } set { address = value; } } public int Area { get { return area; } set { if (value >= 1 && value 0) weight = value; else throw new Exception("重量不能小于0!"); } } public double Charge { get { return charge; } } public Cargo(string name, long phone, string address, int area, string getname, long getphone, double weight) { num++; this.no = MadeNo(); this.name = name; this.phone = phone; this.address = address; this.Area = area; this.getname = getname; this.getphone = getphone; this.Weight = weight; this.charge = CalCharge(); } private static long MadeNo() { long number; if (num < 10) number = long.Parse(DateTime.Now.ToString("yyyyMMdd") + "000" + num.ToString()); else if (num < 100) number = long.Parse(DateTime.Now.ToString("yyyyMMdd") + "00" + num.ToString()); else if (num < 1000) number = long.Parse(DateTime.Now.ToString("yyyyMMdd") + "0" + num.ToString()); else number = long.Parse(DateTime.Now.ToString("yyyyMMdd") + num.ToString()); return number; } public double CalCharge() { int first = 0;//首重 int second = 0;//续重 double charge; switch (area) { case 1: first = 10; second = 5; break; case 2: first = 12; second = 8; break; case 3: first = 15; second = 10; break; case 4: first = 18; second = 12; break; case 5: first = 30; second = 25; break; } if (weight 4) { Console.WriteLine("你的选择超出范围,请重新选择!"); Console.ReadKey(); } } while (choice < 0 || choice > 4); return choice; } public static void Exit() { Console.WriteLine("谢谢使用,再见!"); Console.ReadKey(); Environment.Exit(0);//返回操作系统 } public static void Input() { for (int i = Cargo.num + 1; i 5) { Console.WriteLine("你的选择超出范围,请重新选择!"); Console.ReadKey(); } } while (area < 1 || area > 5); return area; } public static void Output() { double totalweight = 0; double totalcharge = 0; Console.WriteLine("{0,12}{1,6}{2,6}{3,6}", "编号", "寄件人", "快递重量", "快递运费"); for (int i = 1; i


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有