C++公司管理系统源代码(14页).doc
-C+公司管理系统源代码-第 14 页#include<iostream> #include<fstream> using namespace std;class device public: char name10;/物品名称char color10;/物品颜色char address50;/厂商地址 char factory50;/生产厂商 char type20;/物品型号 int year,month,day;/出厂日期 int number;/物品数量 device() /构造函数 device() / 析构函数 virtual void pay() /设置价格函数class TV:virtual public devicepublic: TV() void set1(char *n,char *c,char *a,char *f,char *t,int y,int m,int d,int nn) strcpy(name,n); strcpy(color,c); strcpy(address,a); strcpy(factory,f); strcpy(type,t); year=y; month=m; day=d; number=nn; void pay() price1=3000; /普通电视机售价float price1; class DVD:virtual public devicepublic: DVD() void set2(char *n,char *c,char *a,char *f,char *t,int y,int m,int d,int nn) strcpy(name,n); strcpy(color,c); strcpy(address,a); strcpy(factory,f); strcpy(type,t); year=y; month=m; day=d; number=nn; void pay() price2=2000;/DVD售价float price2; class TV_DVD:public TV,public DVD public: TV_DVD() void set3(char *n,char *c,char *a,char *f,char *t,int y,int m,int d,int nn) strcpy(name,n); strcpy(color,c); strcpy(address,a); strcpy(factory,f); strcpy(type,t); year=y; month=m; day=d; number=nn; void pay() price=(2000+3000)*80/100;/带DVD的普通电视机售价float price; TV t120;DVD d120;TV_DVD td120; static int k(0),k1(0),k2(0); void main()/主函数void caidan(); caidan(); void caidan() void employw();/信息录用void addw();/添加物品信息void shown();/显示物品信息void selectw();/删除物品信息void searchw();/查找物品信息void savew();/保存物品信息int a1; cout<<"tt 功能菜单 nn" cout<<"t(1) 信息录用 n" cout<<"t(2) 添加物品信息 n" cout<<"t(3) 显示物品信息 n" cout<<"t(4) 查找物品信息 n" cout<<"t(5) 删除物品信息 n" cout<<"t(6) 保存物品信息 n" cout<<"t(7) 退出 n" cout<<"n请输入1或2或3或4或5或6或7进行你所要执行地下一步动作:n" cin>>a1;while(a1!=1&&a1!=2&&a1!=3&&a1!=4&&a1!=5&&a1!=6&&a1!=7) cout<<"n请重新输入数字1或2或3或4或5或6或7:"cin>>a1; if(a1=1) employw(); if(a1=2) addw(); if(a1=3) shown(); if(a1=4) searchw(); if(a1=5) selectw(); if(a1=6) savew(); if(a1=7) cout<<"n退出程序!n" void employw() char a10,b10,c50,d50,e20; int m,n,h,n1,rr,i1,v,i=9,r1; cout<<"n(1-普通电视机 2-DVD 3-带DVD的普通电视机):" while(i!=0) cin>>i; if(i=1) cout<<"n请输入普通电视机的相关信息!n" for(v=0;v<20;v+) cout<<"物品名称:" cin>>a; cout<<"n物品颜色:" cin>>b; cout<<"n物品的生产厂商:" cin>>c; cout<<"n厂商地址:" cin>>d; cout<<"n物品型号:" cin>>e; cout<<"n物品出厂日期:" cin>>m>>n>>h; cout<<"n物品数量:" cin>>n1; t1v.set1(a,b,c,d,e,m,n,h,n1); t1v.pay(); k+; cout<<"n想继续输入普通电视机的相关信息吗?(1-是 2-否):" cin>>i1; while(i1!=1&&i1!=2) cout<<"n请重新输入数字1或2:" cin>>i1; if(i1=1) system("cls");cout<<"n请继续输入普通电视机的相关信息!n" else break; if(i=2) cout<<"n请输入DVD的相关信息!n" for(v=0;v<20;v+) cout<<"物品名称:" cin>>a; cout<<"n物品颜色:" cin>>b;cout<<"n物品的生产厂商:" cin>>c; cout<<"n厂商地址:" cin>>d; cout<<"n物品型号:" cin>>e; cout<<"n物品出厂日期:" cin>>m>>n>>h; cout<<"n物品数量:" cin>>n1; d1v.set2(a,b,c,d,e,m,n,h,n1); d1v.pay(); k1+; cout<<"n想继续输入DVD的相关信息吗?(1-是 2-否):" cin>>i1; while(i1!=1&&i1!=2) cout<<"n请重新输入数字1或2:" cin>>i1; if(i1=1) system("cls"); cout<<"n请继续输入DVD的相关信息!n" else break; if(i=3) cout<<"n请输入带DVD的普通电视机的相关信息!n" for(v=0;v<20;v+) cout<<"物品名称:" cin>>a; cout<<"n物品颜色:" cin>>b; cout<<"n物品的生产厂商:" cin>>c; cout<<"n厂商地址:" cin>>d; cout<<"n物品型号:" cin>>e; cout<<"n物品出厂日期:" cin>>m>>n>>h; cout<<"n物品数量:" cin>>n1; td1v.set3(a,b,c,d,e,m,n,h,n1); td1v.pay(); k2+; cout<<"n想继续输入带DVD的普通电视机的相关信息吗?(1-是 2-否):" cin>>i1; while(i1!=1&&i1!=2) cout<<"n请重新输入数字1或2:" cin>>i1; if(i1=1) system("cls");cout<<"n请继续输入带DVD的普通电视机的相关信息!n" if(i1=2) break; cout<<"n想输入其他物品的相关信息吗?(1-是 2-否):" cin>>i1; while(i1!=1&&i1!=2) cout<<"n请重新输入数字1或2:"cin>>i1; if(i1=1) system("cls"); cout<<"n请输入数字输入相对应的物品信息(1-普通电视机 2-DVD 3-带DVD的普通电视机):" if(i1=2) break;cout<<"想保存你所输入得数据吗?(1-是 2否):" cin>>rr; while(rr!=1&&rr!=2) cout<<"n请重新输入数字1或2:"cin>>rr; if(rr=1) ofstream ofile("wiring.txt",ios_base:out); for(v=0;v<k;v+) ofile<<"n普通电视机的名称:"<<t1v.name<<"n普通电视机的颜色:" <<t1v.color<<"n普通电视机的出厂地址:"<<t1v.address <<"n普通电视机的出厂的厂商:"<<t1v.factory<<"n普通电视机的型号:" <<t1v.type<<"n普通电视机的出厂日期:"<<t1v.year<<"/"<<t1v.month <<"/"<<t1v.day<<"n普通电视机的单价:"<<t1v.price1<<"n普通电视机的数量:"<<t1v.number<<endl; for(v=0;v<k1;v+) ofile<<"nDVD的名称:"<<d1v.name<<"nDVD的颜色:" <<d1v.color<<"nDVD的出厂地址:"<<d1v.address <<"nDVD的出厂的厂商:"<<d1v.factory<<"nDVD的型号:" <<d1v.type<<"nDVD的出厂日期:"<<d1v.year<<"/"<<d1v.month <<"/"<<d1v.day<<"nDVD的单价:"<<d1v.price2<<"nDVD的数量:"<<d1v.number<<endl; for(v=0;v<k2;v+) ofile<<"n带DVD的普通电视机的名称:"<<td1v.name<<"n带DVD的普通电视机的颜色:" <<td1v.color<<"n带DVD的普通电视机的出厂地址:"<<td1v.address <<"n带DVD的普通电视机的出厂的厂商:"<<td1v.factory<<"n带DVD的普通电视机的型号:" <<td1v.type<<"n带DVD的普通电视机的出厂日期:"<<td1v.year<<"/"<<td1v.month <<"/"<<td1v.day<<"n带DVD的普通电视机的单价:"<<td1v.price<<"n带DVD的普通电视机的数量:"<<td1v.number<<endl; ofile.close(); cout<<"n物品信息已储存!" cout<<"n按键1返回菜单:" cin>>r1; while(r1!=1) cout<<"n请重新输入数字1:"cin>>r1; if(r1=1) system("cls");caidan(); if(r1=2) cout<<"n退出程序!" if(rr=2) cout<<"n按键1返回菜单2退出程序:" cin>>r1; while(r1!=1&&r1!=2) cout<<"n请重新输入数字1或2:"cin>>r1; if(r1=1) system("cls");caidan(); if(r1=2) cout<<"n退出程序!" void addw()/添加物品信息函数 void caidan();/菜单函数char a10,b10,c50,d50,e20; int m,n,h,n1,rr,i1,v,i=9,r1; cout<<"n请输入数字键添加对应的物品信息(1-普通电视机 2-DVD 3-带DVD的普通电视机):" while(i!=0) cin>>i; if(i=1) cout<<"n请输入普通电视机的相关信息!n" for(v=k;v<20;v+) cout<<"物品名称:" cin>>a; cout<<"n物品颜色:" cin>>b; cout<<"n物品的生产厂商:" cin>>c; cout<<"n厂商地址:" cin>>d; cout<<"n物品型号:" cin>>e; cout<<"n物品出厂日期:" cin>>m>>n>>h; cout<<"n物品数量:" cin>>n1; t1v.set1(a,b,c,d,e,m,n,h,n1); t1v.pay(); k+; cout<<"n想继续添加普通电视机的相关信息吗?(1-是 2-否):" cin>>i1; while(i1!=1&&i1!=2) cout<<"n请重新输入数字1或2:" cin>>i1; if(i1=1) cout<<"n请继续输入普通电视机的相关信息!n" else break; if(i=2) cout<<"n请输入DVD的相关信息!n" for(v=k1;v<20;v+) cout<<"物品名称:"cin>>a; cout<<"n物品颜色:" cin>>b; cout<<"n物品的生产厂商:" cin>>c; cout<<"n厂商地址:" cin>>d; cout<<"n物品型号:" cin>>e; cout<<"n物品出厂日期:" cin>>m>>n>>h; cout<<"n物品数量:" cin>>n1; d1v.set2(a,b,c,d,e,m,n,h,n1); d1v.pay(); k1+; cout<<"n想继续添加DVD的相关信息吗?(1-是 2-否):" cin>>i1; while(i1!=1&&i1!=2) cout<<"n请重新输入数字1或2:" cin>>i1; if(i1=1) cout<<"n请继续输入DVD的相关信息!n" else break; if(i=3) cout<<"n请输入带DVD的普通电视机的相关信息!n" for(v=k2;v<20;v+) cout<<"物品名称:" cin>>a; cout<<"n物品颜色:" cin>>b; cout<<"n物品的生产厂商:" cin>>c; cout<<"n厂商地址:" cin>>d; cout<<"n物品型号:" cin>>e; cout<<"n物品出厂日期:" cin>>m>>n>>h; cout<<"n物品数量:" cin>>n1; td1v.set3(a,b,c,d,e,m,n,h,n1); td1v.pay(); k2+; cout<<"n想继续添加带DVD的普通电视机的相关信息吗?(1-是 2-否):" cin>>i1; while(i1!=1&&i1!=2) cout<<"n请重新输入数字1或2:" cin>>i1; if(i1=1) cout<<"n请继续输入带DVD的普通电视机的相关信息!n" if(i1=2) break; cout<<"n想添加其他物品的相关信息吗?(1-是 2-否):" cin>>i1; while(i1!=1&&i1!=2) cout<<"n请重新输入数字1或2:"cin>>i1; if(i1=1) cout<<"n请输入数字输入相对应的物品信息(1-普通电视机 2-DVD 3-带DVD的普通电视机):" if(i1=2) break; cout<<"想保存你所输入得数据吗?(1-是 2否):" cin>>rr; while(rr!=1&&rr!=2) cout<<"n请重新输入数字1或2:"cin>>rr; if(rr=1) ofstream ofile("wiring.txt",ios_base:out); for(v=0;v<k;v+) ofile<<"n普通电视机的名称:"<<t1v.name<<"n普通电视机的颜色:" <<t1v.color<<"n普通电视机的出厂地址:"<<t1v.address <<"n普通电视机的出厂的厂商:"<<t1v.factory<<"n普通电视机的型号:" <<t1v.type<<"n普通电视机的出厂日期:"<<t1v.year<<"/"<<t1v.month <<"/"<<t1v.day<<"n普通电视机的单价:"<<t1v.price1<<"n普通电视机的数量:"<<t1v.number<<endl; for(v=0;v<k1;v+) ofile<<"nDVD的名称:"<<d1v.name<<"nDVD的颜色:" <<d1v.color<<"nDVD的出厂地址:"<<d1v.address <<"nDVD的出厂的厂商:"<<d1v.factory<<"DVD的型号:"<<d1v.type<<"nDVD的出厂日期:"<<d1v.year<<"/"<<d1v.month <<"/"<<d1v.day<<"nDVD的单价:"<<d1v.price2<<"nDVD的数量:"<<d1v.number<<endl; for(v=0;v<k2;v+) ofile<<"n带DVD的普通电视机的名称:"<<td1v.name<<"n带DVD的普通电视机的颜色:" <<td1v.color<<"n带DVD的普通电视机的出厂地址:"<<td1v.address <<"n带DVD的普通电视机的出厂的厂商:"<<td1v.factory<<"n带DVD的普通电视机的型号:"<<td1v.type<<"n带DVD的普通电视机的出厂日期:"<<td1v.year<<"/"<<td1v.month <<"/"<<td1v.day<<"n带DVD的普通电视机的单价:"<<td1v.price<<"n带DVD的普通电视机的数量:"<<td1v.number<<endl; ofile.close(); cout<<"n物品信息已储存!" cout<<"n按键1返回菜单:" cin>>r1; while(r1!=1) cout<<"n请重新输入数字1:"cin>>r1; if(r1=1) system("cls");caidan(); if(r1=2) cout<<"n退出程序!" if(rr=2) cout<<"n按键1返回菜单2退出程序:" cin>>r1; while(r1!=1&&r1!=2) cout<<"n请重新输入数字1或2:"cin>>r1; if(r1=1) system("cls");caidan(); if(r1=2) cout<<"n退出程序!" void shown()/显示物品信息 cout<<"n从文件中读取物品信息n" char ch;int nn; ifstream ofile("wiring.txt"); while(ofile.get(ch) cout<<ch; ofile.close(); cout<<"请按键1返回菜单或按键2退出程序:" cin>>nn; while(nn!=1&&nn!=2) cout<<"请重新输入数字1或2:"cin>>nn; if(nn=1) system("cls"); caidan(); if(nn=2) cout<<"退出程序!n" void searchw()/查找物品信息 void caidan(); char namestr20;int rr;int i,j; cout<<"n请输入你想查找的物品类型(1-普通电视机 2-DVD 3-带DVD的普通电视机):" cin>>rr; while(rr!=1&&rr!=2&&rr!=3) cout<<"n请重新输入数字1或2或3:"cin>>rr; if(rr=1) cout<<"n请输入你要查找的普通电视机名称:" cin>>namestr; for(i=0;i<k;i+) if(strcmp(namestr,t1i.name)=0) cout<<"n普通电视机的名称:"<<t1i.name<<"n普通电视机的颜色:"<<t1i.color<<"n普通电视机的出厂地址:"<<t1i.address <<"n普通电视机的出厂的厂商:"<<t1i.factory<<"n普通电视机的型号:" <<t1i.type<<"n普通电视机的出厂日期:"<<t1i.year<<"/"<<t1i.month <<"/"<<t1i.day<<"n普通电视机的单价:"<<t1i.price1<<"n普通电视机的数量:"<<t1i.number<<endl;break; if(i=k) cout<<"n对不起没有你所要的普通电视机的相关信息!n" if(rr=2) cout<<"n请输入你要查找的DVD名称:" cin>>namestr; for(i=0;i<k1;i+) if(strcmp(namestr,d1i.name)=0) cout<<"nDVD的名称:"<<d1i.name<<"nDVD的颜色:" <<d1i.color<<"nDVD的出厂地址:"<<d1i.address <<"nDVD的出厂的厂商:"<<d1i.factory<<"nDVD的型号:"<<d1i.type<<"nDVD的出厂日期:"<<d1i.year<<"/"<<d1i.month <<"/"<<d1i.day<<"nDVD的单价:"<<d1i.price2<<"nDVD的数量:"<<d1i.number<<endl;break; if(i=k1) cout<<"n对不起没有你所要的DVD的相关信息!n" if(rr=3) cout<<"n请输入你要查找的带DVD的普通电视机的名称:" cin>>namestr; for(i=0;i<k2;i+) if(strcmp(namestr,td1i.name)=0) cout<<"n带DVD的普通电视机的名称:"<<td1i.name<<"n带DVD的普通电视机的颜色:" <<td1i.color<<"n带DVD的普通电视机的出厂地址:"<<td1i.address <<"n带DVD的普通电视机的出厂的厂商:"<<td1i.factory<<"n带DVD的普通电视机的型号:" <<td1i.type<<"n带DVD的普通电视机的出厂日期:"<<td1i.year<<"/"<<td1i.month <<"/"<<td1i.day<<"n带DVD的普通电视机的单价:"<<td1i.price<<"n带DVD的普通电视机的数量:"<<td1i.number<<endl;break; if(i=k2) cout<<"n对不起没有你所要的带DVD的普通电视机的相关信息!n" cout<<"n请输入数字键1返回菜单或数字键2退出程序:" cin>>j; while(j!=1&&j!=2) cout<<"n请重新输入数字1或2:" cin>>j; if(j=1) system("cls");caidan();if(j=2) cout<<"n退出程序!" void selectw()/删除物品信息 void caidan(); char namestr20;int rr,i,r1,i1(-1),i2(-1),i3(-1); cout<<"n请输入你要删除的物品信息(1-普通电视机 2-DVD 3-带DVD的普通电视机):" cin>>rr; while(rr!=1&&rr!=2&&rr!=3) cout<<"n请重新输入数字1或2或3:"cin>>rr; if(rr=1) cout<<"n请输入你想删除的普通电视机名称:" cin>>namestr; for(i=0;i<k;i+) if(strcmp(namestr,t1i.name)=0) i1=i; if(rr=2) cout<<"n请输入你想删除的DVD名称:" cin>>namestr; for(i=0;i<k1;i+) if(strcmp(namestr,d1i.name)=0) i2=i; if(rr=3) cout<<"n请输入你想删除的带DVD的普通电视机的名称:" cin>>namestr; for(i=0;i<k2;i+) if(strcmp(namestr,td1i.name)=0) i3=i; cout<<"想保存删除后的信息吗?(1-是 2-否):" cin>>r1; while(r1!=1&&r1!=2) cout<<"请重新输入数字1或2:"cin>>r1; if(r1=1) ofstream ofile("wiring.txt",ios_base:out); for(i=0;i<k;i+) if(i=i1) continue; else ofile<<"n普通电视机的名称:"<<t1i.name<<"n普通电视机的颜色:" <<t1i.color<<"n普通电视机的出厂地址:"<<t1i.address <<"n普通电视机的出厂的厂商:"<<t1i.factory<<"n普通电视机的型号:" <<t1i.type<<"n普通电视机的出厂日期:"<<t1i.year<<"/"<<t1i.month <<"/"<<t1i.day<<"n普通电视机的单价:"<<t1i.price1<<"n普通电视机的数量:"<<t1i.number<<endl; for(i=0;i<k1;i+) if(i=i2) continue; else ofile<<"nDVD的名称:"<<d1i.name<<"nDVD的颜色:" <<d1i.color<<"nDVD的出厂地址:"<<d1i.address <<"nDVD的出厂的厂商:"<<d1i.factory<<"nDVD的型号:"<<d1i.type<<"nDVD的出厂日期:"<<d1i.year<<"/"<<d1i.month <<"/"<<d1i.day<<"nDVD的单价:"<<d1i.price2<<"nDVD的数量:"<<d1i.number<<endl; for(i=0;i<k2;i+) if(i=i3) continue; else ofile<<"n带DVD的普通电视机的名称:"<<td1i.name<<"n带DVD的普通电视机的颜色:" <<td1i.color<<"n带DVD的普通电视机的出厂地址:"<<td1i.address <<"n带DVD的普通电视机的出厂的厂商:"<<td1i.factory<<"n带DVD的普通电视机的型号:" <<td1i.type<<"n带DVD的普通电视机的出厂日期:"<<td1i.year<<"/"<<td1i.month <<"/"<<td1i.day<<"n带DVD的普通电视机的单价:"<<td1i.price<<"n带DVD的普通电视机的数量:"<<td1i.number<<endl; ofile.close(); cout<<"n物品信息已保存!n" cout<<"按键1返回菜单2退出程序:" cin>>r1; while(r1!=1&&r1!=2) cout<<"请重新输入数字1或2:"cin>>r1; if(r1=1) system("cls"); caidan(); if(r1=2) cout<<"退出程序!n" void savew()/保存物品信息 void caidan(); ofstream ofile("wiring.txt",ios_base:out); int i,rr; for(i=0;i<k;i+) ofile<<"n普通电视机的名称:"<<t1i.name<<"n普通电视机的颜色:" <<t1i.color<<"n普通电视机的出厂地址:"<<t1i.address <<"n普通电视机的出厂的厂商:"<<t1i.factory<<"n普通电视机的型号:" <<t1i.type<<"n普通电视机的出厂日期:"<<t1i.year<<"/"<<t1i.month <<"/"<<t1i.day<<"n普通电视机的单价:"<<t1i.price1<<"n普通电视机的数量:"<<t1i.number<<endl; for(i=0;i<k1;i+) ofile<<"nDVD的名称:"<<d1i.name<<"nDVD的颜色:" <<d1i.color<<"nDVD的出厂地址:"<<d1i.address <<"nDVD的出厂的厂商:"<<d1i.factory<<"DVD的型号:"<<d1i.type<<"nDVD的出厂日期:"<<d1i.year<<"/"<<d1i.month <<"/"<<d1i.day<<"nDVD的单价:"<<d1i.price2<<"nDVD的数量:"<<d1i.number<<endl; for(i=0;i<k2;i+) ofile<<"n带DVD的普通电视机的名称:"<<td1i.name<<"n带DVD的普通电视机的颜色:" <<td1i.color<<"n带DVD的普通电视机的出厂地址:"<<td1i.address <<"n带DVD的普通电视机的出厂的厂商:"<<td1i.factory<<"n带DVD的普通电视机的型号:" <<td1i.type<<"n带DVD的普通电视机的出厂日期:"<<td1i.year<<"/"<<td1i.month <<"/"<<td1i.day<<"n带DVD的普通电视机的单价:"<<td1i.price<<"n带DVD的普通电视机的数量:"<<td1i.number<<endl; ofile.close(); cout<<"n物品信息已储存!" cout<<"n输入数字键1返回菜单,2退出程序:" cin>>rr; while(rr!=1&&rr!=2) cout<<"