课程设计选题管理系统代码改改吧亲
#include <iostream>#include <string>
#include <iomanip>
using namespace std;
class Student
{
long num;
char name[20];
char subject[30];
Student *Next;
Student *Head;
public:
int Creat()
{
FILE *fp;
Head = NULL; //存放链表的起始地址
Student *p, *pEnd;
p = new Student; //创建一个动态对象
if((fp=fopen("Student.txt","r"))==NULL)
{
cout << "can not open file!" << endl;
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 = new Student; //动态创建下一个对象
fscanf(fp,"%ld%s%s",&p->num,p->name,p->subject); //输入下一个对象数据成员的值
}
pEnd->Next = NULL;
return 0;
}
int Newstudent()//************************增加学生信息
{
FILE *fp;
cout << "请输入增加的学生的相关信息: " << endl;
cout << "学号: " ;
cin >> num ;
cout << endl;
cout << "姓名: " ;
cin >> name;
cout << endl;
cout << "已选课程设计题目: " ;
cin >> subject;
cout << endl;
if((fp=fopen("student.txt","a"))==NULL)
{
cout << "can not open file!" << endl;
exit(0);
}
fprintf(fp,"%ld %s %s\n",num,name,subject);
fclose (fp);
return 0;
}
int Modify()//*****************************修改学生资料
{
FILE *fp;
Student *p;
char namer[20];
Creat();
cout << "请输入要修改的姓名:";
cin >> namer;
cout << endl;
if(Head!=NULL)
{
p=Head;
while(strcmp(namer,p->name))
{
p=p->Next;
if(p==NULL)
break;
}
if(p!=NULL)
{
cout << "你要修改的学生的相关信息如下:" << endl << endl;
cout << p->num << ' ' << p->name << ' ' << p->subject << endl << endl;
cout << "请输入修改后的相关信息:" << endl << endl;
cout << "请输入修改后的学生的学号: ";
cin >> p->num;
cout << endl;
cout << "请输入修改后的姓名: ";
cin >> p->name;
cout << endl;
cout << "请输入修改后的所选题目: ";
cin >> p->subject;
cout << endl;
if((fp=fopen("Student.txt","w"))==NULL)
{
cout << "can not open file!" << endl;
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 << "没有找到你想要修改的题目的信息" <<endl;
}
else
cout << "文件中还没有任何题目"<<endl;
return 0;
}
int Del()//****************************************删除学生信息
{
FILE *fp;
Student *p,*p1;
char namer[30];
Creat();
cout << "请输入要删除的学生的姓名:";
cin >> namer;
cout << endl;
if(Head!=NULL)
{
p=Head;
while(strcmp(namer,p->name))
{
p1=p;
p=p->Next;
if(p==NULL)
break;
}
if(p!=NULL)
{
cout << "你要删除的题目的相关信息如下:" << endl;
cout << " 姓名 : " << p->name<< endl;
cout << " 学号 : " << p->num << endl;
cout << "所选题目: " << p->subject << endl;
system("pause");
if(p==Head)Head=p->Next;
else
p1->Next=p->Next;
if((fp=fopen("Student.txt","w"))==NULL)
{
cout << "can not open file!" << endl;
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 << "该学生的所有信息已被删除!" << endl;
}
else
cout << "没有找到你想要删除的学生的信息" <<endl;
}
else
cout << "文件中还没有任何学生的信息"<<endl;
return 0;
}
};
class Subject//***************************************************************************************
{
int serial_number;//序号
char subject[30]; //题目
int peoples;//限定人数
int people;//已选人数
char description[100];//所选课程的描述
Subject *next;
Subject *head;
public:
int Chosesubject();
int creat();
int newsubject();
int modify();
int del();
int demand();
};
int Subject::creat()
{
FILE *fp;
head = NULL; //存放链表的起始地址
Subject *p, *pEnd;
p = new Subject; //创建一个动态对象
if((fp=fopen("Subject.txt","r"))==NULL)
{
cout << "can not open file!" << endl;
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 = new Subject; //动态创建下一个对象
fscanf(fp,"%d%s%d%s%d",&p->serial_number,p->subject,&p->peoples,p->description,&p->people); //输入下一个对象数据成员的值
}
pEnd->next = NULL;
return 0;
}
int Subject::newsubject()//************************************增加新的题目
{
FILE *fp;
cout << "请输入要增加的题目的序号:";
cin >> serial_number;
cout << endl;
cout << "请输入要增加的题目:";
cin >> subject;
cout << endl;
cout << "请输入要增加的题目的人数限定:";
cin >> peoples;
cout << endl;
cout << "请输入要增加的题目的描述::";
cin >> description;
cout << endl;
cout << "请输入要增加的题目的已选人数:";
cin >> people;
cout << endl;
if((fp=fopen("Subject.txt","a"))==NULL)
{
cout << "can not open file!" << endl;
exit(0);
}
fprintf(fp,"%d %s %d %s %d\n",serial_number,subject,peoples,description,people);
return 0;
}
int Subject::modify()//*****************************修改
{
FILE *fp;
Subject *p;
char sub[30];
creat();
cout << "请输入要修改的题目:";
cin >> sub;
cout << endl;
if(head!=NULL)
{
p=head;
while(strcmp(sub,p->subject))
{
p=p->next;
if(p==NULL)
break;
}
if(p!=NULL)
{
cout << "你要修改的题目的相关信息如下:" << endl;
cout << p->serial_number << ' ' << p->subject << ' ' << p->people << ' ' << p->description << endl;
cout << "请输入修改后的相关信息:" << endl;
cout << "请输入修改后的题目的序号:";
cin >> p->serial_number;
cout << endl;
cout << "请输入修改后的题目:";
cin >> p->subject;
cout << endl;
cout << "请输入修改后的题目的人数限定:";
cin >> p->peoples;
cout << endl;
cout << "请输入修改后的题目的描述::";
cin >> p->description;
cout << endl;
cout << "请输入修改后的题目的已选人数:";
cin >> p->people;
cout << endl;
if((fp=fopen("Subject.txt","w"))==NULL)
{
cout << "can not open file!" << endl;
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 << "没有找到你想要修改的题目的信息" <<endl;
}
else
cout << "文件中还没有任何题目"<<endl;
return 0;
}
int Subject::del()//****************************************删除
{
FILE *fp;
Subject *p,*p1;
char sub[30];
creat();
cout << "请输入要删除的题目:";
cin >> sub;
cout << endl;
if(head!=NULL)
{
p=head;
while(strcmp(sub,p->subject))
{
p1=p;
p=p->next;
if(p==NULL)
break;
}
if(p!=NULL)
{
cout << "你要删除的题目的相关信息如下:" << endl;
cout << " 序号 : " << p->serial_number << endl;
cout << " 题目 : " << p->subject << endl;
cout << "限定人数: " << p->peoples << endl;
cout << "题目描述: " << p->description << endl;
cout << "已选人数: " << p->people << endl;
system("pause");
if(p==head)head=p->next;
else
p1->next=p->next;
if((fp=fopen("Subject.txt","w"))==NULL)
{
cout << "can not open file!" << endl;
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 << "该题目的所有信息已被删除!" << endl;
}
else
cout << "没有找到你想要删除的题目的信息" <<endl;
}
else
cout << "文件中还没有任何题目"<<endl;
return 0;
}
int Subject::demand()//***************************************查询课程设计题目
{
Subject *p,*p1;
char sub[30];
creat();
cout << "所有题目列表如下" << endl;
p=head;
while(p != NULL)
{
cout << "序号: " << p->serial_number << " 题目 : " << p->subject << endl;
cout << endl;
p = p->next;
}
cout << " 请输入你想要查看的题目: " ;
cin >> sub;
cout << endl;
if(head!=NULL)
{
p=head;
while(strcmp(sub,p->subject))
{
p1=p;
p=p->next;
if(p==NULL)
break;
}
if(p!=NULL)
cout << "关于该题目有如下描述:"<< endl << p->description << endl;
else
cout << "没有找到你想要修改的题目的信息" <<endl;
}
else
cout << "文件中还没有任何题目"<<endl;
return 0;
}
int Subject::Chosesubject()
{
FILE *fp;
Subject *p,*p1;
char sub[30];
creat();
cout << "请输入你要选择的题目: ";
cin >> sub;
cout << endl;
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 << "人数超限!你不能再选择此题目!" << endl;
exit(0);
}
Student a;
a.Newstudent();
p->people++;
if((fp=fopen("Subject.txt","w"))==NULL)
{
cout << "can not open file!" << endl;
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 << "****选题成功!***" << endl;
fclose (fp);
}
else
cout << "没有找到你想要修改的题目的信息" <<endl;
}
else
cout << "文件中还没有任何题目"<<endl;
return 0;
}
int main()
{
system("color 1d");
Subject a;
Student b;
char choice;
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<<"请输入您的选择:";
cin>>choice;
if(choice=='0')
exit(0);
else
if(choice=='1')
{ a.newsubject();
system("pause");
main();
}
else if(choice=='2')
{a.del();
system("pause");
main();}
else if(choice=='3')
{a.modify();
system("pause");
main();}
else if(choice=='4')
{b.Newstudent();
system("pause");
main();}
else
if(choice=='5')
{b.Del();
system("pause");
main();}
else if(choice=='6')
{b.Modify();
system("pause");
main();}
else if(choice=='7')
{a.demand();
system("pause");
main();}
else if(choice=='8')
{a.Chosesubject();
system("pause");
main();}
else
cout<<"输入错误,请重新输入您的选择:";
system("pause");
main();
}