金山急救箱,一道大作业,但相对高手来说是小菜,急救!!!!

一道大作业,但相对高手来说是小菜,急救!!!! - 故障解答 - 电脑教程网

一道大作业,但相对高手来说是小菜,急救!!!!

日期:2007-03-30   荐:
一道大作业,但相对高手来说是小菜,急救!!!!用C++编程任务:1. 设计一个管理信息系统,如课程管理系统、学生管理系统、图书管理系统等MIS,能完成以下功能:a) 录入信息b) 查询信息:可按单个条件查询,也可做成按多个条件查询c) 插入和删除。插入信息,删除满足条件的信息。d) 修改信息2. 用链表作存储结构来实现。3. 界面做成基于DOS的或图形界面的都可以。上交内容:1. 系统详细功能说明2. 源码3. 系统使用说明/*这是头文件,包含用到的函数和类的声明*/#include "iostream"#include "string"#include "stdio.h"#include "fstream"using namespace std;void test(void);void choice(int choice);class student{public: void display(void); void set(void);string getname(void);string getaddress(void); bool getsex(void); int getstuid(void); int getage(void);void save(ofstream &save);bool load(ifstream &load);private:string name;string address;bool sex;int stuid; int age;};/*这是main函数部分*/#include "stdlib.h"#include "sfy.h"#include "iostream"using namespace std; int main(void){ int choose; test();while (1){system("cls");cout<<"*****************************************";cout<<"这是一个学生信息管理程序,在这里你可以"<<"进行查询、删除、添加、修改等操作!"<<" "<<"警告:在程序运行过程中,请不要非法关闭,否则"<<"会造成所有的数据信息丢失!!!"<<"PROGRAMMED BY 梁宇"<<endl;cout<<"*****************************************";cout<<"现在你可以进行下面的操作。"<<"1.查询;\t\t"<<"2.删除;" <<"3.添加;\t\t"<<"4.修改;" <<"5.备份数据库;\t\t"<<"6.从备份数据库导入;"<<"7.按学号从小到大排序。\t"<<"0.退出。"<<endl;cout<<"请选择:";cin>>choose;cout<<choose;choice(choose);}return 0;}......要半年才做的完善的,老大,你也太,,,,#include "iostream"#include "string"#include "list"#include "stdlib.h" #include "sfy.h"#include "stdio.h"#include "fstream"int testflag=0;void student::display(void){cout<<"\t\t\t学生信息如下:\t\t" <<"名字:\t"<<name<<'' <<"学号:\t"<<stuid<<''<<"性别:\t"<<(sex?"女":"男")<<'' <<"年龄:\t"<<age<<''<<"籍贯:\t"<<address<<endl;system("pause");}void student::set(void){cout<<"请输入学生的名字:"; cin>>name; cout<<"请输入学生的性别:"<<"0.男;" <<"1.女."<<"请选择:";cin>>sex; cout<<"请输入学生的学号:"; cin>>stuid; cout<<"请输入学生的年龄:"; cin>>age;cout<<"请输入学生的籍贯:";cin>>address; cout<<'';}string student::getname(void){return name;}string student::getaddress(void){return address;}bool student::getsex(void){return sex;}int student::getstuid(void){return stuid;}int student::getage(void){return age;}void student::save(ofstream &save){save<<name<<endl;save<<sex<<endl;save<<stuid<<endl;save<<age<<endl;save<<address<<endl;}bool student::load(ifstream &load){getline(load,name);load>>sex;load>>stuid;load>>age;load>>address;char ch;load.get(ch);return load.good() && ch == '';}void choice(int choice){string cname; student stu; int stuid;bool flag=0;static bool readflag=0;static list<student> L;static list<student>::iterator i;static ifstream load;static ofstream save;static ifstream loadbak;static ofstream savebak; list<student>::iterator j,k;//排序所用的迭代器。if(readflag==0&&choice!=6&&choice!=3&&choice!=0){if(testflag==0){load.open("data.txt"); if(!load){cout<<"读数据发生错误(可能是没有数据文件引起),现在退出。"; exit(1);} else{do{stu.load(load); L.push_front(stu);}while(!load.eof());} L.erase(L.begin()); load.close();}else{do{cout<<"如果有备份数据库,请先从备份数据库导入。"<<"如果没有,请先添加!!!"<<endl; cin>>choice;}while(choice!=6&&choice!=3&&choice!=0);}}readflag=1; switch (choice){case 1: system("cls");cout<<"请输入你要查询的学生学号 :"; cin>>stuid;i=L.begin(); while (i!=L.end()){ if (stuid==(*i).getstuid()){flag=1;(*i).display();break;}else{ i;}}if (!flag){cout<<"数据库没有学号"<<stuid<<"的信息!"; system("pause");}break;case 2: system("cls");cout<<"请输入要删除的学生学号:"; cin>>stuid;i=L.begin();while (i!=L.end()){ if ((*i).getstuid()==stuid){(*i).display();flag=1;cout<<"确实要删除此学生的信息吗?Y/N:";char choose;cin>>choose; if(choose=='y'||choose=='Y'){L.erase(i);cout<<"信息已删除!";system("pause");break;}else{cout<<"数据没有改动。";system("pause");}break;}else{ i;}}if (!flag){cout<<"数据库没有学生"<<cname<<"的信息!";system("pause");}break;case 3:system("cls");cout<<"你现在要添加学生的信息,请按提示输入。";stu.set();stuid=stu.getstuid(); i=L.begin(); while (i!=L.end()){ if ((*i).getstuid()==stuid){cout<<"经检查,在数据库已有此学号的信息。";(*i).display();flag=1;break;}else{ i;}}if (!flag){L.push_front(stu);cout<<"已在数据库添加如下信息。";i=L.begin();(*i).display();}break;case 4:system("cls");cout<<"请输入你要修改的学生学号:";cin>>stuid;i=L.begin();while (i!=L.end()){ if (stuid==(*i).getstuid()){(*i).display();flag=1;cout<<"确实要修改此学生的信息吗?Y/N:";char choose;cin>>choose; if(choose=='y'||choose=='Y'){L.erase(i); stu.set(); L.push_front(stu); cout<<"已修改此学生的信息。"; (*L.begin()).display(); flag=1;break;}else{cout<<"数据没有改动。";system("pause");}break;}else{ i;}}if (!flag){cout<<"数据库没有学生"<<cname<<"的信息!";system("pause");}break;case 5:system("cls");savebak.open("data.bak");if(!savebak){cout<<"创建备份文件错误。";cout<<"按任意键返回。";}else{for(i=L.begin();i!=L.end();i ){(*i).save(savebak);}cout<<"备份数据库成功!!!"<<endl;savebak.close(); system("pause");}break;case 6:system("cls");cout<<"现在从备份数据库导入数据。";L.clear(); loadbak.open("data.bak"); if(!loadbak){cout<<"读数据发生错误,现在退出。"; exit(1);} else{do{stu.load(loadbak); L.push_front(stu);}while(!loadbak.eof());}L.erase(L.begin()); loadbak.close();cout<<"导入成功!"<<endl;system("pause");break;case 7: system("cls");for(k=L.begin();k!=--L.end();k ){for(j= k,k--;j!=L.end();j ){if((*k).getstuid()>(*j).getstuid()){stu=(*k); (*k)=(*j); (*j)=stu;}}}cout<<"已经从小到大排序好,以下逐步显示:"; for(i=L.begin();i!=L.end();i ){(*i).display();} cout<<"已经显示完毕,现在按任意键返回主界面。"<<endl; system("pause"); break;case 0:cout<<endl;save.open("data.txt"); if(!save) {cout<<"保存数据出错!!!"<<endl;}else{for(i=L.begin();i!=L.end();i ){(*i).save(save);}}save.close();cout<<"数据已经保存。"<<endl;cout<<"谢谢使用。";system("xplayer.exe");exit(0);default:cout<<"你输入有错,请重新输入。";system("pause");}}void test(void){list<student> L;list<student>::iterator i;student stu;char choice;ifstream load("data.txt");if(!load){cout<<"在当前目录找不到数据文件,是否创建?Y/N"<<endl;cin>>choice;if(choice!='y'&&choice!='Y'){cout<<" 你选择的不是创建,因为没有数据,所以无法导入,";cout<<" 如果有备份数据库,随后请从备份数据库导入,如果"<<" 没有,请先添加。"<<endl; testflag=1; system("pause");}else{ofstream save("data.txt");if(!save){cout<<"创建文件失败,现在退出。"<<endl;system("pause"); exit(1);}else{cout<<"创建成功,现在请你往数据文件里面添加数据:"; char cho; do{stu.set(); L.push_front(stu);cout<<"是否继续添加?Y/N:";cin>>cho;}while(cho=='y'||cho=='Y');for(i=L.begin();i!=L.end();i ){(*i).save(save);}} save.close();}}else{load.close();}}出现过N亿次的作业题,估计在Google上也可以搜到源代码了要用链表实现的。其实最重要的是要实现查询功能,我不知该怎么做,用遍历吗?还是用什么方法?cadn 里早就有同学问到了~~可以查的到不好意思,不符题意~~有人救我吗?急!!!// student.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <tchar.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <locale>#define SIZE sizeof(struct Student)struct Student/*定义结构体*/{long int num;char name[50];char sex;float score1;float score2;float score3;struct Student *next;}stu;struct Student *head,*End; /*定义链表头和尾*/void new_input();/*声明函数*/void menu_search();void find1();void find2();void menu_delete();void del_info1();void del_info2();void menu_edit();void edit_info1();void edit_info2();void insert();void save();void load_info();void output();void sort();void ChangeOrder(Student *p1,Student *p2);int _tmain(int argc, _TCHAR* argv[])/*主函数*/{ int choice;while(1){printf("\t\t\t ^_^欢迎使用学生信息管理系统^_^");printf("\t\t\t MAIN MENU");printf("\t\t\t ================");printf("\t\t\t 1.新建学生信息");printf("\t\t\t 2.查询学生信息");printf("\t\t\t 3.删除学生信息");printf("\t\t\t 4.修改学生信息");printf("\t\t\t 5.插入学生信息");printf("\t\t\t 6.保存学生信息");printf("\t\t\t 7.导出学生信息");printf("\t\t\t 8.输出学生信息");printf("\t\t\t 9.排序学生信息");printf("\t\t\t 0.退出管理系统");printf("\t\t\t ================");printf("Please choose a number between 0 to 9:");scanf("%d",&choice);switch(choice){ case 1:new_input();break;case 2:menu_search();break;case 3:menu_delete();break;case 4:menu_edit();break;case 5:insert();break;case 6:save();break;case 7:load_info();break;case 8:output();break;case 9:sort();output();break;case 0:{printf("1.保存后退出.");printf("2.不保存退出.");printf("Do you want to save the information before exit?");int choice;printf("Please enter your choice:");scanf("%d",&choice);switch(choice){case 1:{FILE* fp;struct Student *stud;stud=head;char* filename;printf("Please enter a name which you to save the infomation:");filename=(char*)malloc(15);scanf("%s",filename);printf("The information is saved in file %s.",filename);fp=fopen(filename,"wb");for(;stud!=NULL;){fwrite(stud,SIZE,1,fp);stud=stud->next;}printf("The file have been saved.");fclose(fp);printf("谢谢您的使用.");exit(0);}break;case 2:{ printf("谢谢您的使用.");exit(0);}break;default:{printf("Please enter a number between 1 to 2.");exit(0);}}} break;default:{ printf("Please enter a number betweent 0 to 9.");exit(0);}}}return 0;}void new_input()/*新建学生信息*/{struct Student *stud;int NUM,i;printf("Input the students amount:");/*输入学生的个数*/scanf("%d",&NUM);for(i=1;i<=NUM;i ){stud=(struct Student *)malloc(SIZE);printf("Please input the students' information.");printf("They are num,name,sex,score1,score2,score3:");scanf("%ld %s %c %f %f %f",&stud->num,stud->name,&stud->sex,\&stud->score1,&stud->score2,&stud->score3);printf("%ld %s %c %.2f %.2f %.2f",stud->num,stud->name,stud->sex,\stud->score1,stud->score2,stud->score3);if(head==NULL){End=head=stud;stud->next=NULL;}else {End->next=stud;End=stud;}}End->next=NULL; }void menu_search(void)/*查找子菜单*/{int choice;while(1){printf("\t\t\t 查询子菜单");printf("\t\t\t ==============");printf("\t\t\t 1.按学号查询");printf("\t\t\t 2.按姓名查询");printf("\t\t\t 0.返回主菜单");printf("\t\t\t =============="); printf("Please choose a number between 0 to 2:");scanf("%d",&choice); switch(choice){case 1:find1();//调用按学号查询函数break;case 2:find2();//调用按姓名查询函数break;case 0:return;default:{printf("Please enter a number betweent 0 to 2.");exit(0);}}}}void menu_delete(void)/*删除子菜单*/{int choice;while(1){printf("\t\t\t 删除子菜单");printf("\t\t\t ==============");printf("\t\t\t 1.按学号删除");printf("\t\t\t 2.按姓名删除");printf("\t\t\t 0.返回主菜单");printf("\t\t\t =============="); printf("Please choose a number between 0 to 2:");scanf("%d",&choice); switch(choice){case 1:del_info1();//调用按学号删除函数break;case 2:del_info2();//调用按姓名删除函数break;case 0:return;default:{printf("Please enter a number betweent 0 to 2.");exit(0);}}}}void menu_edit(void)/*修改子菜单*/{int choice;while(1){printf("\t\t\t 修改子菜单");printf("\t\t\t ==============");printf("\t\t\t 1.按学号修改");printf("\t\t\t 2.按姓名修改");printf("\t\t\t 0.返回主菜单");printf("\t\t\t =============="); printf("Please choose a number between 0 to 2:");scanf("%d",&choice); switch(choice){case 1:edit_info1();//调用按学号修改函数break;case 2:edit_info2();//调用按姓名修改函数break;case 0:return;default:{printf("Please enter a number betweent 0 to 2.");exit(0);}}}}void insert()/*插入学生信息*/{struct Student *stud=(struct Student*)malloc(SIZE);int NUM,i;printf("Please input the numbers of student you want to insert:");/*插入学生的个数*/scanf("%d",&NUM);for(i=1;i<=NUM;i ){struct Student *stud=(struct Student*)malloc(SIZE);printf("Please input the students' infomation.");printf("They are num,name,sex,score1,score2,score3:");scanf("%ld %s %c %f %f %f",&stud->num,stud->name,&stud->sex,\&stud->score1,&stud->score2,&stud->score3);printf("%ld %s %c %.2f %.2f %.2f",stud->num,stud->name,stud->sex,\stud->score1,stud->score2,stud->score3);if(head==NULL){End=head=stud;stud->next=NULL;}else {End->next=stud;End=stud;}}End->next=NULL;}void save()/*保存学生信息*/{FILE* fp;struct Student *stud;stud=head;char *filename;printf("Please enter a name which you to save the infomation:");filename=(char*)malloc(15);scanf("%s",filename);printf("The infomation is saved in file %s.",filename);fp=fopen(filename,"wb");for(;stud!=NULL;){fwrite(stud,SIZE,1,fp);stud=stud->next;}printf("The file have been saved.");fclose(fp);return;}void load_info()/*导出已经存在的文件*/{FILE *fp;char * filename;filename=(char *)malloc(20);printf("Please enter a filename:");scanf("%s",filename);if((fp=fopen(filename,"rb"))==NULL){printf("Can not open file.");return;}else{struct Student* stud; stud=(struct Student *)malloc(SIZE);fread(stud,SIZE,1,fp);head=stud;End=stud; while(1){stud=(struct Student *)malloc(SIZE);if(fread(stud,SIZE,1,fp)){End->next=stud;End=stud;} else break;}}fclose(fp);End->next=NULL;return;}void output()/*输出学生信息*/{struct Student* stud;stud=head;printf("Num\tName\tSex\tScore1\tScore2\tScore3"); do{if(stud==NULL){printf("It is NULL now.Please new_input the infomation."); return;}else{printf("%ld\t%s\t%c\t%.2f\t%.2f\t%.2f\t",stud->num,stud->name,stud->sex,\stud->score1,stud->score2,stud->score3);stud=stud->next;}}while(stud!=NULL);/*int item;item=getchar();*/return;}void ChangeOrder(Student *p1,Student *p2)/*交换学生信息*/{struct Student stu;stu=*p2;p2->score1=p1->score1;p2->score2=p1->score2;p2->score3=p1->score3;p2->num=p1->num; strcpy(p2->name,p1->name);p2->sex=p1->sex;p1->score1=stu.score1;p1->score2=stu.score2; p1->score3=stu.score3;p1->num=stu.num; strcpy(p1->name,stu.name);p1->sex=stu.sex;return;}void sort()/*对学生信息进行排序*/{ struct Student *p1,*p2;int Choose;printf("1.Sort by score1.");printf("2.Sort by score2.");printf("3.Sort by score3.");printf("4.Sort by num.");printf("Please choose a subject to sort:");scanf("%d",&Choose);switch(Choose){case 1: for(p1=head;p1!=NULL;p1=p1->next){ for(p2=p1;(p2=p2->next)!=NULL;){if(p1->score1<p2->score1){ChangeOrder(p1,p2);}}}break;case 2: for(p1=head;p1!=NULL;p1=p1->next){ for(p2=p1;(p2=p2->next)!=NULL;){if(p1->score2<p2->score2){ChangeOrder(p1,p2);}}}break;case 3: for(p1=head;p1!=NULL;p1=p1->next){ for(p2=p1;(p2=p2->next)!=NULL;){if(p1->score3<p2->score3){ChangeOrder(p1,p2);}}}break;case 4:for(p1=head;p1!=NULL;p1=p1->next){ for(p2=p1;(p2=p2->next)!=NULL;){if(p1->num>p2->num){ChangeOrder(p1,p2);}}}break;}return;}void find1()//按学号查询{struct Student *stud;long int num;stud=head;printf("Please the num you want to search:"); scanf("%ld",&num);while(stud){if(stud->num==num){ printf("The infomation of the student is:");printf("\t Information ");printf("\t===========================");printf("Num\tName\tSex\tScore1\tScore2\tScore3"); printf("%ld\t%s\t%c\t%.2f\t%.2f\t%.2f",stud->num,stud->name,stud->sex,\stud->score1,stud->score2,stud->score3);break;}else{stud=stud->next;}}return;}void find2()//按姓名查询{struct Student *stud;char *name;name=(char*)malloc(50);stud=head;printf("Please enter the name you want to search:");scanf("%s",name);while(stud){if(!strcmp(name,stud->name)) {printf("The infomation of the student is:");printf("\t Information ");printf("\t===========================");printf("Num\tName\tSex\tScore1\tScore2\tScore3"); printf("%ld\t%s\t%c\t%.2f\t%.2f\t%.2f\t",stud->num,stud->name,stud->sex,\stud->score1,stud->score2,stud->score3);break;}else {stud=stud->next;}}return;}void del_info1()//按学号删除{struct Student *stud,*previous;long int num;previous=stud=head;printf("Please enter the num you want to delete:"); scanf("%ld",&num);while(stud){if(stud->num==num){ if(stud==head){head=stud->next;free(stud);}else{previous->next=stud->next;free(stud);}break;}else{previous=stud;stud=stud->next;}}return;}void del_info2()//按姓名删除{struct Student *stud,*previous;char *name;name=(char*)malloc(50);stud=previous=head;printf("Please enter the name you want to delete:");scanf("%s",name);while(stud){if(!strcmp(name,stud->name)){ if(stud==head){head=stud->next;free(stud);}else{previous->next=stud->next;free(stud);}break;}else{previous=stud;stud=stud->next;}}return;}void edit_info1()//按学号修改{struct Student *stud;long int num;stud=head;printf("Please the num you want to edit:"); scanf("%ld",&num);while(stud){if(stud->num==num){printf("The infomation of the student is:");printf("\t Information ");printf("\t===========================");printf("Num\tName\tSex\tScore1\tScore2\tScore3"); printf("%ld\t%s\t%c\t%.2f\t%.2f\t%.2f\t",stud->num,stud->name,stud->sex,\stud->score1,stud->score2,stud->score3);printf("Please input the student's infomation.");printf("They are num,name,sex,score1,score2,score3:");scanf("%ld %s %c %f %f %f",&stud->num,stud->name,&stud->sex,\&stud->score1,&stud->score2,&stud->score3);printf("The infomation of the student is:");printf("\t Information ");printf("\t===========================");printf("Num\tName\tSex\tScore1\tScore2\tScore3"); printf("%ld\t%s\t%c\t%.2f\t%.2f\t%.2f\t",stud->num,stud->name,stud->sex,\stud->score1,stud->score2,stud->score3);break;}else{stud=stud->next; }}return;}void edit_info2()//按姓名修改{struct Student *stud,*previous;char *name;name=(char*)malloc(50);stud=previous=head;printf("Please enter the name you want to edit:");scanf("%s",name);while(stud){if(!strcmp(name,stud->name)) {printf("The infomation of the student is:");printf("\t Information ");printf("\t===========================");printf("Num\tName\tSex\tScore1\tScore2\tScore3"); printf("%ld\t%s\t%c\t%.2f\t%.2f\t%.2f\t",stud->num,stud->name,stud->sex,\stud->score1,stud->score2,stud->score3);printf("Please input the students' infomation.");printf("They are num,name,sex,score1,score2,score3:");scanf("%ld %s %c %f %f %f",&stud->num,stud->name,&stud->sex,\&stud->score1,&stud->score2,&stud->score3);printf("The infomation of the student is:");printf("\t Information ");printf("\t===========================");printf("Num\tName\tSex\tScore1\tScore2\tScore3"); printf("%ld\t%s\t%c\t%.2f\t%.2f\t%.2f\t",stud->num,stud->name,stud->sex,\stud->score1,stud->score2,stud->score3);break;}else{previous=stud;stud=stud->next;}}return;}代码能找么?在那啊?
标签: