1、CC+课程设计选题管理系统课程设计选题管理系统 作者:admin 日期:2008-05-23/*设计学生类;课程设计题目类(序号,题目,人数,描述);每个题目限两个人选;要求使用面向对象编程进行模拟课程设计选题;要求以链表格式存储,信息保存在文件中。主要包括下列模块:1 新增、修改、删除课程设计题目;2 新增、修改、删除学生信息;3 查询课程设计内容;4 课程设计选题;*/#include #include #include using namespace std;class Student long num; char name20; char subject30; Student *Nex
2、t; Student *Head;public: int Creat() FILE *fp; Head = NULL; /存放链表的起始地址 Student *p, *pEnd; p = new Student; /创建一个Teacher的动态对象 if(fp=fopen(Student.txt,r)=NULL) cout can not open file! num,p-name,p-subject); /输入指针p指向的对象的数据成员的值 pEnd = Head; / 存放当前对象的地址 while(!feof(fp) / 0 是输入结束的标志 if(NULL = Head) Head =
3、 p; / 只在第一次执行此语句 else pEnd-Next = p; / 存放下一个对象的地址 pEnd = p; p = new Student; /动态创建下一个对象 fscanf(fp,%ld%s%s,&p-num,p-name,p-subject); /输入下一个对象数据成员的值 pEnd-Next = NULL; return 0; int Newstudent() FILE *fp; cout 请输入增加的学生的相关信息: endl; cout num ; cout endl; cout name; cout endl; cout subject; cout endl; if(
4、fp=fopen(student.txt,a)=NULL) cout can not open file! endl; exit(0); fprintf(fp,%ld %s %sn,num,name,subject); fclose (fp); return 0; int Modify()/修改 FILE *fp; Student *p; char namer20; Creat(); cout namer; cout name) p=p-Next; if(p=NULL) break; if(p!=NULL) cout 你要修改的学生的相关信息如下: endl endl; cout num na
5、me subject endl endl; cout 请输入修改后的相关信息: endl endl; cout p-num; cout endl; cout p-name; cout endl; cout p-subject; cout endl; if(fp=fopen(Student.txt,w)=NULL) cout can not open file! num,p-name,p-subject); p=p-Next; while(p!=NULL); fclose (fp); else cout 没有找到你想要修改的题目的信息 endl; else cout 文件中还没有任何题目endl
6、; return 0; int Del()/删除 FILE *fp; Student *p,*p1; char namer30; Creat(); cout namer; cout name) p1=p; p=p-Next; if(p=NULL) break; if(p!=NULL) cout 你要删除的题目的相关信息如下: endl; cout 姓名 : name endl; cout 学号 : num endl; cout 所选题目: subject Next; else p1-Next=p-Next; if(fp=fopen(Student.txt,w)=NULL) cout can n
7、ot open file! num,p-name,p-subject); p=p-Next; while(p!=NULL); fclose (fp); cout 该学生的所有信息已被删除! endl; else cout 没有找到你想要删除的学生的信息 endl; else cout 文件中还没有任何学生的信息endl; return 0; ;class Subject/* int serial_number;/序号 char subject30; /题目 int peoples;/限定人数 int people;/已选人数 char description100;/描述 Subject *n
8、ext; Subject *head;public: int Chosesubject(); int creat(); int newsubject(); int modify(); int del(); int demand();int Subject:creat() FILE *fp; head = NULL; /存放链表的起始地址 Subject *p, *pEnd; p = new Subject; /创建一个Teacher的动态对象 if(fp=fopen(Subject.txt,r)=NULL) cout can not open file! serial_number,p-sub
9、ject,&p-peoples,p-description,&p-people); /输入指针p指向的对象的数据成员的值 pEnd = head; / 存放当前对象的地址 while(!feof(fp) / 0 是输入结束的标志 if(NULL = head) head = p; / 只在第一次执行此语句 else pEnd-next = p; / 存放下一个对象的地址 pEnd = p; p = new Subject; /动态创建下一个对象 fscanf(fp,%d%s%d%s%d,&p-serial_number,p-subject,&p-peoples,p-description,&p
10、-people); /输入下一个对象数据成员的值 pEnd-next = NULL; return 0;int Subject:newsubject()/*增加 FILE *fp; cout serial_number; cout endl; cout subject; cout endl; cout peoples; cout endl; cout description; cout endl; cout people; cout endl; if(fp=fopen(Subject.txt,a)=NULL) cout can not open file! endl; exit(0); fpr
11、intf(fp,%d %s %d %s %dn,serial_number,subject,peoples,description,people); return 0;int Subject:modify()/*修改 FILE *fp; Subject *p; char sub30; creat(); cout sub; cout subject) p=p-next; if(p=NULL) break; if(p!=NULL) cout 你要修改的题目的相关信息如下: endl; cout serial_number subject people description endl; cout
12、请输入修改后的相关信息: endl; cout p-serial_number; cout endl; cout p-subject; cout endl; cout p-peoples; cout endl; cout p-description; cout endl; cout p-people; cout endl; if(fp=fopen(Subject.txt,w)=NULL) cout can not open file! serial_number,p-subject,p-peoples,p-description,p-people); p=p-next; while(p!=NU
13、LL); fclose (fp); else cout 没有找到你想要修改的题目的信息 endl; else cout 文件中还没有任何题目endl; return 0;int Subject:del()/*删除 FILE *fp; Subject *p,*p1; char sub30; creat(); cout sub; cout subject) p1=p; p=p-next; if(p=NULL) break; if(p!=NULL) cout 你要删除的题目的相关信息如下: endl; cout 序号 : serial_number endl; cout 题目 : subject e
14、ndl; cout 限定人数: peoples endl; cout 题目描述: description endl; cout 已选人数: people next; else p1-next=p-next; if(fp=fopen(Subject.txt,w)=NULL) cout can not open file! serial_number,p-subject,p-peoples,p-description,p-people); p=p-next; while(p!=NULL); fclose (fp); cout 该题目的所有信息已被删除! endl; else cout 没有找到你想
15、要删除的题目的信息 endl; else cout 文件中还没有任何题目endl; return 0;int Subject:demand()/*查询课程设计题目 Subject *p,*p1; char sub30; creat(); cout 所有题目列表如下 endl; p=head; while(p != NULL) cout 序号: serial_number 题目 : subject endl; cout next; cout sub; cout subject) p1=p; p=p-next; if(p=NULL) break; if(p!=NULL) cout 关于该题目有如下
16、描述: endl description endl; else cout 没有找到你想要修改的题目的信息 endl; else cout 文件中还没有任何题目endl; return 0;int Subject:Chosesubject() FILE *fp; Subject *p,*p1; char sub30; creat(); cout sub; cout subject) p1=p; p=p-next; if(p=NULL) break; if(p!=NULL) if(p-people=p-peoples) cout 人数超限!你不能再选择此题目! people+; if(fp=fop
17、en(Subject.txt,w)=NULL) cout can not open file! serial_number,p-subject,p-peoples,p-description,p-people); p=p-next; while(p!=NULL); cout *选题成功!* endl; fclose (fp); else cout 没有找到你想要修改的题目的信息 endl; else cout 文件中还没有任何题目endl; return 0;int main() system(color 1d); Subject a; Student b; char choice;coutn
18、nt 欢迎使用课程设计选课系统nn; coutt1.添加新的科目n; coutt2.*删除所选内容*n; coutt3.修改课程设计信息n; coutt4.*添加新的学生的相关信息*n; coutt5.删除学生记录nnn; coutt6.*修改学生相关信息*n; coutt7.查询课程设计内容n; coutt8.*进行课程设计选课*n; coutt0.退出系统nnn; coutt *制作人:肖涛*nnn; coutt *指导老师:范永全*nnn;coutchoice; if(choice=0) exit(0);else if(choice=1) a.newsubject();system(pa
19、use);main(); else if(choice=2) a.del();system(pause); main();else if(choice=3) a.modify();system(pause);main();else if(choice=4) b.Newstudent();system(pause);main();elseif(choice=5) b.Del();system(pause);main();else if(choice=6) b.Modify();system(pause);main();else if(choice=7) a.demand();system(pause);main();else if(choice=8) a.Chosesubject();system(pause);main();else cout输入错误,请重新输入您的选择:; system(pause);main(); 文章来自: 本站原创
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1