CC++课程设计选题管理系统.docx
《CC++课程设计选题管理系统.docx》由会员分享,可在线阅读,更多相关《CC++课程设计选题管理系统.docx(18页珍藏版)》请在冰豆网上搜索。
![CC++课程设计选题管理系统.docx](https://file1.bdocx.com/fileroot1/2023-1/22/007d53b4-19a5-4710-a184-dce369deea2f/007d53b4-19a5-4710-a184-dce369deea2f1.gif)
CC++课程设计选题管理系统
课程设计选题管理系统作者:
admin日期:
2008-05-23
/*设计学生类;课程设计题目类(序号,题目,人数,描述);每个题目限两个人选;要求使用面向对象编程进行模拟课程设计选题;要求以链表格式存储,信息保存在文件中。
主要包括下列模块:
1.新增、修改、删除课程设计题目;
2.新增、修改、删除学生信息;
3.查询课程设计内容;
4.课程设计选题;*/
#include
#include
#include
usingnamespacestd;
classStudent
{
longnum;
charname[20];
charsubject[30];
Student*Next;
Student*Head;
public:
intCreat()
{
FILE*fp;
Head=NULL;//存放链表的起始地址
Student*p,*pEnd;
p=newStudent;//创建一个Teacher的动态对象
if((fp=fopen("Student.txt","r"))==NULL)
{
cout<<"cannotopenfile!
"<exit(0);
}
fscanf(fp,"%ld%s%s",&p->num,p->name,p->subject);//输入指针p指向的对象的数据成员的值
pEnd=Head;//存放当前对象的地址
while(!
feof(fp))
{//0是输入结束的标志
if(NULL==Head)
Head=p;//只在第一次执行此语句
else
pEnd->Next=p;//存放下一个对象的地址
pEnd=p;
p=newStudent;//动态创建下一个对象
fscanf(fp,"%ld%s%s",&p->num,p->name,p->subject);//输入下一个对象数据成员的值
}
pEnd->Next=NULL;
return0;
}
intNewstudent()
{
FILE*fp;
cout<<"请输入增加的学生的相关信息:
"<cout<<"学号:
";
cin>>num;
cout<cout<<"姓名:
";
cin>>name;
cout<cout<<"已选课程设计题目:
";
cin>>subject;
cout<if((fp=fopen("student.txt","a"))==NULL)
{
cout<<"cannotopenfile!
"<exit(0);
}
fprintf(fp,"%ld%s%s\n",num,name,subject);
fclose(fp);
return0;
}
intModify()//修改
{
FILE*fp;
Student*p;
charnamer[20];
Creat();
cout<<"请输入要修改的姓名:
";
cin>>namer;
cout<if(Head!
=NULL)
{
p=Head;
while(strcmp(namer,p->name))
{
p=p->Next;
if(p==NULL)
break;
}
if(p!
=NULL)
{
cout<<"你要修改的学生的相关信息如下:
"<cout<num<<''<name<<''<subject<cout<<"请输入修改后的相关信息:
"<cout<<"请输入修改后的学生的学号:
";
cin>>p->num;
cout<cout<<"请输入修改后的姓名:
";
cin>>p->name;
cout<cout<<"请输入修改后的所选题目:
";
cin>>p->subject;
cout<if((fp=fopen("Student.txt","w"))==NULL)
{
cout<<"cannotopenfile!
"<exit(0);
}
p=Head;
if(Head!
=NULL)
do
{
fprintf(fp,"%ld%s%s\n",p->num,p->name,p->subject);
p=p->Next;
}
while(p!
=NULL);
fclose(fp);
}
else
cout<<"没有找到你想要修改的题目的信息"<}
else
cout<<"文件中还没有任何题目"<return0;
}
intDel()//删除
{
FILE*fp;
Student*p,*p1;
charnamer[30];
Creat();
cout<<"请输入要删除的学生的姓名:
";
cin>>namer;
cout<if(Head!
=NULL)
{
p=Head;
while(strcmp(namer,p->name))
{
p1=p;
p=p->Next;
if(p==NULL)
break;
}
if(p!
=NULL)
{
cout<<"你要删除的题目的相关信息如下:
"<cout<<"姓名:
"<name<cout<<"学号:
"<num<cout<<"所选题目:
"<subject<system("pause");
if(p==Head)Head=p->Next;
else
p1->Next=p->Next;
if((fp=fopen("Student.txt","w"))==NULL)
{
cout<<"cannotopenfile!
"<exit(0);
}
p=Head;
if(Head!
=NULL)
do
{
fprintf(fp,"%ld%s%s\n",p->num,p->name,p->subject);
p=p->Next;
}
while(p!
=NULL);
fclose(fp);
cout<<"该学生的所有信息已被删除!
"<}
else
cout<<"没有找到你想要删除的学生的信息"<}
else
cout<<"文件中还没有任何学生的信息"<return0;
}
};
classSubject//***************************************************************************************
{
intserial_number;//序号
charsubject[30];//题目
intpeoples;//限定人数
intpeople;//已选人数
chardescription[100];//描述
Subject*next;
Subject*head;
public:
intChosesubject();
intcreat();
intnewsubject();
intmodify();
intdel();
intdemand();
};
intSubject:
:
creat()
{
FILE*fp;
head=NULL;//存放链表的起始地址
Subject*p,*pEnd;
p=newSubject;//创建一个Teacher的动态对象
if((fp=fopen("Subject.txt","r"))==NULL)
{
cout<<"cannotopenfile!
"<exit(0);
}
fscanf(fp,"%d%s%d%s%d",&p->serial_number,p->subject,&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=newSubject;//动态创建下一个对象
fscanf(fp,"%d%s%d%s%d",&p->serial_number,p->subject,&p->peoples,p->description,&p->people);//输入下一个对象数据成员的值
}
pEnd->next=NULL;
return0;
}
intSubject:
:
newsubject()//************************************增加
{
FILE*fp;
cout<<"请输入要增加的题目的序号:
";
cin>>serial_number;
cout<cout<<"请输入要增加的题目:
";
cin>>subject;
cout<cout<<"请输入要增加的题目的人数限定:
";
cin>>peoples;
cout<cout<<"请输入要增加的题目的描述:
:
";
cin>>description;
cout<cout<<"请输入要增加的题目的已选人数:
";
cin>>people;
cout<if((fp=fopen("Subject.txt","a"))==NULL)
{
cout<<"cannotopenfile!
"<exit(0);
}
fprintf(fp,"%d%s%d%s%d\n",serial_number,subject,peoples,description,people);
return0;
}
intSubject:
:
modify()//*****************************修改
{
FILE*fp;
Subject*p;
charsub[30];
creat();
cout<<"请输入要修改的题目:
";
cin>>sub;
cout<if(head!
=NULL)
{
p=head;
while(strcmp(sub,p->subject))
{
p=p->next;
if(p==NULL)
break;
}
if(p!
=NULL)
{
cout<<"你要修改的题目的相关信息如下:
"<cout<serial_number<<''<subject<<''<people<<''<description<cout<<"请输入修改后的相关信息:
"<cout<<"请输入修改后的题目的序号:
";
cin>>p->serial_number;
cout<cout<<"请输入修改后的题目:
";
cin>>p->subject;
cout<cout<<"请输入修改后的题目的人数限定:
";
cin>>p->peoples;
cout<cout<<"请输入修改后的题目的描述:
:
";
cin>>p->description;
cout<cout<<"请输入修改后的题目的已选人数:
";
cin>>p->people;
cout<if((fp=fopen("Subject.txt","w"))==NULL)
{
cout<<"cannotopenfile!
"<exit(0);
}
p=head;
if(head!
=NULL)
do
{
fprintf(fp,"%d%s%d%s%d\n",p->serial_number,p->subject,p->peoples,p->description,p->people);
p=p->next;
}
while(p!
=NULL);
fclose(fp);
}
else
cout<<"没有找到你想要修改的题目的信息"<}
else
cout<<"文件中还没有任何题目"<return0;
}
intSubject:
:
del()//****************************************删除
{
FILE*fp;
Subject*p,*p1;
charsub[30];
creat();
cout<<"请输入要删除的题目:
";
cin>>sub;
cout<if(head!
=NULL)
{
p=head;
while(strcmp(sub,p->subject))
{
p1=p;
p=p->next;
if(p==NULL)
break;
}
if(p!
=NULL)
{
cout<<"你要删除的题目的相关信息如下:
"<cout<<"序号:
"<serial_number<cout<<"题目:
"<subject<cout<<"限定人数:
"<peoples<cout<<"题目描述:
"<description<cout<<"已选人数:
"<people<system("pause");
if(p==head)head=p->next;
else
p1->next=p->next;
if((fp=fopen("Subject.txt","w"))==NULL)
{
cout<<"cannotopenfile!
"<exit(0);
}
p=head;
if(head!
=NULL)
do
{
fprintf(fp,"%d%s%d%s%d\n",p->serial_number,p->subject,p->peoples,p->description,p->people);
p=p->next;
}
while(p!
=NULL);
fclose(fp);
cout<<"该题目的所有信息已被删除!
"<}
else
cout<<"没有找到你想要删除的题目的信息"<}
else
cout<<"文件中还没有任何题目"<return0;
}
intSubject:
:
demand()//***************************************查询课程设计题目
{
Subject*p,*p1;
charsub[30];
creat();
cout<<"所有题目列表如下"<p=head;
while(p!
=NULL)
{
cout<<"序号:
"<serial_number<<"题目:
"<subject<cout<p=p->next;
}
cout<<"请输入你想要查看的题目:
";
cin>>sub;
cout<if(head!
=NULL)
{
p=head;
while(strcmp(sub,p->subject))
{
p1=p;
p=p->next;
if(p==NULL)
break;
}
if(p!
=NULL)
cout<<"关于该题目有如下描述:
"<description<else
cout<<"没有找到你想要修改的题目的信息"<}
else
cout<<"文件中还没有任何题目"<return0;
}
intSubject:
:
Chosesubject()
{
FILE*fp;
Subject*p,*p1;
charsub[30];
creat();
cout<<"请输入你要选择的题目:
";
cin>>sub;
cout<if(head!
=NULL)
{
p=head;
while(strcmp(sub,p->subject))
{
p1=p;
p=p->next;
if(p==NULL)
break;
}
if(p!
=NULL)
{
if(p->people>=p->peoples)
{
cout<<"人数超限!
你不能再选择此题目!
"<exit(0);
}
Studenta;
a.Newstudent();
p->people++;
if((fp=fopen("Subject.txt","w"))==NULL)
{
cout<<"cannotopenfile!
"<exit(0);
}
p=head;
if(head!
=NULL)
do
{
fprintf(fp,"%d%s%d%s%d\n",p->serial_number,p->subject,p->peoples,p->description,p->people);
p=p->next;
}
while(p!
=NULL);
cout<<"****选题成功!
***"<fclose(fp);
}
else
cout<<"没有找到你想要修改的题目的信息"<}
else
cout<<"文件中还没有任何题目"<return0;
}
intmain()
{
system("color1d");
Subjecta;
Studentb;
charchoice;
cout<<"\n\n\t★欢迎使用课程设计选课系统★\n\n";
cout<<"\t1.★★★★添加新的科目★★★★★★★★★\n";
cout<<"\t2.********删除所选内容******************\n";
cout<<"\t3.★★★★修改课程设计信息★★★★★★★\n";
cout<<"\t4.********添加新的学生的相关信息********\n";
cout<<"\t5.★★★★删除学生记录★★★★★★★★★\n\n\n";
cout<<"\t6.********修改学生相关信息**************\n";
cout<<"\t7.★★★★查询课程设计内容★★★★★★★\n";
cout<<"\t8.********进行课程设计选课**************\n";
cout<<"\t0.★★★★退出系统★★★★★★★★★★★\n\n\n";
cout<<"\t★***制作人:
肖涛***★\n\n\n";
cout<<"\t★**指导老师:
范永全***★\n\n\n";
cout<<"请输入您的选择:
";
cin>>choice;
if(choice=='0')
exit(0);
else
if(choice=='1')
{a.newsubject();
system("pause");
main();
}
elseif(choice=='2')
{a.del();
system("pause");
main();}
elseif(choice=='3')
{a.modify();
system("pause");
main();}
elseif(choice=='4')
{b.Newstudent();
system("pause");
main();}
else
if(choice=='5')
{b.Del();
system("pause");
main();}
elseif(choice=='6')
{b.Modify();
system("pause");
main();}
elseif(choice=='7')
{a.demand();
system("pause");
main();}
elseif(choice=='8')
{a.Chosesubject();
system("pause");
main();}
else
cout<<"输入错误,请重新输入您的选择:
";
system("pause");
main();
}
文章来自:
本站原创