C++选修课系统.docx
《C++选修课系统.docx》由会员分享,可在线阅读,更多相关《C++选修课系统.docx(24页珍藏版)》请在冰豆网上搜索。
![C++选修课系统.docx](https://file1.bdocx.com/fileroot1/2023-2/7/a1c3caa3-459f-45ed-9f6b-02f1271ccd0d/a1c3caa3-459f-45ed-9f6b-02f1271ccd0d1.gif)
C++选修课系统
#include
#include
#include
#include
#include
#include
#include
usingnamespacestd;
ofstreamfout;
ifstreamfin;
typedefstructsubjects//课程结构体
{
intnum;//课程编号
charname[20];//课程名称
charkind[10];//课程性质
intstime;//总学时
intttime;//授课学时
intetime;//实验或上机学时
intscore;//学分
intterm;//开课学期
structsubjects*next;
}SUB;
SUB*head=NULL;
//创建链表模块
SUB*create_form()//创建链表
{
SUB*head,*tail,*p;
intnum,stime,ttime;
intetime,score,term;
charname[20],kind[10];
intsize=sizeof(SUB);
head=tail=NULL;
cout<<'\t'<<"输入选修课程信息:
"<cin>>num;
cin>>name;
cin>>kind;
cin>>stime;
cin>>ttime;
cin>>etime;
cin>>score;
cin>>term;
while(num!
=0)
{
p=(SUB*)malloc(size);
p->num=num;
strcpy(p->name,name);
strcpy(p->kind,kind);
p->stime=stime;
p->ttime=ttime;
p->etime=etime;
p->score=score;
p->term=term;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
cin>>num;
cin>>name;
cin>>kind;
cin>>stime;
cin>>ttime;
cin>>etime;
cin>>score;
cin>>term;
}
tail->next=NULL;
returnhead;
}
//保存文件模块
voidsavefile()//保存文件
{
SUB*p;
FILE*fp;
fp=fopen("1.txt","w");
if(fp==NULL)
exit(0);
fout<<"课程编号"<<''<<"课程名称"<<''<<"课程性质"<<''<<"总学时"<<''
<<"授课学时"<<''<<"实验或上机学时"<<''<<"学分"<<''<<"开课学期"
<for(p=head;p;p=p->next)
fout<num<name<kind<stime
<ttime<etime<score<<term<fclose(fp);
fout<<'\t'<<"创建后的信息已放入'1.txt文件中"<system("pause");
}
voidsavefile1()//保存文件2
{
SUB*p;
FILE*fp;
fp=fopen("2.txt","w");
if(fp==NULL)
exit(0);
fout<<"课程编号"<<''<<"课程名称"<<''<<"课程性质"<<''<<"总学时"<<''
<<"授课学时"<<''<<"实验或上机学时"<<''<<"学分"<<''<<"开课学期"
<for(p=head;p;p=p->next)
fout<num<name<kind
<stime<ttime<etime
<score<term<fclose(fp);
fout<<'\t'<<"创建后的信息已放入'2.txt文件中"<system("pause");
}
//读取文件模块
voidreadfile()//读取文件
{
void*myInsert(SUB*);
SUB*newSub;//新课程
intnum,stime,ttime,etime;
intscore,term;
charc,name[20],kind[10],fname[20];
cout<<'\t'<<"请输入课程信息所在的文件名称:
";
cin>>fname;
FILE*fp;
fp=fopen(fname,"r");
while(!
feof(fp))
{
if((c=fgetc(fp))=='\n')
break;
}
while(!
feof(fp))
{
newSub=(SUB*)malloc(sizeof(SUB));
fin>>newSub->num;
fin>>newSub->name;
fin>>newSub->kind;
fin>>newSub->stime;
fin>>newSub->ttime;
fin>>newSub->etime;
fin>>newSub->score;
fin>>newSub->term;
myInsert(newSub);
}
fclose(fp);
}
//浏览模块
voiddisplay()
{
SUB*ptr;
head=NULL;
readfile();
if(head==NULL)
{
cout<cout<cout<<'\t'<<"*********没有相关记录*********"<return;
}
fout<<"课程编号"<<''<<"课程名称"<<''<<"课程性质"<<''<<"总学时"<<''
<<"授课学时"<<''<<"实验或上机学时"<<''<<"学分"<<''<<"开课学期"
<for(ptr=head;ptr;ptr=ptr->next)
{
fout<num<name<kind
<stime<ttime<etime
<score<term<}
system("pause");
}
//插入链表
void*myInsert(SUB*subj)
{
SUB*ptr,*ptr2;
ptr=subj;
if(head==NULL)
{
head=ptr;
head->next=NULL;
}
else
{
for(ptr2=head;ptr2;ptr2=ptr2->next)
if(ptr2->next==NULL)
{
ptr2->next=subj;
subj->next=NULL;
break;
}
}
returnhead;
}
//添加模块
void*insert()//插入课程信息
{
SUB*ptr,*subj;
intsize=sizeof(SUB);
intn;
charch,ch1;
while(ch=='\0')
{
subj=(SUB*)malloc(size);
ptr=subj;
cout<<'\t'<<"************************************************************"<cout<<'\t'<<"输入要插入的课程信息"<cout<<'\t'<<"************************************************************"<cout<cout<<'\t'<<"请输入课程编号:
";
cin>>subj->num;
cout<cout<<'\t'<<"请输入课程名称:
";
cin>>subj->name;
cout<cout<<'\t'<<"请输入课程性质:
";
cin>>subj->kind;
cout<cout<<'\t'<<"请输入课程总学时:
";
cin>>subj->stime;
cout<cout<<'\t'<<"请输入课程授课学时:
";
cin>>subj->ttime;
cout<cout<<'\t'<<"请输入实验或上机学时:
";
cin>>subj->etime;
cout<cout<<'\t'<<"请输入课程学分:
";
cin>>subj->score;
cout<cout<<'\t'<<"请输入课程开课学期:
";
cin>>subj->term;
myInsert(subj);
cout<cout<<"继续插入请按回车键"<ch1=getchar();//将回车键赋给ch1,否则subj->term输完后输入的回车键会赋给ch,因此用ch1填补
cout<<"结束添加课程请输入0:
";
ch=getchar();
}
returnhead;
}
//删除模块
void*del()//删除课程
{
SUB*p1,*p2;
charch,ch1;
intnum;
while(ch!
='\0')
{
cout<<"输入想要删除的课程的编号:
";
cin>>num;
if(head->num==num)
{
p2=head;
head=head->next;
free(p2);
}
if(head==NULL)
returnNULL;
p1=head;
p2=head->next;
while(p2)
{
if(p2->num==num)
{
p1->next=p2->next;
free(p2);
}
else
p1=p2;
p2=p1->next;
}
cout<cout<<"继续删除请按回车键,结束删除请按0:
";
ch1=getchar();
ch=getchar();
}
returnhead;
system("pause");
}
//选修课程模块
voidchoose()
{
SUB*p,*q;
inta[5];
intnum,total=0,i=0,j;
cout<<'\t'<<"输入要选修课程的编号,编号之间用空格分开:
";
cin>>num;
cout<<'\t'<<"输入完成请输入0:
";
while(num!
=0)
{
for(p=head;p;p=p->next)
if(p->num==num)
{
total=total+p->score;
a[i]=num;
i++;
}
cin>>num;
}
if(total<60)
{
cout<<"选修总学分为"<"<system("pause");
}
else
{
FILE*fp;
fp=fopen("3.txt","w");
fout<<"课程编号"<<''<<"课程名称"<<''<<"课程性质"<<''<<"总学时"<<''
<<"授课学时"<<''<<"实验或上机学时"<<''<<"学分"<<''<<"开课学期"
<for(j=0;j
for(q=head;q;q=q->next)
if(q->num==a[j])
fout<num<name<kind<stime
<ttime<etime<score<<term<fclose(fp);
//printf("\t\t*****选修成功*****\n");
cout<<'\t'<<'\t'<<"*****选修成功*****"<//printf("\n你选修的课程总学分为%d,课程分别为:
\n,total");
cout<cout<<"你选修的课程总学分为"<"<<"课程编号"<<''<<"课程名称"
<<''<<"课程性质"<<''<<"总学时"<<''<<"授课学时"<<''<<"实验或上机学时"<<''
<<"学分"<<''<<"开课学期"<for(j=0;j
for(q=head;q;q->next)
if(q->num==a[j])
cout<num<name<kind
<stime<ttime<etime
<score<term<cout<cout<<"以上信息全部保存在'3.txt'中"<}
system("pause");
}
//查询模块
voidsearch()
{
inta,num;
intt=1;
chartype[10],min[10];
SUB*ptr;
L1:
system("cls");
puts("\t***********************请选择查询方式***********************\n");
puts("\t******************1.按课程名称查找******************\n");
puts("\t******************2.按课程性质查找******************\n");
puts("\t******************3.按学分查找******************\n");
puts("\t******************4.退出查找******************\n");
puts("\t************************************************************\n");
cout<<'\t'<<"请选择操作(1-4):
";
cin>>a;
switch(a)
{
case1:
cout<<'\t'<<"请输入要查找课程的名称:
";//按课程名查找
cin>>min;
cout<<"**********************************************************************"<cout<<"课程编号"<<''<<"课程名称"<<''<<"课程性质"<<''<<"总学时"<<''
<<"授课学时"<<''<<"实验或上机学时"<<''<<"学分"<<''<<"开课学期"
<for(ptr=head;ptr;ptr=ptr->next)
if(strcmp(min,ptr->name)==0)
{
cout<num<name<kind
<stime<ttime<etime
<score<term<t=0;
}
if(t)
cout<cout<<"*******************************未找到!
*******************************"<t=1;
system("pause");
gotoL1;
case2:
cout<<'\t'<<"请输入要查找课程的性质:
";//按课程性质查找
cin>>type;
cout<<"**********************************************************************"<cout<<"课程编号"<<''<<"课程名称"<<''<<"课程性质"<<''<<"总学时"<<''
<<"授课学时"<<''<<"实验或上机学时"<<''<<"学分"<<''<<"开课学期"
<for(ptr=head;ptr;ptr=ptr->next)
if(strcmp(type,ptr->kind)==0)
{
cout<num<name<kind
<stime<ttime<etime
<score<term<t=0;
}
if(t)
cout<cout<<"*******************************未找到!
*******************************"<t=1;
system("pause");
gotoL1;
case3:
cout<<'\t'<<"请输入要查找课程的学分:
";//按课程学分查找
cin>>num;
cout<<"**********************************************************************"<cout<<"课程编号"<<''<<"课程名称"<<''<<"课程性质"<<''<<"总学时"<<''
<<"授课学时"<<''<<"实验或上机学时"<<''<<"学分"<<''<<"开课学期"
<for(ptr=head;ptr;ptr=ptr->next)
if(ptr->score==num)
{
cout<num<name<kind
<stime<ttime<etime
<score<term<t=0;
}
if(t)
cout<cout<<"*******************************未找到!
*******************************"<t=1;
system("pause");
gotoL1;
case4:
break;//退出查找
}
}
//管理员功能模块
/*
voidManagers()
{
inta,j;
intn,w=1,flag=0,i=3;
chars[8];
charpassword[]="000";
do
{
cout<<'\t'<<"请输入密码:
";
j=0;
while
(1)
{
a=getch();
if(a==13)
break;
s[j]=a;
j++;
cout<<'*';
}
s[j]='\0';
if(!
strcmp(s,password))//进行密码验证
{
flag=1;
break;
}
else
{
cout<<'\t'<<'\t'<<"密码错误!
你还有"<i--;
}
}
while(i>0);
if(!
flag)
{
cout<<'\t'<<"你输入的密码错误超过3次!
自动退出...";
exit(0);
}
do
{
system("cls");
puts("\t**********************管理员菜单**********************\n");
puts("\t******************1.浏览课程******************\n");