软件综合实践专题
作者:互联网
订单系统简单分析
这是一个订单系统软件,是我的同学在小学期设计的一段代码,这段代码的主要功能是对于图书的管理,通过order类的订单管理,其中包含图书信息,购书人信息,应付金额信息等,不同的信息由不同的类掌控,我根据代码信息也画了一个相应的简易流程图
这段代码有优点也有缺点,优点是对于图书管理系统中一个个功能模块分的非常清楚,无论是用户的信息还是图书的信息或者是订单的信息都在一个个相应的类里,包括售后评价等也是齐全,但是我觉得有些代码显得太过繁琐,或者说使用的方法一直是那么几个,函数方法没有改变,继承的时候也是普通单继承方式,看多了会让其他人觉得代码太过冗长,如果还要加以完善的话,在功能上建议添加用户权限这种功能,分为总管理员系统,读者系统,不同的权限可以访问不同的功能,当然,就我们现在的知识和能力而言,这段代码在c++中已经是较为优秀和完善的代码了。
#include<string> using namespace std; class buyer { protected: string name; int buyerID; string address; double pay; public: buyer(); buyer(string n,int b,string a,double p); string getbuyname(); string getaddress(); double getpay(); int getid(); virtual void display()=0; virtual void setpay(double=0)=0; }; class member:public buyer { int leaguer_grade; public: member(string n,int b,int l,string a,double p):buyer(n,b,a,p) {leaguer_grade=l;} void display(); void setpay(double p); }; class honoured_guest:public buyer { double discount_rate; public: honoured_guest(string n,int b,double r,string a,double p):buyer(n,b,a,p) {discount_rate=r;} void display(); void setpay(double p); }; class order {protected: string orderID; int buyerID; string orderlist; int listcount; double price; public: order(); order(string o,int b,string ol,int l,int pr); string getorderID(); int getbuyerID(); string getorderlist(); int getlistcount(); double getprice(); void display(); void getlist(); }; order::order(string o,int b,string ol,int l,int pr) { orderID=o; buyerID=b; orderlist=ol; listcount=l; price=pr; } order::order() { orderID=""; buyerID=0; orderlist=""; listcount=0; price=0; } void order::getlist(){ int i; cout<<"\n\n订单信息:\n\n"; ofstream fout("buying.dat",ios::out); for(i=0;i<3;i++) { order* o[3]; order o1("2016-06-27-001",1,"7-302-04504-6",100,2500); order o2("2016-06-27-002",3,"7-402-03388-9",10,200); order o3("2016-06-27-003",2,"7-302-04504-6",40,1000); o[0]=&o1; o[1]=&o2; o[2]=&o3; o[i]->display(); fout<<"订单编号:"<<o[i]->getorderID()<<endl; fout<<"购书人编号:"<<o[i]->getbuyerID()<<endl; fout<<"图书编号:"<<o[i]->getorderlist()<<endl; fout<<"购书数量:"<<o[i]->getlistcount()<<endl; fout<<"总价格:"<<o[i]->getprice()<<endl<<endl; } fout.close(); cout<<"订单已保存到buying.dat中"<<endl;} void order::display() { cout<<"订单编号:"<<orderID<<endl; cout<<"购书人编号:"<<buyerID<<endl; cout<<"图书编号:"<<orderlist<<endl; cout<<"购书数量:"<<listcount<<endl; cout<<"总价格:"<<price<<endl<<endl; } string order::getorderID() {return orderID;} int order::getbuyerID() {return buyerID;} string order::getorderlist() {return orderlist;} int order::getlistcount() {return listcount;} double order::getprice() {return price;} class layfolk:public buyer {public: layfolk(string n,int b,string a,double p):buyer(n,b,a,p) { } void display(); void setpay(double p); }; #include<string> using namespace std; class buyer { protected: string name; int buyerID; string address; double pay; public: buyer(); buyer(string n,int b,string a,double p); string getbuyname(); string getaddress(); double getpay(); int getid(); virtual void display()=0; virtual void setpay(double=0)=0; }; class member:public buyer { int leaguer_grade; public: member(string n,int b,int l,string a,double p):buyer(n,b,a,p) {leaguer_grade=l;} void display(); void setpay(double p); }; class honoured_guest:public buyer { double discount_rate; public: honoured_guest(string n,int b,double r,string a,double p):buyer(n,b,a,p) {discount_rate=r;} void display(); void setpay(double p); }; class layfolk:public buyer {public: layfolk(string n,int b,string a,double p):buyer(n,b,a,p) { } void display(); void setpay(double p); }; buyer::buyer() { name=""; buyerID=0; address=""; pay=0; } buyer::buyer(string n,int b,string a,double p) { name=n; buyerID=b; address=a; pay=p; } double buyer::getpay() {return pay;} string buyer::getaddress() {return address;} string buyer::getbuyname() {return name;} int buyer::getid() {return buyerID;} void member::display() { cout<<"购书人姓名:"<<name<<"\t"; cout<<"购书人编号:"<<buyerID<<"\t"; cout<<"购书人为会员,级别:"<<leaguer_grade<<endl; cout<<"地址:"<<address<<endl; } void member::setpay(double p) { if(leaguer_grade==1) pay=0.95*p+pay; else if(leaguer_grade==2) pay=0.9*p+pay; else if(leaguer_grade==3) pay=0.85*p+pay; else if(leaguer_grade==4) pay=0.8*p+pay; else if(leaguer_grade==5) pay=0.7*p+pay; else cout<<"级别错误!"; } void honoured_guest::display() { cout<<"购书人姓名:"<<name<<"\t"; cout<<"购书人编号:"<<buyerID<<"\t"; cout<<"购书人为贵宾,折扣率为:"<<discount_rate*100<<"%\n"; cout<<"地址:"<<address<<endl<<endl; } void honoured_guest::setpay(double p) { pay=pay+(1-discount_rate)*p; } void layfolk::display() { cout<<"购书人姓名:"<<name<<"\t"; cout<<"购书人编号:"<<buyerID<<"\t"; cout<<"购书人为普通人"<<endl; cout<<"地址:"<<address<<endl<<endl; } void layfolk::setpay(double p) { pay=p+pay; } //buy.h文件结束 class book {protected: string book_ID; string book_name; string author; string publishing; double price; public: book(); book(string b_id,string b_n,string au,string pu,double pr); void display(); string getbook_ID(); string getbook_name(); string getauthor(); string getpublishing(); double getprice(); void getall(); }; book::book(string b_id,string b_n,string au,string pu,double pr) { book_ID=b_id; book_name=b_n; author=au; publishing=pu; price=pr; } book::book() { book_ID=""; book_name=""; author=""; publishing=""; price=0; } void book::display() { cout<<"书号:"<<book_ID<<"\t"; cout<<"书名:"<<book_name<<"\t"; cout<<"作者:"<<author<<endl; cout<<"出版社:"<<publishing<<"\t"; cout<<"定价:"<<price<<"\n"; } void book::getall(){ book* c[5]; book c1("7-302-04504-6","c++程序设计","谭浩强","清华",25); book c2("7-402-03388-9"," 数据结构","徐卓群","北大",20); book c3("7-547-82783-3"," 海洋大数据","黄冬梅","海洋出版社",40); book c4("7-302-32507-9"," 离散数学","屈婉玲","清华大学出版社",33); book c5("7-040-37346-2"," 数学分析","哈工大数学系","高等教育出版社",26); c[0]=&c1; c[1]=&c2; c[2]=&c3; c[3]=&c4; c[4]=&c5; cout<<"图书信息"<<endl; ofstream outf("book.txt",ios::out); int i; for(i=0;i<5;i++){ outf.write((char*)&c[i],sizeof(c[i])); c[i]->display(); } outf.close(); } string book::getbook_ID() {return book_ID;} string book::getbook_name() {return book_name;} string book::getauthor() {return author;} string book::getpublishing() {return publishing;} double book::getprice() {return price;} //book.h 文件结束
//buy_book.cpp文件开始 #include<iostream> #include<fstream> #include<string> using namespace std; #include"buy.h" #include"book.h" #include"order.h" #include"orderank.h" #include"strclass.h" const string people[4][2] = { "chenbx", "1234", "zhaoyt", "3456", "wangj", "5678", "zhujh","7890" }; void pingjia(); int main() { string name,pw; int m,n; cout<<" 欢迎来到网上购书查询系统"<<endl; cout<<"----------------请登录------------------"<<endl; cout<<"请输入用户名:"; while(cin>>name) { for(m = 0; m < 3; m ++) { if(people[m][0]==name)break; } if(m == 3) { cout << "未找到该用户\n"; return 0; } n=m; break; } cout<<"请输入密码:"; cin >> pw; if(people[n][1]!=pw) { cout << "密码错误\n"; return 0; } cout << "登陆成功,欢迎你"<< name << endl; int i=0,buyerid,flag; layfolk b1("林小茶",1,"北京",0); honoured_guest b2("王遥遥",2,.6,"上海",0); member b3("赵红艳",3,5,"广州",0); buyer*b[3]={&b1,&b2,&b3}; book* c[5]; book c1("7-302-04504-6","c++程序设计","谭浩强","清华",25); book c2("7-402-03388-9"," 数据结构","徐卓群","北大",20); book c3("7-547-82783-3"," 海洋大数据","黄冬梅","海洋出版社",40); book c4("7-302-32507-9"," 离散数学","屈婉玲","清华大学出版社",33); book c5("7-040-37346-2"," 数学分析","哈工大数学系","高等教育出版社",26); c[0]=&c1; c[1]=&c2; c[2]=&c3; c[3]=&c4; c[4]=&c5; order* o[3]; order o1("2016-06-27-001",1,"7-302-04504-6",100,2500); order o2("2016-06-27-002",3,"7-402-03388-9",10,200); order o3("2016-06-27-003",2,"7-302-04504-6",40,1000); o[0]=&o1; o[1]=&o2; o[2]=&o3; orderank* r[3]; orderank r1("2016-06-27-001",1,"7-302-04504-6",100,2500); orderank r2("2016-06-27-002",3,"7-402-03388-9",10,200); orderank r3("2016-06-27-003",2,"7-302-04504-6",40,1000); r[0]=&r1; r[1]=&r2; r[2]=&r3; char k; while(k!='6') { cout<<endl<<endl; cout<<"---------------------------------------------"<<endl; cout<<"----1.查看购书人信息-------------------------"<<endl; cout<<"----2.查看图书信息---------------------------"<<endl; cout<<"----3.订单查询-------------------------------"<<endl; cout<<"----4.查询应付金额---------------------------"<<endl; cout<<"----5.订单排序打印---------------------------"<<endl; cout<<"----6.进行评价-------------------------------"<<endl; cout<<"---------------------------------------------"<<endl; cout<<"----请选择功能:"; cin>>k; switch(k) { case '1': { cout<<"购书人信息:\n\n"; for(i=0;i<3;i++) b[i]->display(); }break; case '2': { book A; A.getall(); }break; case '3':{ order B; B.getlist(); }break; case '4':{ cout<<"\n\n请输入购书人编号:"; cin>>buyerid; flag=0; for(i=0;i<3;i++) if(b[i]->getid()==buyerid) { flag=1;break; } if(!flag) {cout<<"编号不存在"<<endl;} else { b[i]->setpay(c[0]->getprice()); b[i]->setpay(c[1]->getprice()); cout<<endl<<"购书人需要付费:"<<b[i]->getpay()<<"\n\n"; }}break; case '5': { cout<<"\n\n订单按总价格排序为:"<<endl<<endl; int w,s,l=3; orderank* tmp; ofstream sout("order.txt",ios::out); for(s=0; s<l-1; s++) for(w=0; w<l-1-i; w++) if(r[w+1]->getprice() > r[w]->getprice()) { tmp = r[w]; r[w] = r[w+1]; r[w+1] = tmp; } for(w=0;w<l;w++) { r[w]->display(); sout<<"订单编号:"<<r[w]->getorderID()<<endl; sout<<"购书人编号:"<<r[w]->getbuyerID()<<endl; sout<<"图书编号:"<<r[w]->getorderlist()<<endl; sout<<"购书数量:"<<r[w]->getlistcount()<<endl; sout<<"总价格:"<<r[w]->getprice()<<endl<<endl; } sout.close(); cout<<"\n订单已按总价格排序并打印到order.txt中"<<endl; }break; case '6': pingjia();break; } } return 0; } void pingjia( ){ cout<<"\n\n\n\n\n\n\t\t\t\t *********************待评价*******************\n\n\n"; cout<<"\t\t\t\t 交易成功,请对卖家作出评价\n\n\n"; cout<<"\t\t\t\t 1.☆ 2.☆☆ 3.☆☆☆ 4.☆☆☆☆ 5.☆☆☆☆☆\n"; int a; cout<<"\n\t\t\t\t\t 描述相符:"; cin>>a; switch(a) { case 1:cout<<"\t\t\t\t\t 描述相符:☆\n";break; case 2:cout<<"\t\t\t\t\t 描述相符:☆☆\n";break; case 3:cout<<"\t\t\t\t\t 描述相符:☆☆☆\n";break; case 4:cout<<"\t\t\t\t\t 描述相符:☆☆☆☆\n";break; case 5:cout<<"\t\t\t\t\t 描述相符:☆☆☆☆☆\n";break; } int b; cout<<"\n\t\t\t\t\t 物流服务:"; cin>>b; switch(b) { case 1:cout<<"\t\t\t\t\t 物流服务:☆\n";break; case 2:cout<<"\t\t\t\t\t 物流服务:☆☆\n";break; case 3:cout<<"\t\t\t\t\t 物流服务:☆☆☆\n";break; case 4:cout<<"\t\t\t\t\t 物流服务:☆☆☆☆\n";break; case 5:cout<<"\t\t\t\t\t 物流服务:☆☆☆☆☆\n";break; } int c; cout<<"\n\t\t\t\t\t 服务态度:"; cin>>c; switch(c) { case 1:cout<<"\t\t\t\t\t 服务态度:☆\n";break; case 2:cout<<"\t\t\t\t\t 服务态度:☆☆\n";break; case 3:cout<<"\t\t\t\t\t 服务态度:☆☆☆\n";break; case 4:cout<<"\t\t\t\t\t 服务态度:☆☆☆☆\n";break; case 5:cout<<"\t\t\t\t\t 服务态度:☆☆☆☆☆\n";break; } cout<<"\n\t\t\t\t\t 感谢您的评价(*^◎^*)\n\n\n"; } //buy_book.cpp文件结束
图书信息
标签:专题,string,int,double,void,实践,buyer,软件,public 来源: https://www.cnblogs.com/abcd123asa/p/10469949.html