模拟网上购书的结帐功能项目说明书2.docx
- 文档编号:17823121
- 上传时间:2023-08-04
- 格式:DOCX
- 页数:15
- 大小:42.54KB
模拟网上购书的结帐功能项目说明书2.docx
《模拟网上购书的结帐功能项目说明书2.docx》由会员分享,可在线阅读,更多相关《模拟网上购书的结帐功能项目说明书2.docx(15页珍藏版)》请在冰点文库上搜索。
模拟网上购书的结帐功能项目说明书2
《面向对象程序设计基础》
项目设计说明书
项目:
模拟网上购书
的结账系统
专业:
软件工程
班级:
16级1班
学号:
16044115
姓名:
李泽
哈尔滨学院·信息工程学院
一、功能要求
模拟实现网上购书的结账功能。
使用C++,实现图书信息的输入、输出,购书人信息的输出、购书账单的结算、保存等功能。
二、设计要求
1.设计类。
包含:
(1)定义基类buyer,其中含有数据成员:
姓名、购书人编号、地址等。
(2)定义基类buyer的派生类:
普通人、会员、贵宾。
要求会员类增加数据成员会员级别,贵宾类增加数据成员折扣率。
(3)定义书类book,其中含有数据成员:
书号、书名、作者、定价等。
2.系统实现以下相应的各项功能:
(1)图书信息的输入、输出;
(2)购书人信息的输出;
(3)购书账单的结算;
(4)购书信息的保存。
3.其它要求:
(1)使用构造函数、析构函数和成员函数;
(2)使用友元、继承;
(3)使用文件保存;
(4)使用适当的注释进行说明;
(5)允许适当地增加其它功能。
三、全部的程序源代码(有相应注释)
//buy.h
classbuyer
{
protected:
stringname;
intbuyerID;
stringaddress;
doublepay;
public:
buyer();
buyer(stringn,intb,stringa,doublep);
stringgetbuyname();
stringgetaddress();
doublegetpay();
intgetid();
virtualvoiddisplay()=0;
virtualvoidsetpay(double=0)=0;
};
classmember:
publicbuyer
{
intleaguer_grade;
public:
member(stringn,intb,intl,stringa,doublep):
buyer(n,b,a,p)
{
leaguer_grade=l;
}
voiddisplay();
voidsetpay(doublep);
};
classhonoured_guest:
publicbuyer
{
doublediscount_rate;
public:
honoured_guest(stringn,intb,doubler,stringa,doublep):
buyer(n,b,a,p)
{
discount_rate=r;
}
voiddisplay();
voidsetpay(doublep);
};
classlayfolk:
publicbuyer
{
public:
layfolk(stringn,intb,stringa,doublep):
buyer(n,b,a,p)
{}
voiddisplay();
voidsetpay(doublep);
};
buyer:
:
buyer()
{
name="";
buyerID=0;
address="";
pay=0;
}
buyer:
:
buyer(stringn,intb,stringa,doublep)
{
name=n;
buyerID=b;
address=a;
pay=p;
}
doublebuyer:
:
getpay()
{
returnpay;
}
stringbuyer:
:
getaddress()
{returnaddress;}
stringbuyer:
:
getbuyname()
{returnname;
}
intbuyer:
:
getid()
{returnbuyerID;}
//////////////////////////////////////////////
voidmember:
:
display()
{
cout<<"购书人姓名:
"< cout<<"购书人编号: "< cout<<"购书人为会员,级别: "< cout<<"购书地址: "< } ////////////////////////////////////////////// voidmember: : setpay(doublep) { if(leaguer_grade==1) pay=.95*p+pay; elseif(leaguer_grade==2) pay=.90*p+pay; elseif(leaguer_grade==3) pay=.85*p+pay; elseif(leaguer_grade==4) pay=.8*p+pay; elseif(leaguer_grade==5) pay=.7*p+pay; else cout<<"级别错误! "; } ///////////////////////voidmember: : display() voidhonoured_guest: : display() { cout<<"购书人姓名: "< cout<<"购书人编号: "< cout<<"购书人为贵宾,折扣率为: "< cout<<"购书地址: "< } voidhonoured_guest: : setpay(doublep) { pay=pay+(1-discount_rate)*p; } voidlayfolk: : display() { cout<<"购书人姓名: "< cout<<"购书人编号: "< cout<<"购书人为普通人: "<<"\n"; cout<<"购书地址: "< } voidlayfolk: : setpay(doublep) { pay=pay+p; } //book.h classbook { protected: stringbook_ID; stringbook_name; stringauthor; stringpublishing; doubleprice; public: book() { book_ID=""; book_name=""; author=""; publishing=""; price=0; } book(stringb_id,stringb_n,stringau,stringpu,doublepr) { book_ID=b_id; book_name=b_n; author=au; publishing=pu; price=pr; } voiddisplay() { cout<<"书号: "< cout<<"书名: "< cout<<"作者: "< cout<<"出版社: "< cout<<"定价: "< } stringgetbook_ID() { returnbook_ID; } stringgetbook_name() { returnbook_name; } stringgetauthor() { returnauthor; } stringgetpublishing() { returnpublishing; } doublegetprice() { returnprice; } }; //strclass.h #include"string.h" classstring { friendostream&operator<<(ostream&S,conststring&Str); friendistream&operator>>(istream&S,string&Str); public: string(); string(conststring&Str); voidoperator=(conststring&Str); ~string(); string(char*p); private: shortm_Length; char*m_Date; }; string: : string() { m_Length=1; m_Date=newchar[m_Length]; memcpy(m_DATE,"",m_Length); }; string: : string(conststring&Str) { m_Length=Str.m_Length; m_Date=newchar[m_Length]; memcpy(m_Date,Str.m_Date,m_Length); }; string: : string(char*p) { m_Length=strlen(p)+1; m_Date=newchar[m_Length]; memcpy(m_Date,p,m_Length); }; voidstring: : operator=(conststring&Str) { if(&Str! =this) { delete[]m_Date; m_Length=Str.m_Length; m_Date=newchar[m_Length]; memcpy(m_Date,Str.m_Date,m_Length); } return; }; string: : ~string() {delete[]m_Date; }; ostream&operator<<(ostream&S,conststring&Str) { shorti; for(i=1;i S< returnS; }; istream&operator>>(istream&S,string&Str) { constshortBUFLEN=256; charBuf[BUFLEN]; memset(Buf,0,BUFLEN); if(S.peek()=='\n') S.ignore(); S.getline(Buf,BUFLEN,'\n'); Str=Buf; returnS; }; //buy_book.cpp #include #include usingnamespacestd; #include"buy.h" #include"book.h" classorder { public: order() { buyerID=0; ordercount++; orderID=ordercount; listcount=0; } voidsetbuyid(intb_id) { buyerID=b_id; } voidbuy_one_book(stringb_id) { orderlist[listcount]=b_id; listcount++; } voiddisplay(); private: staticintordercount; intorderID; intbuyerID; intlistcount; stringorderlist[20]; }; voidorder: : display() {inti; cout<<"\n订单信息\n\n订单号: "< cout<<"购书人编号: "< cout<<"所购图书书号: "; for(i=0;i cout< cout< } intorder: : ordercount=0; voidmain() { inti=0,j=0; intbuyerid,flag; book*c[2];//用指针数组存放book对象的地址 layfolkb1("林小茶",1,"北京",0); honoured_guestb2("王遥遥",2,.6,"上海",0); memberb3("赵红艳",3,5,"广州",0); ordero1[20]; buyer*b[3]={&b1,&b2,&b3};//用指针数组存放继承了buyer类的3个对象的地址 bookc1("7-302-040504-6","c++程序设计","谭浩强","清华",25); bookc2("7-402-03388-9","数据结构","许卓群","北大",20); c[0]=&c1; c[1]=&c2; cout<<"购书人信息: \n\n"; for(i=0;i<3;i++)//显示3个继承了buyer类的对象 b[i]->display(); cout<<"\n图书信息: \n\n";//显示两个book对象的信息 for(i=0;i<2;i++) c[i]->display(); while(j<2) { cout<<"\n\n请输入购书人编号: "; cin>>buyerid; flag=0; for(i=0;i<3;i++) if(b[i]->getid()==buyerid) { flag=1; break; } if(! flag) { cout<<"编号不存在"< } else { b[i]->setpay(c[0]->getprice());//计算购书金额 b[i]->setpay(c[1]->getprice()); cout< "<getpay()<<"\n\n"; o1[j].setbuyid(b[i]->getid()); o1[j].buy_one_book(c[0]->getbook_ID()); o1[j].buy_one_book(c[1]->getbook_ID()); o1[j].display();j++; } } } 四、程序运行结果(各功能模块) 五、项目设计总结
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 模拟 网上 购书 结帐 功能 项目 说明书