收藏 分销(赏)

C专业课程设计程序.docx

上传人:w****g 文档编号:2864538 上传时间:2024-06-07 格式:DOCX 页数:33 大小:15.14KB
下载 相关 举报
C专业课程设计程序.docx_第1页
第1页 / 共33页
C专业课程设计程序.docx_第2页
第2页 / 共33页
C专业课程设计程序.docx_第3页
第3页 / 共33页
C专业课程设计程序.docx_第4页
第4页 / 共33页
C专业课程设计程序.docx_第5页
第5页 / 共33页
点击查看更多>>
资源描述

1、#include #include using std:cout;using std:endl;class Coursepublic: Course():name(0),next(0) Course(char n); Course()delete name; void setName(char n); void setNextCourse(Course* c); char *getName()return name; Course* getNext()return next;private: char* name; Course* next;Course:Course(char n) name

2、=new charstrlen(n)+1; strcpy(this-name,n);void Course:setName(char n) delete name; this-name=new charstrlen(n)+1; strcpy(this-name,n);void Course:setNextCourse(Course* c) this-next=c;class Personpublic: Person():id(0),name(0),courses(0) Person(char i,char n); Person(); void setID(char i); void setNa

3、me(char n); char *getID()return id; char *getName()return name; void addCourses(Course* c); virtual void display();protected: char* id; char* name; Course* courses;Person:Person(char i,char n) this-id=new charstrlen(i)+1; strcpy(this-id,i); this-name=new charstrlen(n)+1; strcpy(this-name,n);void Per

4、son:setID(char i) delete id; this-id=new charstrlen(i)+1; strcpy(this-id,i);Person:Person() Course* c; while(courses!=0) c=courses-getNext(); delete courses; courses=c; delete id; delete name;void Person:setName(char n) delete name; this-name=new charstrlen(n)+1; strcpy(this-name,n);void Person:disp

5、lay() coutID: id Name: name Courses: ; Course* c=courses; while(c!=0) coutgetName()getNext(); coutgetNext()!=0) t=t-getNext(); t-setNextCourse(c); class Teacher:public Personpublic: Teacher():Person(),position(0) Teacher(char id,char name,char position); Teacher(const Teacher& t); Teacher(); void di

6、splay(); void setPosition(char p); char *getPosition()return position;private: char* position;Teacher:Teacher(char i, char n, char p):Person(i,n) position=new charstrlen(position)+1; strcpy(this-position,p);Teacher:Teacher(const Teacher& t):Person() this-id=new charstrlen(t.id)+1; strcpy(this-id,t.i

7、d); this-name=new charstrlen(t.name)+1; strcpy(this-name,t.name); this-position=new charstrlen(t.position)+1; strcpy(this-position,t.position);Teacher:Teacher() delete position;void Teacher:display() coutID: id Name: name Position: position Courses to teacher: ; Course* c=courses; while(c!=0) coutge

8、tName()getNext(); coutposition=new charstrlen(p)+1; strcpy(this-position,p);class Postgraduate:public Personpublic: Postgraduate():Person()degree=new charstrlen(Postgraduate)+1;strcpy(this-degree,Postgraduate); Postgraduate(char i,char n); Postgraduate(const Postgraduate& p); Postgraduate(); void di

9、splay(); char *getDegree()return degree;private: char* degree;Postgraduate:Postgraduate(char i,char n):Person(i,n) this-degree=new charstrlen(Postgraduate)+1; strcpy(this-degree,Postgraduate);Postgraduate:Postgraduate(const Postgraduate& p):Person() this-id=new charstrlen(p.id)+1; strcpy(this-id,p.i

10、d); this-name=new charstrlen(p.name)+1; strcpy(this-name,p.name); this-degree=new charstrlen(Postgraduate)+1; strcpy(this-degree,Postgraduate);Postgraduate:Postgraduate() delete degree;void Postgraduate:display() coutID: id Name: name Degree: degree Courses to study: ; Course* c=courses; while(c!=0)

11、 coutgetName()getNext(); coutdegree,Undergraduate); Undergraduate(char i,char n); Undergraduate(const Undergraduate& u); Undergraduate(); void display(); char *getDegree()return degree;private: char* degree;Undergraduate:Undergraduate(char i, char n):Person(i,n) this-degree=new charstrlen(Undergradu

12、ate)+1; strcpy(this-degree,Undergraduate);Undergraduate:Undergraduate(const Undergraduate& u):Person() this-id=new charstrlen(u.id)+1; strcpy(this-id,u.id); this-name=new charstrlen(u.name)+1; strcpy(this-name,u.name); this-degree=new charstrlen(Undergraduate)+1; strcpy(this-degree,Undergraduate);Un

13、dergraduate:Undergraduate() delete degree;void Undergraduate:display() coutID: id Name: name Degree: degree Courses to study: ; Course* c=courses; while(c!=0) coutgetName()getNext(); coutdegree,Junior college student); JuniorCollegeStudent(char i,char n); JuniorCollegeStudent(const JuniorCollegeStud

14、ent& j); JuniorCollegeStudent(); void display(); char *getDegree()return degree;private: char* degree;JuniorCollegeStudent:JuniorCollegeStudent(char i,char n):Person(i,n) this-degree=new charstrlen(Junior college student)+1; strcpy(this-degree,Junior college student);JuniorCollegeStudent:JuniorColle

15、geStudent(const JuniorCollegeStudent& j) this-id=new charstrlen(j.id)+1; strcpy(this-id,j.id); this-name=new charstrlen(j.name)+1; strcpy(this-name,j.name); this-degree=new charstrlen(Junior college student)+1; strcpy(this-degree,Junior college student);JuniorCollegeStudent:JuniorCollegeStudent() de

16、lete degree;void JuniorCollegeStudent:display() coutID: id Name: name Degree: degree Courses to study: ; Course* c=courses; while(c!=0) coutgetName()getNext(); coutendl;#include #includeint N1,N2,kk1,kk2,kk3;struct couse * head1;struct student * head2;struct couse/课程信息结构体 int num1; char name120; int

17、 score; int nelepeo;/课程已选人数 int Melepeo;/课程人数上限 struct couse * next;struct student/学生信息结构体 int num2; char name220; int nelenum50;/已选课程编号 int nelen;/已选课程数量 struct student * next;void Ms() for(kk1=0;kk11100;kk1+) for(kk2=0;kk21200;kk2+) for(kk3=0;kk3num1,p1-name1,&p1-score,&p1-Melepeo);p1-nelepeo=0;he

18、ad1=NULL;while(p1-num1!=0) N1=N1+1; if(N1=1)head1=p1; else p2-next=p1; p2=p1; p1=(struct couse * )malloc(sizeof(struct couse); scanf(%d%s%d%d,&p1-num1,p1-name1,&p1-score,&p1-Melepeo); p1-nelepeo=0;p2-next=NULL;void filec()/录入键盘子函数(从文件录入) FILE * fp; char filepath20; struct couse *p1,*p2; N1=0; printf

19、(输入要读入文件路径:); getchar(); gets(filepath); if(fp=fopen(filepath,r)=NULL) printf(找不到%s文件!n,filepath); exit(0); p1=p2=(struct couse*)malloc(sizeof(struct couse); fscanf(fp,%d%s%d%d%d,&p1-num1,p1-name1,&p1-score,&p1-nelepeo,&p1-Melepeo); head1=NULL; while(!feof(fp) N1=N1+1; if(N1=1)head1=p1; else p2-next

20、=p1; p2=p1; p1=(struct couse * )malloc(sizeof(struct couse); fscanf(fp,%d%s%d%d%d,&p1-num1,p1-name1,&p1-score,&p1-nelepeo,&p1-Melepeo); p2-next=NULL;void inputc()/录入课程主函数 int i; printf(ttt录入课程信息n); printf(n1.从键盘录入n); printf(2.从文件录入n); printf(3.返回主菜单n); printf(请选择(13):n); scanf(%d,&i); switch(i) case

21、(1):keyboardc();break; case(2):filec();break; case(3):break; void insertc(struct couse *incouse)/课程管理子函数(增加课程) struct couse *p0,*p1,*p2; p1=head1; p0=incouse; if(head1=NULL) head1=p0; p0-next=NULL; else while(p0-num1 p1-num1) & (p1-next!=NULL) p2=p1; p1=p1-next; if(p0-num1 num1) if(head1=p1) head1=p

22、0; else p2-next=p0; p0-next=p1; else p1-next=p0; p0-next=NULL; N1=N1+1;void delc(int num1)/课程管理子函数(删除课程) struct couse *p1,*p2; if(head1=NULL) printf(n没有课程,无法删除!n); goto end; p1=head1; while(num1!=p1-num1 & p1-next!=NULL) p2=p1; p1=p1-next; if(num1=p1-num1) if(p1=head1) head1=p1-next; else p2-next=p1

23、-next; printf(已删除该编号课程!n); N1=N1-1; else printf(无该编号课程!n); end:;void managementc()/课程管理主函数 struct couse * incouse; int i,num1; printf(ttt课程管理n); printf(1.新增课程n); printf(2.删除课程n); printf(3.返回主菜单n); printf(请选择(13):n); scanf(%d,&i); switch(i) case(1): incouse=(struct couse *)malloc(sizeof(struct couse)

24、; printf(课程编号t课程名称t学分t课程人数上限n); scanf(%d%s%d%d,&incouse-num1,incouse-name1,&incouse-score,&incouse-Melepeo); incouse-nelepeo=0; insertc(incouse); break; case(2): printf(请输入要删除课程编号:n); scanf(%d,&num1); delc(num1); break; case(3):break; void keyboards()/录入学生信息子函数(从键盘录入) int i; struct student *p1,*p2;

25、N2=0; p1=p2=(struct student *)malloc(sizeof(struct student); printf(学生学号t学生姓名n); scanf(%d%s,&p1-num2,p1-name2); p1-nelen=0; for(i=0;inelenumi=0; head2=NULL; while(p1-num2!=0) N2=N2+1; if(N2=1)head2=p1; else p2-next=p1; p2=p1; p1=(struct student * )malloc(sizeof(struct student); scanf(%d%s,&p1-num2,p

26、1-name2); p1-nelen=0; for(i=0;inelenumi=0; p2-next=NULL;void files()/录入学生信息子函数(从文件录入) int i=0; FILE * fp; char filepath20; struct student *p1,*p2; N2=0; printf(输入要读入文件路径:); getchar(); gets(filepath); if(fp=fopen(filepath,r)=NULL) printf(找不到%s文件!n,filepath); exit(0); p1=p2=(struct student*)malloc(siz

27、eof(struct student); fread(p1,sizeof(struct student),1,fp); head2=NULL; while(!feof(fp) i=0; N2=N2+1; if(N2=1)head2=p1; else p2-next=p1; p2=p1; p1=(struct student * )malloc(sizeof(struct student); fread(p1,sizeof(struct student),1,fp); p2-next=NULL;void inputs()/录入学生信息主函数 int i; printf(ttt录入学生信息n);

28、printf(n1.从键盘录入n); printf(2.从文件录入n); printf(3.返回主菜单n); printf(请选择(13):n); scanf(%d,&i); switch(i) case(1):keyboards();break; case(2):files();break; case(3):break; void inserts(struct student * incouse)/学生信息管理子函数(填加学生信息) struct student *p0,*p1,*p2; p1=head2; p0=incouse; if(head2=NULL) head2=p0; p0-ne

29、xt=NULL; else while(p0-num2 p1-num2) & (p1-next!=NULL) p2=p1; p1=p1-next; if(p0-num2 num2) if(head2=p1) head2=p0; else p2-next=p0; p0-next=p1; else p1-next=p0; p0-next=NULL; N2=N2+1;void dels(int num2)/学生信息管理子函数(删除学生信息) struct student *p1,*p2; if(head2=NULL) printf(n没有该学生信息,无法删除!n); goto end; p1=hea

30、d2; while(num2!=p1-num2 & p1-next!=NULL) p2=p1; p1=p1-next; if(num2=p1-num2) if(p1=head2) head2=p1-next; else p2-next=p1-next; printf(已删除该学生信息!n); N2=N2-1; else printf(无该学号学生!n); end:;void managements()/学生信息管理主函数 struct student * incouse; int i,num2; printf(ttt学生信息管理n); printf(1.新增学生信息n); printf(2.删

31、除学生信息n); printf(3.返回主菜单n); printf(请选择(13):n); scanf(%d,&i); switch(i) case(1): incouse=(struct student *)malloc(sizeof(struct student); incouse-nelen=0; incouse-nelenum0=0; printf(学生学号t学生姓名n); scanf(%d%s,&incouse-num2,incouse-name2); inserts(incouse); break; case(2): printf(请输入要删除学生学号:n); scanf(%d,&

32、num2); dels(num2); break; case(3):break; void elect(struct student * s)/选课 struct couse * p; int num1,i; printf(请输入要选课编号:n); scanf(%d,&num1); for(i=0;s-nelenumi!=0;i+); s-nelenumi=num1; (s-nelen)+; p=head1; while(p-num1!=num1) p=p-next; (p-nelepeo)+;void cheak()/学生选课子函数(查询可选课程) char e; struct couse

33、* c; struct student * s; int num2,i,j=0,t=0; printf(请输入你学号:); scanf(%d,&num2); s=head2; while(s-num2!=num2 & s-next!=NULL) s=s-next; if(s-num2!=num2) printf(不存在你信息,请进入主菜单录入你信息!n); goto end; c=head1; printf(你可选课程编号:n); while(c!=NULL) for(t=0,i=0;s-nelenumi!=0;i+) if(c-num1=s-nelenumi) t=1; if(t=0 & (c-nelepeo!=c-Melepeo) printf(%dn,c-num1); j+; c=c-next; if(j=0) printf(你已选完全部课程,无法再多选!n); goto end; printf(选课(y/n)?:n); getchar(); e=getchar(); i=0; while(e=y) elect(s); printf(继续选课(y/n)?:n); getchar(); e=getchar(); end:;void b

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服