logo资料库

课程设计设备管理系统 C++.doc

第1页 / 共15页
第2页 / 共15页
第3页 / 共15页
第4页 / 共15页
第5页 / 共15页
第6页 / 共15页
第7页 / 共15页
第8页 / 共15页
资料共15页,剩余部分请下载后查看
//设备信息管理系统 //头文件及类 #include #include #include #include using namespace std; class equipment { protected: char name[20]; char type[20]; float price; int amount; char remark[40]; public: equipment *next; equipment(){ } ~equipment(){ } char* gettype(){ return type;}//只有通过它才可以访问相应值 char* getname(){ return name; } float getprice(){ return price;} int getamount(){ return amount; } char* getremark(){ return remark; } void input() { cout<<"\t\t\t 按提示输入:"<>name; cout<<"\t\t 输入设备型号: "; cin>>type; cout<<"\t\t 输入设备单价: "; cin>>price; cout<<"\t\t 输入设备数量: "; cin>>amount; cout<<"\t\t 输入备注(如设备购进日期): ";
cin>>remark; } void input(ifstream & is) { is>>name>>type>>price>>amount>>remark; is.get(); } void output() { cout<next=NULL; key=0; } ~equs(){ delete head; } void input(); void mend(); void del(); int find(equipment **p,char *pt="^",char *pn="^"); void found(); void show();
void count(); void save(); void begin(); void sorted(); int statistics(equipment **p,char *pt="^",char *pn="^"); void sort(int flag); void clear(); void equs::saving(); char mainmenu(); int getkey(){ return key;} void setkey(int k){ key=k; } private: equipment *head; int key; }; char filepl[20];/*用来提取文件路径以及文件名*/ //录入函数 void equs::input() { equipment *p,*p2=NULL; p=head; int n; while(p->next) p=p->next;//p 在链表尾 while(n) { p2=new equipment;//开辟新节点 p2->input();//录入新值 p->next=p2;//插在表尾 p2->next=NULL;//封闭 p=p->next;//p 再次指表 尾 equs::setkey(1);//表记保存数据 cout<<"\t\t\t 按 1 继续,按 0 返回 : "; cin>>n; } } //子查找函数 int equs::find(equipment **p1,char *pt,char *pn)
{ equipment *p; p=head; while(p->next) { (*p1)=p; if( !strcmp( (p->next)->gettype(),pt )||!strcmp( (p->next) ->getname(),pn ) ) return 1; p=p->next; } return 0; } //查找函数 void equs::found() { equipment *p; int n=9; char name[20]="^"; char type[10]="^"; do { cout<<"\t\t1:按型号查找,2:按名称查找: "; cin>>n; }while(n<1||n>2); if(n==1) { cout<<"\t\t\t 输入型号: "; cin>>type; } if(n==2) { cout<<"\t\t\t 输入名称: "; cin>>name; } if(!find(&p,type,name) ) { cout<<"\t\t 找不到您要查找的内容!"<next)->output(); } //删除函数
void equs::del() { equipment *p,*p2; int flag=1; int ask=1; char type[20]; char name[20]; cout<<"1:按型号删除 2:按名称删除:"<>flag; if(flag==1) { cout<<"\t\t\t 输入设备型号: "; cin>>type; } if(flag==2) { cout<<"\t\t\t 输入设备名称: "; cin>>name; } if( !find(&p,type,name) ) { cout<<"\t\t 找不到你要删除的内容!"<next)->output(); p2=p->next; p->next=p2->next; delete p2; equs::setkey(1); cout<>ask; if(ask==1) { equs::saving(); equs::setkey(0);} } //显示函数 void equs::show() { equipment *p; p=head; while(p->next) {
(p->next)->output(); p=p->next; } } //修改函数 void equs::mend() { equipment *p; int n; int ask=1; int ask2=1; char name[20]="^"; char type[10]="^"; do { cout<<"\t\t1:按型号修改,2:按名称修改: "; cin>>n; }while(n<1||n>2); if(n==1) { cout<<"\t\t\t 输入型号: "; cin>>type; } if(n==2) { cout<<"\t\t\t 输入名称: "; cin>>name; } if( !find(&p,type,name) ) { cout<<"\t\t 找不到你要修改的内容!"<next)->output(); (p->next)->input(); equs::setkey(1); cout<>ask; if(ask==1) else mend(); return; cout<
2:等等再说吧:"<>ask; if(ask==1) { equs::saving(); equs::setkey(0);} } //排序函数 void equs::sorted() { int flag=1; int ask=1; cout<<"请您选择排序方法:"<>flag; }while(flag<1||flag>4); sort(flag); show(); cout<>ask; if(ask==1) equs::sorted(); else return; } //子排序函数 void equs::sort(int flag) { equipment *p,*pm,*pp,*pt; p=head; if(flag==1) while(p->next)
{ pt=new equipment; *pt=*(p->next); pm=p; pp=p->next; while(pm->next!=NULL) { if((pm->next)->getamount()getamount()) pp=pm->next; pm=pm->next; } *(p->next)=*pp; *pp=*pt; pp->next=(p->next)->next; (p->next)->next=pt->next; p=p->next; delete(pt); } if(flag==2) while(p->next) { pt=new equipment; *pt=*(p->next); pm=p; pp=p->next; while(pm->next!=NULL) { if((pm->next)->getprice()getprice()) pp=pm->next; pm=pm->next; } *(p->next)=*pp; *pp=*pt; pp->next=(p->next)->next; (p->next)->next=pt->next; p=p->next; delete(pt); } if(flag==3) while(p->next) { pt=new equipment; *pt=*(p->next); pm=p;
分享到:
收藏