完整版排课程序.docx

上传人:b****7 文档编号:16796983 上传时间:2023-07-17 格式:DOCX 页数:74 大小:27.47KB
下载 相关 举报
完整版排课程序.docx_第1页
第1页 / 共74页
完整版排课程序.docx_第2页
第2页 / 共74页
完整版排课程序.docx_第3页
第3页 / 共74页
完整版排课程序.docx_第4页
第4页 / 共74页
完整版排课程序.docx_第5页
第5页 / 共74页
完整版排课程序.docx_第6页
第6页 / 共74页
完整版排课程序.docx_第7页
第7页 / 共74页
完整版排课程序.docx_第8页
第8页 / 共74页
完整版排课程序.docx_第9页
第9页 / 共74页
完整版排课程序.docx_第10页
第10页 / 共74页
完整版排课程序.docx_第11页
第11页 / 共74页
完整版排课程序.docx_第12页
第12页 / 共74页
完整版排课程序.docx_第13页
第13页 / 共74页
完整版排课程序.docx_第14页
第14页 / 共74页
完整版排课程序.docx_第15页
第15页 / 共74页
完整版排课程序.docx_第16页
第16页 / 共74页
完整版排课程序.docx_第17页
第17页 / 共74页
完整版排课程序.docx_第18页
第18页 / 共74页
完整版排课程序.docx_第19页
第19页 / 共74页
完整版排课程序.docx_第20页
第20页 / 共74页
亲,该文档总共74页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

完整版排课程序.docx

《完整版排课程序.docx》由会员分享,可在线阅读,更多相关《完整版排课程序.docx(74页珍藏版)》请在冰点文库上搜索。

完整版排课程序.docx

完整版排课程序

#include

#include

#include

#include

#defineN10

#defineM20

#defineSIZE40

usingnamespacestd;

typedefstructtcnode

{#include

#include

#include

#include

#defineN10

#defineM20

#defineSIZE40

usingnamespacestd;

typedefstructtcnode

{

charname[20];

intipri;

}tclist,*ptclist;

typedefstructnode

{

charname[20];

charnum[20];

intwork_time;

tclisttc[M];

charcbuf[SIZE];

structnode*next;

}tlist,*ptlist;

typedefstructNode

{

charname[20];

charnum[20];

intweek_time;

intall_time;

intpriority;

boolmc;//是否被选

structNode*next;

}clist,*pclist;

classteacher

{

public:

teacher();

~teacher();

voidinitdata();

voidsave();

friendvoidprint(teacher&,ptlist);

tlist*pt;

};

classcourse

{

public:

course();

~course();

voidinitdata();

voidsave();

friendpclistconvert(course&,char*s);

private:

clist*pc;

};

teacher:

:

teacher()

{

pt=NULL;

}

teacher:

:

~teacher()

{

ptlistp;

while(pt)

{

p=pt;

pt=pt->next;

deletep;

}

}

voidteacher:

:

initdata()

{

chartag;

ptlistp=pt;

ptlists;

intt=0;

cout<<"请输入教师信息:

"<

cout<<"姓名\t教师号\t工作量"<

do

{

if(t>=1)

{

cout<<"请输入教师信息:

"<

cout<<"姓名\t教师号\t工作量"<

}

s=(ptlist)malloc(sizeof(tlist));

cin>>s->name>>s->num>>s->work_time;

cout<<"请输入相应课程名及期望值:

"<

for(inti=0;i

cin>>s->tc[i].name>>s->tc[i].ipri;

fflush(stdin);

s->next=NULL;

if(!

pt)

{

pt=s;

p=pt;

}

else

{

p->next=s;

p=p->next;

}

t++;

cout<<"是否继续输入信息:

"<

fflush(stdin);

cin>>tag;

system("cls");

}while((tag=='y'||tag=='Y')&&t

}

voidteacher:

:

save()

{

ptlistp=pt;

charpath[20]="D:

\\teacher.txt";

charstr[50]={'\0'};

cout<<"请选择保存教师信息文件的路径:

"<

cin>>path;

ofstreamoutfile(path);

if(!

outfile)

{

cerr<<"保存失败,请检查所选路径是否正确!

"<

return;

}

sprintf(str,"姓名\t教师号\t工作量\n");

outfile.write((char*)str,strlen(str));

while(p)

{

sprintf(str,"%s\t%s\t%d\n",p->name,p->num,p->work_time);

outfile.write((char*)str,strlen(str));

sprintf(str,"对相应课程的期望值:

\n");

outfile.write((char*)str,strlen(str));

for(inti=0;i

{

sprintf(str,"%s\t%d\n",p->tc[i].name,p->tc[i].ipri);

outfile.write((char*)str,strlen(str));

}

sprintf(str,"\n");

outfile.write((char*)str,strlen(str));

p=p->next;

}

outfile.close();

cout<<"保存成功!

"<

}

course:

:

course()

{

pc=NULL;

}

course:

:

~course()

{

pclistp;

while(pc)

{

p=pc;

pc=pc->next;

deletep;

}

}

voidcourse:

:

initdata()

{

pclistp=pc;

pclists;

chartag;

inti=0;

cout<<"请输入课程信息:

"<

cout<<"课程名\t课程号\t周学时\t总学时\t优先级"<

do{

if(i>=1)

{

cout<<"请输入课程信息:

"<

cout<<"课程名\t课程号\t周学时\t总学时\t优先级"<

}

s=(pclist)malloc(sizeof(clist));

cin>>s->name>>s->num>>s->week_time>>s->all_time>>s->priority;

fflush(stdin);

s->mc=true;

s->next=NULL;

i++;

if(!

pc)

{

pc=s;

p=pc;

}

else

{

p->next=s;

p=p->next;

}

cout<<"是否继续载入课程信息?

y/Y"<

cin>>tag;

system("cls");

}while(tag=='y'||tag=='Y');

}

voidcourse:

:

save()

{

charpath[20]="D:

\\course.txt";

pclistp=pc;

charstr[100]={'\0'};

cout<<"请输入文件保存路径:

"<

cin>>path;

ofstreamoutfile(path);

if(!

outfile)

{

cerr<<"保存失败,请检查输入路径是否正确";

return;

}

sprintf(str,"课程名\t课程号\t周学时\t总学时\t优先级\n");

outfile.write((char*)str,strlen(str));

while(p)

{

sprintf(str,"%s\t%s\t%d\t%d\t%d\n",p->name,p->num,p->week_time,p->all_time,p->priority);

outfile.write((char*)str,strlen(str));

p=p->next;

}

outfile.close();

cout<<"保存成功!

"<

}

voidsort(teacher&t,course&c)

{

ptlistq=t.pt;

ptlistn=t.pt;

ptlistm=n;

intsum=0;

intnum=-1;

srand(time(0));

for(inti=0;i

{

while(m)

{

m=n->next;

if(m==NULL)

break;

for(intj=0;j

if((m->tc[i].ipri==n->tc[j].ipri)&&(0==strcmp(m->tc[i].name,n->tc[j].name)))

{

num=rand()%2;

switch(num)

{

case0:

(convert(c,q->tc[num].name))->mc=false;

break;

case1:

(convert(c,q->tc[num].name))->mc=false;

break;

default:

break;

}

}

n=n->next;

}

while(q)

{

for(inti=0;i

{

if((convert(c,q->tc[i].name))->mc)

{

sum+=(convert(c,q->tc[i].name))->all_time;

(convert(c,q->tc[i].name))->mc=false;

if(i==0)

strcpy(q->cbuf,q->tc[i].name);

else

{

strcat(q->cbuf,"");

strcat(q->cbuf,q->tc[i].name);

}

if(sum>=q->work_time)

break;

}

}

sum=0;

q=q->next;

}

}

cout<<"课程已排好!

"<

}

//test

voidprint(teacher&t)

{

ptlistp=t.pt;

cout<<"最终排课情况:

"<

cout<<"教师姓名\t工作量\t教授课程"<

while(p)

{

cout<name<<"\t\t"<work_time<<"\t"<cbuf<

p=p->next;

}

}

pclistconvert(course&c,char*s)

{

pclistp=c.pc;

while(p)

{

if(0==strcmp(p->name,s))

returnp;

else

p=p->next;

}

cout<<"应用程序出错!

"<

returnNULL;

}

teachertea;

coursecou;

voiddis_menu()

{

boolttag=false;

boolctag=false;

chartag;

intchoice=0;

do{

system("cls");

cout<<">>>>>>>欢迎使用教师排课系统,请根据提示完成相关操作<<<<<<<<<<<<<<<<<<<<"<

cout<<">>>>>>>1:

载入教师信息"<

cout<<">>>>>>>2:

载入课程信息"<

cout<<">>>>>>>3:

存储教师信息"<

cout<<">>>>>>>4:

存储课程信息"<

cout<<">>>>>>>5:

教师排课"<

cout<<">>>>>>>6:

打印排课结果"<

cout<<">>>>>>>0:

退出"<

fflush(stdin);

cout<<"请输入选择:

"<

cin>>choice;

switch(choice)

{

case1:

system("cls");

cout<<"***********教师信息载入******************"<

tea.initdata();

ttag=true;

break;

case2:

system("cls");

cout<<"***********课程信息载入******************"<

cou.initdata();

ctag=true;

break;

case3:

system("cls");

cout<<"***********教师信息保存******************"<

if(!

ttag)

cout<<"请先载入教师信息"<

else

tea.save();

break;

case4:

system("cls");

cout<<"***********课程信息保存******************"<

if(!

ctag)

cout<<"请先载入课程信息"<

else

cou.save();

break;

case5:

system("cls");

cout<<"***********教师排序界面*****************"<

if(!

ttag||!

ctag)

cout<<"请先载入相关信息"<

else

sort(tea,cou);

break;

case6:

system("cls");

cout<<"***********排课信息打印******************"<

if(!

ttag||!

ctag)

cout<<"请先载入相关信息"<

else

print(tea);

break;

default:

system("cls");

cout<<"\t****************THANKSFORYOURUSE***********"<

cout<<"\t*****************感谢使用本系统!

*************"<

exit(0);

}

cout<<"系统使用中........."<

cout<<"是否继续其他操作?

y/Y"<

cin>>tag;

}while(tag=='y'||tag=='Y');

}

voidmain()

{

dis_menu();

}

#include

#include

#include

#include

#defineN10

#defineM20

#defineSIZE40

usingnamespacestd;

typedefstructtcnode

{

charname[20];

intipri;

}tclist,*ptclist;

typedefstructnode

{

charname[20];

charnum[20];

intwork_time;

tclisttc[M];

charcbuf[SIZE];

structnode*next;

}tlist,*ptlist;

typedefstructNode

{

charname[20];

charnum[20];

intweek_time;

intall_time;

intpriority;

boolmc;//是否被选

structNode*next;

}clist,*pclist;

classteacher

{

public:

teacher();

~teacher();

voidinitdata();

voidsave();

friendvoidprint(teacher&,ptlist);

tlist*pt;

};

classcourse

{

public:

course();

~course();

voidinitdata();

voidsave();

friendpclistconvert(course&,char*s);

private:

clist*pc;

};

teacher:

:

teacher()

{

pt=NULL;

}

teacher:

:

~teacher()

{

ptlistp;

while(pt)

{

p=pt;

pt=pt->next;

deletep;

}

}

voidteacher:

:

initdata()

{

chartag;

ptlistp=pt;

ptlists;

intt=0;

cout<<"请输入教师信息:

"<

cout<<"姓名\t教师号\t工作量"<

do

{

if(t>=1)

{

cout<<"请输入教师信息:

"<

cout<<"姓名\t教师号\t工作量"<

}

s=(ptlist)malloc(sizeof(tlist));

cin>>s->name>>s->num>>s->work_time;

cout<<"请输入相应课程名及期望值:

"<

for(inti=0;i

cin>>s->tc[i].name>>s->tc[i].ipri;

fflush(stdin);

s->next=NULL;

if(!

pt)

{

pt=s;

p=pt;

}

else

{

p->next=s;

p=p->next;

}

t++;

cout<<"是否继续输入信息:

"<

fflush(stdin);

cin>>tag;

system("cls");

}while((tag=='y'||tag=='Y')&&t

}

voidteacher:

:

save()

{

ptlistp=pt;

charpath[20]="D:

\\teacher.txt";

charstr[50]={'\0'};

cout<<"请选择保存教师信息文件的路径:

"<

cin>>path;

ofstreamoutfile(path);

if(!

outfile)

{

cerr<<"保存失败,请检查所选路径是否正确!

"<

return;

}

sprintf(str,"姓名\t教师号\t工作量\n");

outfile.write((char*)str,strlen(str));

while(p)

{

sprintf(str,"%s\t%s\t%d\n",p->name,p->num,p->work_time);

outfile.write((char*)str,strlen(str));

sprintf(str,"对相应课程的期望值:

\n");

outfile.write((char*)str,strlen(str));

for(inti=0;i

{

sprintf(str,"%s\t%d\n",p->tc[i].name,p->tc[i].ipri);

outfile.write((char*)str,strlen(str));

}

sprintf(str,"\n");

outfile.write((char*)str,strlen(str));

p=p->next;

}

outfile.close();

cout<<"保存成功!

"<

}

course:

:

course()

{

pc=NULL;

}

course:

:

~course()

{

pclistp;

while(pc)

{

p=pc;

pc=pc->next;

deletep;

}

}

voidcourse:

:

initdata()

{

pclistp=pc;

pclists;

chartag;

inti=0;

cout<<"请输入课程信息:

"<

cout<<"课程名\t课程号\t周学时\t总学时\t优先级"<

do{

if(i>=1)

{

cout<<"请输入课程信息:

"<

cout<<"课程名\t课程号\t周学时\t总学时\t优先级"<

}

s=(pclist)malloc(sizeof(clist));

cin>>s->name>>s->num>>s->week_time>>s->all_time>>s->priority;

fflush(stdin);

s->mc=true;

s->next=NULL;

i++;

if(!

pc)

{

pc=s;

p=pc;

}

else

{

p->next=s;

p=p->next;

}

cout<<"是否继续载入课程信息?

y/Y"<

cin>>tag;

system("cls");

}while(tag=='y'||tag=='Y');

}

voidcourse:

:

save()

{

charpath[2

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2