C++影碟出租系统课程设计源代码.docx
《C++影碟出租系统课程设计源代码.docx》由会员分享,可在线阅读,更多相关《C++影碟出租系统课程设计源代码.docx(29页珍藏版)》请在冰豆网上搜索。
C++影碟出租系统课程设计源代码
#ifndefVIDEO_H
#defineVIDEO_H
#include
#include
usingnamespacestd;
//classvideo
stringvidname;
classvideo{//影碟类
friendostream&operator<<(ostream&os,video&vi);
friendclassapplication;
public:
video(string="",string="",int=0,string="",string="",string="",int=0);
video(video&vi);
voidinput();
//private:
stringVname;//碟片名称
stringCountry;//国家
intType;//类型
stringProducer;//制片人
stringDirector;//导演
stringStar;//主演明星
intNumber;//库存量
video*next;
};
video:
:
video(stringvname,stringcountry,inttype,stringproducer,stringdirector,stringstar,intnumber){
Vname=vname;
Country=country;
Type=type;
Producer=producer;
Director=director;
Star=star;
Number=number;
}
video:
:
video(video&vi){
Vname=vi.Vname;
Country=vi.Country;
Type=vi.Type;
Producer=vi.Producer;
Director=vi.Director;
Star=vi.Star;
Number=vi.Number;
}
ostream&operator<<(ostream&os,video*vi){
os<<"****************************************************************"<os<<"该影碟信息为:
"<os<<"名称:
"<Vname<<"国家:
"<Country<<"类型:
";
if(vi->Type==1)os<<"喜剧";
else{
if(vi->Type==2)os<<"悲剧";
else{
if(vi->Type==3)os<<"科幻片";
else{
if(vi->Type==4)os<<"悬疑剧";
else{
if(vi->Type==5)os<<"惊悚片";
else{
if(vi->Type==6)os<<"其他";
}
}
}
}
}
os<os<<"制片人:
"<Producer<<"导演:
"<Director<<"主演:
"<Star<<"库存量:
"<Number<returnos;
}
#endif
#ifndefCUSTOMER_H
#defineCUSTOMER_H
#include
#include
#include"video.h"
usingnamespacestd;
//classCustomer
structVideoInfo{//碟片信息
stringVideoName;//影片名称
intBeginTime;//影片借阅日期
intEndTime;//影片归还日期
};
stringCname;
classCustomer{//顾客类
friendostream&operator<<(ostream&os,constCustomer&cu);
friendclassapplication;
friendclassvideo;
public:
Customer(string="",string="",int=0,int=0,string="",int=0,int=0);//构造函数
intDeclineMoney(int);//扣取消费额
boolRentVideo(string);//出租影碟
boolReturnVideo(string);//归还影片
//private:
stringidPerson;//会员账号
stringName;//会员
intLeftMoney;//会员剩余金额
intnCount;//所借碟片数量
VideoInfoVideo[10];//每个会员最多借10影碟
Customer*next1;
};
Customer:
:
Customer(stringidperson,stringname,intleftmoney,intncount,stringvideoname,intbegintime,intendtime){
idPerson=idperson;
Name=name;
LeftMoney=leftmoney;
nCount=ncount;
for(inti=0;iVideo[i].VideoName=videoname;
Video[i].BeginTime=begintime;
Video[i].EndTime=endtime;
}
}
ostream&operator<<(ostream&os,constCustomer*cu){
os<<"会员编号为:
\t"<idPerson<<"会员为:
\t"<Name<<"会员剩余会费余额为:
\t"<LeftMoney<for(inti=0;inCount;i++){
os<<"所借影片名为:
\t"<Video[i].VideoName<os<<"影片借阅日期为:
\t"<Video[i].BeginTime<os<<"影片归还日期为:
\t"<Video[i].EndTime<os<<"--------------------------------------------\n";
}
returnos;
}
#endif
#ifndefMENU_H
#defineMENU_H
#include
usingnamespacestd;
//classmenu
classmenu{//菜单类
public:
intshowMainMenu();
private:
};
intmenu:
:
showMainMenu(){
system("cls");
cout<<"————————————————————————"<cout<<"|欢迎使用影碟出租系统|"<cout<<"|************************************************|"<cout<<"|1.影碟租赁|"<cout<<"|2.影碟归还|"<cout<<"|3.查看各类型影碟信息|"<cout<<"|4.查询碟片信息|"<cout<<"|5.添加新影碟|"<cout<<"|6.删除碟片信息|"<cout<<"|7.修改碟片信息|"<cout<<"|8.查看会员信息|"<cout<<"|9.注册会员|"<cout<<"|10.注销会员|"<cout<<"|11.更新会员信息与充值|"<cout<<"|12.退出系统|"<cout<<"————————————————————————"<cout<<"请选择1-12:
"<intselect;
cin>>select;
while(select<1||select>12){
cout<<"选择错误,请重新选择1-12"<cin.clear();//当输入字符,清空流错误状态
cin.sync();//清空数据流
cin>>select;
}
returnselect;
}
#endif
#ifndefAPPLICATION_H
#defineAPPLICATION_H
#include
#include
#include
#include"video.h"
#include"Customer.h"
#include"menu.h"
usingnamespacestd;
classapplication{//数据应用类
public:
application();
~application();
voidload();//数据输出
voidsave();//数据保存到文件
voidRent();//1.影碟租赁
voidReturn();//2.影碟归还
voidCheckall();//3.查看各类型影碟信息
voidsearch(intType);//根据类型查找
voidCheck(stringvidname);//4.查看影碟信息:
根据碟片名称查找
voidAddvideo();//5.添加影碟
voidDeletevideo();//6.删除影碟
voidModifyvideo(stringVname);//7.修改影碟信息
voidCustomerinfo(stringCname);//8.会员信息:
根据查找
voidAdd();//9.注册会员
voidDelete();//10.注销会员
voidModify(stringName);//11.更新会员信息与充值
voidrun();
private:
stringtitle;
menumyMenu;
videomyvideo;
Customermycustomer;
video*vid;
Customer*cus;
};
application:
:
application(){
vid=0;
cus=0;
load();
}
application:
:
~application(){
video*v;
v=vid;
Customer*c;
c=cus;
while(v){
v=v->next;
deletevid;
vid=v;
}
vid=0;
while(c){
c=c->next1;
deletecus;
cus=c;
}
vid=0;
}
voidapplication:
:
load(){
ifstreamfile;//碟片信息
video*v=vid;
stringVname;//碟片名称
stringCountry;//国家
intType;//类型
stringProducer;//制片人
stringDirector;//导演
stringStar;//主演明星
intNumber=0;//库存量
file.open("video.txt",ios:
:
in);
file>>Vname>>Country>>Type>>Producer>>Director>>Star>>Number;
while(file.good()){
v=newvideo(Vname,Country,Type,Producer,Director,Star,Number);
v->next=0;
//碟片结点加入链表
if(vid)//若已经存在结点
{
video*v2;
v2=vid;
while(v2->next)//查找尾结点
{
v2=v2->next;
}
v2->next=v;//连接
}
else//若不存在结点(表空)
vid=v;//连接
file>>Vname>>Country>>Type>>Producer>>Director>>Star>>Number;
}
file.close();
ifstreamfile1;//会员信息
Customer*c=cus;
stringidPerson;//会员账号
stringName;//会员
intLeftMoney;//会员剩余金额
intnCount;//所借碟片数量
VideoInfoVideo[10];//每个会员最多借10影碟
file1.open("Customer.txt",ios:
:
in);
file1>>idPerson>>Name>>LeftMoney>>nCount;
for(inti=0;ifile1>>Video[i].BeginTime>>Video[i].EndTime>>Video[i].VideoName;
}
while(file1.good()){
for(inti=0;ic=newCustomer(idPerson,Name,LeftMoney,nCount,Video[i].VideoName,Video[i].BeginTime,Video[i].EndTime);
c->next1=0;
//顾客结点加入链表
if(cus)//若已经存在结点
{
Customer*c2;
c2=cus;
while(c2->next1)//查找尾结点
{
c2=c2->next1;
}
c2->next1=c;//连接
}
else//若不存在结点(表空)
cus=c;//连接
file1>>Video[i].BeginTime>>Video[i].EndTime>>Video[i].VideoName;
}
}
file1.close();
}
voidapplication:
:
save(){
ofstreamfile("video.txt",ios:
:
out);
ofstreamfile1("Customer.txt",ios:
:
out);
charc;
cout<<"\n是否保存数据?
[Y/N]:
";
cin>>c;
if(toupper(c)!
='Y')
return;
video*v=vid;
while(v){
file<Vname<Country<Type<Producer<Director<Star<Number<v=v->next;
}
file.close();
Customer*cu=cus;
while(cu){
file1<idPerson<Name<LeftMoney<nCount<Video<cu=cu->next1;
}
file1.close();
cout<<"\n保存成功...\n";
}
voidapplication:
:
Rent(){
intnumber;
Customer*c1;
c1=cus;
cout<<"请输入会员:
"<cin>>Cname;
while(c1){
if(c1->Name==Cname)
break;
else{
c1=c1->next1;
}
}
if(c1!
=NULL){
cout<cout<<"请输入租赁碟片数目:
";
cin>>number;
if(number>10-c1->nCount)
cout<<"租赁数目超过限定值!
"<else
if(number*20>c1->LeftMoney)
cout<<"余额不足,请充值或减少影碟数!
"<if(number<=10-c1->nCount&&number*20<=c1->LeftMoney){
c1->nCount=number;
for(inti=0;icout<<"请输入租赁日期(例:
2013年08月08日写为20130808):
";
cin>>c1->Video[i].BeginTime;
cout<<"请输入碟片名:
";
cin>>c1->Video[i].VideoName;
}
c1->LeftMoney-=number*20;
cout<<"\t\t租赁成功!
"<}
}
else
cout<<"未找到该会员,请先注册!
"<}
voidapplication:
:
Return(){
intnumber,time;
Customer*c1;
c1=cus;
cout<<"请输入会员:
"<cin>>Cname;
while(c1){
if(c1->Name==Cname)
break;
else{
c1=c1->next1;
}
}
if(c1!
=NULL){
cout<Customerinfo(Cname);
cout<<"请输入归还碟片数目:
";
cin>>number;
c1->nCount=c1->nCount-number;
for(inti=0;icout<<"请输入碟片名称:
";
cin>>c1->Video[i].VideoName;
cout<<"请输入归还日期:
";
cin>>c1->Video[i].EndTime;
cout<<"请输入该碟片租赁天数:
";
cin>>time;
if(time%3==0)
c1->LeftMoney=c1->LeftMoney+20-time/3;
else
c1->LeftMoney=c1->LeftMoney+20-time/3-1;
cout<<"\t\t扣费成功!
"<}
cout<<"\t\t***归还成功***\n";
}
else
cout<<"未找到该会员,请确认!
"<}
voidapplication:
:
search(intType){//根据类型查找
video*v1;
v1=vid;
while(v1){
if(v1->Type==Type)
break;
else{
v1=v1->next;
}
}
if(v1!
=NULL){
cout<}
else
cout<<"未找到该类型的碟片!
"<}
voidapplication:
:
Checkall(){
intType;charc;
cout<<"选择要查找的碟片类型(1.喜剧2.悲剧3.科幻片4.悬疑剧5.历史剧6.惊悚片7.其他):
"<cin>>Type;
search(Type);
cout<<"********以上为类型所有碟片*********"<cout<<"是否继续查找【Y/N】?
"<cin>>c;
if(toupper(c)=='Y'){
Checkall();
return;
}
else
return;
system("pause");
}
voidapplication:
:
Check(stringvidname){
video*v1;
v1=vid;
while(v1){
if(v1->Vname==vidname)
break;
else{
v1=v1->next;
}
}
if(v1!
=NULL){
cout<}
else
cout<<"未找到该碟片!
"<}
voidapplication:
:
Addvideo(){
system("cls");
video*v,*v2;//新结点指针
stringVname;//碟片名称
stringCountry;//国家
intType=7;//类型
stringProducer;//制片人
stringDirector;//导演
stringStar;//主演明星
intNumber=0;//库存量
charc;
cout<<"\n**新增碟片信息**\n";
//输入碟片信息
cout<<"输入片名:
\t";
cin>>Vname;
cout<video*v1;
v1=vid;
while(v1){
if(v1->Vname==Vname){
break;
}
else{
v1=v1->next;
}
}
if(v1!
=NULL){