快递的寄件与取件
概述:此次是舍友在大一下的大作业,主要是快递的寄件与取件信息。
解读代码:
他的作业主要是一个一C++位主体的快递寄件与取件小程序。
具体界面:
1、初界面:
2、寄件界面:
3、取件界面:
4、信息查询:
问题发现:
原程序运行一次后上次的订单记录消失不见,对寄件人与收件人的订单下旬会造成很大的麻烦,并且在订单进行更改后,更改前的订单仍然存在,没有自动将其删除
。
原本代码:
class Package:
public Company,public Sendman,public Receiveman
{
public:
bool isAllowRecord,hadSent;
int sendYear=0,sendMonth=0,sendDay=0,
receiveYear=0,receiveMonth=0,receiveDay=0;
int tpackageNumber;
int boxNumber;
Package()
{
isAllowRecord=false;
hadSent=false;
}
string rollcompany()
{
SYSTEMTIME sys;
GetLocalTime(&sys);
switch(((int)sys.wMinute+(int)sys.wSecond)%3)
{
case 0:return "cat快递";break;
case 1:return "猫车运输";break;
case 2:return "乌鸦速递";break;
default:return "怪起来了";break;
}
}
void reset(int pid,string sendName,string receiveName,string sendAddress,string receiveAddress,
int Year,int Month,int Day,bool is_sent)
{
tpackageNumber=pid;
Sendman::change(sendName,sendAddress);
Receiveman::change(receiveName,receiveAddress);
Company::changeCompanyName(rollcompany());
sendYear=Year,sendMonth=Month,sendDay=Day;
isAllowRecord=true,hadSent=is_sent;
boxNumber=tpackageNumber+200000;
}
void record()
{
ofstream t;
t.open("Packagelist.txt",ios::app);
t<<"包裹ID:"<<100000+tpackageNumber<<endl;
t<<"运输公司:"<<Company::companyName<<endl;
t<<"状态:";
if(!hadSent)
t<<"运输中"<<endl;
else
t<<"已签收"<<endl;
t<<"寄件人:"<<Sendman::sendmanName<<endl;
t<<"收件人:"<<Receiveman::receivemanName<<endl;
t<<"寄件地址:"<<Sendman::sendmanAddress<<endl;
t<<"收件地址:"<<Receiveman::receivemanAddress<<endl;
t<<"发货时间:"<<sendYear<<"年"<<sendMonth<<"月"<<sendDay<<"日"<<endl;
if(hadSent)
{
t<<"收货时间:"<<receiveYear<<"年"<<receiveMonth<<"月"<<receiveDay<<"日"<<endl;
t<<"快递箱编号:"<<boxNumber<<endl;
}
t<<endl<<endl;
t.close();
}
void allPackageRecord()
{
ofstream t;
t.open("Packagelist.txt",ios::trunc);
t.close();
for(int i=0;i<100;i++)
if(package[i].isAllowRecord)
package[i].record();
}
修改后的
class Package:
public Company,public Sendman,public Receiveman
{
public:
bool isAllowRecord,hadSent;
int sendYear=0,sendMonth=0,sendDay=0,
receiveYear=0,receiveMonth=0,receiveDay=0;
int tpackageNumber; //包裹id
int boxNumber;
//默认构造函数
Package(){
isAllowRecord=false;
hadSent=false;
}
//叫一个公司
string rollcompany(){
SYSTEMTIME sys;
GetLocalTime(&sys);
switch(((int)sys.wMinute+(int)sys.wSecond)%3){
case 0:
return "cat快递";
break;
case 1:
return "猫车运输";
break;
case 2:
return "乌鸦速递";
break;
default:
return "怪起来了";
break;
}
}
void reset(int pid,string sendName,string receiveName,string sendAddress,string receiveAddress,
int Year,int Month,int Day,bool is_sent){
tpackageNumber=pid;
Sendman::change(sendName,sendAddress);
Receiveman::change(receiveName,receiveAddress);
Company::changeCompanyName(rollcompany());
sendYear=Year,sendMonth=Month,sendDay=Day;
isAllowRecord=true,hadSent=is_sent;
boxNumber=tpackageNumber+200000;
}
//把它记录进文件
void record(){
ofstream t;
t.open("Packagelist.txt",ios::app);
t<<"包裹ID:"<<100000+tpackageNumber<<endl;
t<<"运输公司:"<<Company::companyName<<endl;
t<<"状态:";
if(!hadSent)
t<<"运输中"<<endl;
else
t<<"已签收"<<endl;
t<<"寄件人:"<<Sendman::sendmanName<<endl;
t<<"收件人:"<<Receiveman::receivemanName<<endl;
t<<"寄件地址:"<<Sendman::sendmanAddress<<endl;
t<<"收件地址:"<<Receiveman::receivemanAddress<<endl;
t<<"发货时间:"<<sendYear<<"年"<<sendMonth<<"月"<<sendDay<<"日"<<endl;
if(hadSent)
{
t<<"收货时间:"<<receiveYear<<"年"<<receiveMonth<<"月"<<receiveDay<<"日"<<endl;
t<<"快递箱编号:"<<boxNumber<<endl;
}
t<<endl<<endl;
t.close();
}
void allPackageRecord()
{
ofstream t;
t.open("Packagelist.txt",ios::app);
t.close();
for(int i=0;i<100;i++)
if(package[i].isAllowRecord)
package[i].record();
}
修改后使用户的体验感更好,更加方便用户查询自己的快递以及更容易寄件取件,修复了一些更改快递信息的bug,使程序更容易运行。
总结:
经过此次对代码的解读与更改,了解了软件的运行需要不断的更新与修改,使程序要更贴近用户,便宜用户的使用,使用户的体验感更好。