分享
分销 收藏 举报 申诉 / 33
播放页_导航下方通栏广告

类型C专业课程设计程序.docx

  • 上传人:w****g
  • 文档编号:2864538
  • 上传时间:2024-06-07
  • 格式:DOCX
  • 页数:33
  • 大小:15.14KB
  • 下载积分:12 金币
  • 播放页_非在线预览资源立即下载上方广告
    配套讲稿:

    如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

    特殊限制:

    部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

    关 键  词:
    专业 课程设计 程序
    资源描述:
    #include <iostream> #include <cstring> using std::cout; using std::endl; class Course{ public: 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=new char[strlen(n)+1]; strcpy(this->name,n); } void Course::setName(char n[]){ delete[] name; this->name=new char[strlen(n)+1]; strcpy(this->name,n); } void Course::setNextCourse(Course* c){ this->next=c; } class Person{ public: Person():id(0),name(0),courses(0){} Person(char i[],char n[]); ~Person(); void setID(char i[]); void setName(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 char[strlen(i)+1]; strcpy(this->id,i); this->name=new char[strlen(n)+1]; strcpy(this->name,n); } void Person::setID(char i[]){ delete[] id; this->id=new char[strlen(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 char[strlen(n)+1]; strcpy(this->name,n); } void Person::display(){ cout<<"ID: "<<id<<" Name: "<<name<<" Courses: "; Course* c=courses; while(c!=0){ cout<<c->getName()<<" "; c=c->getNext(); } cout<<endl; } void Person::addCourses(Course* c){ if(courses==0) courses=c; else{ Course* t=courses; while(t->getNext()!=0){ t=t->getNext(); } t->setNextCourse(c); } } class Teacher:public Person{ public: Teacher():Person(),position(0){} Teacher(char id[],char name[],char position[]); Teacher(const Teacher& t); ~Teacher(); void display(); void setPosition(char p[]); char *getPosition(){return position;} private: char* position; }; Teacher::Teacher(char i[], char n[], char p[]):Person(i,n){ position=new char[strlen(position)+1]; strcpy(this->position,p); } Teacher::Teacher(const Teacher& t):Person(){ this->id=new char[strlen(t.id)+1]; strcpy(this->id,t.id); this->name=new char[strlen(t.name)+1]; strcpy(this->name,t.name); this->position=new char[strlen(t.position)+1]; strcpy(this->position,t.position); } Teacher::~Teacher(){ delete[] position; } void Teacher::display(){ cout<<"ID: "<<id<<" Name: "<<name<<" Position: "<<position<<" Courses to teacher: "; Course* c=courses; while(c!=0){ cout<<c->getName()<<" "; c=c->getNext(); } cout<<endl; } void Teacher::setPosition(char p[]){ delete[] position; this->position=new char[strlen(p)+1]; strcpy(this->position,p); } class Postgraduate:public Person{ public: Postgraduate():Person(){degree=new char[strlen("Postgraduate")+1];strcpy(this->degree,"Postgraduate");} Postgraduate(char i[],char n[]); Postgraduate(const Postgraduate& p); ~Postgraduate(); void display(); char *getDegree(){return degree;} private: char* degree; }; Postgraduate::Postgraduate(char i[],char n[]):Person(i,n){ this->degree=new char[strlen("Postgraduate")+1]; strcpy(this->degree,"Postgraduate"); } Postgraduate::Postgraduate(const Postgraduate& p):Person(){ this->id=new char[strlen(p.id)+1]; strcpy(this->id,p.id); this->name=new char[strlen(p.name)+1]; strcpy(this->name,p.name); this->degree=new char[strlen("Postgraduate")+1]; strcpy(this->degree,"Postgraduate"); } Postgraduate::~Postgraduate(){ delete[] degree; } void Postgraduate::display(){ cout<<"ID: "<<id<<" Name: "<<name<<" Degree: "<<degree<<" Courses to study: "; Course* c=courses; while(c!=0){ cout<<c->getName()<<" "; c=c->getNext(); } cout<<endl; } class Undergraduate:public Person{ public: Undergraduate():Person(){degree=new char[strlen("Undergraduate")+1];strcpy(this->degree,"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 char[strlen("Undergraduate")+1]; strcpy(this->degree,"Undergraduate"); } Undergraduate::Undergraduate(const Undergraduate& u):Person(){ this->id=new char[strlen(u.id)+1]; strcpy(this->id,u.id); this->name=new char[strlen(u.name)+1]; strcpy(this->name,u.name); this->degree=new char[strlen("Undergraduate")+1]; strcpy(this->degree,"Undergraduate"); } Undergraduate::~Undergraduate(){ delete[] degree; } void Undergraduate::display(){ cout<<"ID: "<<id<<" Name: "<<name<<" Degree: "<<degree<<" Courses to study: "; Course* c=courses; while(c!=0){ cout<<c->getName()<<" "; c=c->getNext(); } cout<<endl; } class JuniorCollegeStudent:public Person{ public: JuniorCollegeStudent():Person(){degree=new char[strlen("Junior college student")+1];strcpy(this->degree,"Junior college student");} JuniorCollegeStudent(char i[],char n[]); JuniorCollegeStudent(const JuniorCollegeStudent& j); ~JuniorCollegeStudent(); void display(); char *getDegree(){return degree;} private: char* degree; }; JuniorCollegeStudent::JuniorCollegeStudent(char i[],char n[]):Person(i,n){ this->degree=new char[strlen("Junior college student")+1]; strcpy(this->degree,"Junior college student"); } JuniorCollegeStudent::JuniorCollegeStudent(const JuniorCollegeStudent& j){ this->id=new char[strlen(j.id)+1]; strcpy(this->id,j.id); this->name=new char[strlen(j.name)+1]; strcpy(this->name,j.name); this->degree=new char[strlen("Junior college student")+1]; strcpy(this->degree,"Junior college student"); } JuniorCollegeStudent::~JuniorCollegeStudent(){ delete[] degree; } void JuniorCollegeStudent::display(){ cout<<"ID: "<<id<<" Name: "<<name<<" Degree: "<<degree<<" Courses to study: "; Course* c=courses; while(c!=0){ cout<<c->getName()<<" "; c=c->getNext(); } cout<<endl; } #include<stdio.h> #include<stdlib.h> int N1,N2,kk1,kk2,kk3; struct couse * head1; struct student * head2; struct couse//课程信息结构体 { int num1; char name1[20]; int score; int nelepeo;//课程已选人数 int Melepeo;//课程人数上限 struct couse * next; }; struct student//学生信息结构体 { int num2; char name2[20]; int nelenum[50];//已选课程编号 int nelen;//已选课程数量 struct student * next; }; void Ms() { for(kk1=0;kk1<1100;kk1++) for(kk2=0;kk2<1200;kk2++) for(kk3=0;kk3<1200;kk3++); } void keyboardc()//录入课程子函数(从键盘录入) { struct couse *p1,*p2; N1=0; p1=p2=(struct couse*)malloc(sizeof(struct couse)); printf("课程编号\t课程名称\t学分\t课程人数上限\n"); scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo); p1->nelepeo=0; head1=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 filepath[20]; struct couse *p1,*p2; N1=0; printf("输入要读入文件路径:"); 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=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("\t\t\t录入课程信息\n"); printf("\n1.从键盘录入\n"); printf("2.从文件录入\n"); printf("3.返回主菜单\n"); printf("请选择(1~3):\n"); scanf("%d",&i); switch(i) { case(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 <= p1->num1) { if(head1==p1) head1=p0; 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->next; printf("已删除该编号课程!\n"); N1=N1-1; } else printf("无该编号课程!\n"); end:; } void managementc()//课程管理主函数 { struct couse * incouse; int i,num1; printf("\t\t\t课程管理\n"); printf("1.新增课程\n"); printf("2.删除课程\n"); printf("3.返回主菜单\n"); printf("请选择(1~3):\n"); scanf("%d",&i); switch(i) { case(1): { incouse=(struct couse *)malloc(sizeof(struct couse)); 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; 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;i<20;i++) p1->nelenum[i]=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,p1->name2); p1->nelen=0; for(i=0;i<20;i++) p1->nelenum[i]=0; } p2->next=NULL; } void files()//录入学生信息子函数(从文件录入) { int i=0; FILE * fp; char filepath[20]; 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(sizeof(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("\t\t\t录入学生信息\n"); printf("\n1.从键盘录入\n"); printf("2.从文件录入\n"); printf("3.返回主菜单\n"); printf("请选择(1~3):\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->next=NULL; } else { while((p0->num2 > p1->num2) && (p1->next!=NULL)) { p2=p1; p1=p1->next; } if(p0->num2 <= p1->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=head2; 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("\t\t\t学生信息管理\n"); printf("1.新增学生信息\n"); printf("2.删除学生信息\n"); printf("3.返回主菜单\n"); printf("请选择(1~3):\n"); scanf("%d",&i); switch(i) { case(1): { incouse=(struct student *)malloc(sizeof(struct student)); incouse->nelen=0; incouse->nelenum[0]=0; printf("学生学号\t学生姓名\n"); scanf("%d%s",&incouse->num2,incouse->name2); inserts(incouse); break; } case(2): { printf("请输入要删除学生学号:\n"); scanf("%d",&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->nelenum[i]!=0;i++); s->nelenum[i]=num1; (s->nelen)++; p=head1; while(p->num1!=num1) p=p->next; (p->nelepeo)++; } void cheak()//学生选课子函数(查询可选课程) { char e; struct couse * 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->nelenum[i]!=0;i++) { if(c->num1==s->nelenum[i]) t=1; } if(t==0 && (c->nelepeo!=c->Melepeo)) { printf("%d\n",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
    展开阅读全文
    提示  咨信网温馨提示:
    1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
    2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
    3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
    4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
    5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
    6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

    开通VIP折扣优惠下载文档

    自信AI创作助手
    关于本文
    本文标题:C专业课程设计程序.docx
    链接地址:https://www.zixin.com.cn/doc/2864538.html
    页脚通栏广告

    Copyright ©2010-2026   All Rights Reserved  宁波自信网络信息技术有限公司 版权所有   |  客服电话:0574-28810668    微信客服:咨信网客服    投诉电话:18658249818   

    违法和不良信息举报邮箱:help@zixin.com.cn    文档合作和网站合作邮箱:fuwu@zixin.com.cn    意见反馈和侵权处理邮箱:1219186828@qq.com   | 证照中心

    12321jubao.png12321网络举报中心 电话:010-12321  jubao.png中国互联网举报中心 电话:12377   gongan.png浙公网安备33021202000488号  icp.png浙ICP备2021020529号-1 浙B2-20240490   


    关注我们 :微信公众号  抖音  微博  LOFTER               

    自信网络  |  ZixinNetwork