C++选课管理系统课程设计Word文档格式.docx
《C++选课管理系统课程设计Word文档格式.docx》由会员分享,可在线阅读,更多相关《C++选课管理系统课程设计Word文档格式.docx(31页珍藏版)》请在冰点文库上搜索。
![C++选课管理系统课程设计Word文档格式.docx](https://file1.bingdoc.com/fileroot1/2023-5/11/0be58962-bc9f-4dd4-b262-e7792ceafb3b/0be58962-bc9f-4dd4-b262-e7792ceafb3b1.gif)
//密码检查功能函数
/////////////////////////////////////////////
//定义课程信息类
structcourse
{charcnum[10];
charcname[20];
charcteacher[20];
floatcredit;
};
structCourse
{coursekecheng;
Course*next;
classsubject
{Course*head;
Course*p;
public:
//头指针
//当前指针
subject(){head=p=NULL;
};
voidAdd();
voidDelete();
//删除课程
intSearch(charnu[]);
voidReadFile();
//根据课程号查找课程
//从文件中读取课程信息
voidWriteFile();
//向文件写入课程信息
voidDisplay();
//在屏幕中输出全部课程信息
friendXS;
friendJS;
friendvoidxuanke(XSP,charnu[],charna[]);
voidsubject:
:
Add()
{p=newCourse;
cout<
<
"
\t请输入课程号:
;
cin>
>
p->
um;
if(Search(p->
um)==0)
{cout<
\t请输入课程名:
ame;
\t请输入任课教师:
kecheng.cteacher;
\t请输入课程学分:
kecheng.credit;
next=head;
head=p;
增加课程操作成功!
"
endl;
//头插入建链表
}
else
\n\t已经存在该课程,不能重复添加!
Delete()//按课程号删除
{if(head!
=NULL){intn=0;
Course*kc=head;
Course*q1=head,*q2=head->
next;
charkh[10];
\t请输入您要删除的课程号:
cin>
kh;
while(kc!
=NULL)
{n++;
if(strcmp(kc->
um,kh)==0)break;
kc=kc->
next;
if(kc==NULL)cout<
不存在该课程号!
else
{if(n==1)head=head->
{for(inti=1;
i<
n-1;
i++){q1=q2;
q2=q2->
if(q2==NULL)
q1=NULL;
q1->
next=q2->
删除成功!
}}
intsubject:
Search(charnu[])
{Course*kc=head;
while(kc!
{if(strcmp(kc->
um,nu)==0)break;
if(kc==NULL)return0;
elsereturn1;
Display()//在屏幕中输出全部课程信息
{if(head==NULL)
没有课程信息!
\n\n"
else{Course*k=head;
setiosflags(ios:
left)<
setw(10)<
课
程
号
setw(15)<
课程名
分"
<
while(k)
任课教师
setw(5)<
学
k->
um<
k->
ame
setw(16)<
kecheng.cteacher<
kecheng.credit<
k=k->
ReadFile()//从文件读取课程信息
{p=newCourse;
ifstreamfip("
课程信息.dat"
ios:
in|ios:
binary);
if(!
fip)cout<
文件打开失败!
while(fip.read((char*)&
kecheng,sizeof(p->
kecheng)))
{p->
head=p;
p=newCourse;
fip.close();
deletep;
WriteFile()
{Course*s=head;
ofstreamfop;
fop.open("
binary|ios:
trunc);
fop)
{cout<
课程信息.dat无法打开!
abort();
while(s)
{while(fop.write((char*)&
s->
kecheng,sizeof(s->
{s=s->
fop.close();
///////////////定义教师信息类
structteacher
{chartnum[10];
chartname[20];
charzhicheng[20];
structTeacher
{teacherjiaoshi;
Teacher*next;
classJS
{
Teacher*head;
//头指针
Teacher*p;
//当前指针
JS(){head=p=NULL;
voidSearch(charna[]);
intSearch1(charnu[]);
//通过教师姓名查找任课教师
//通过教师号查找教师
//从文件中读取教师信息
//向文件写入教师信息
//在屏幕中输出全部教师信息
voidJS:
{p=newTeacher;
\t请输入教师证号:
jiaoshi.tnum;
if(Search1(p->
jiaoshi.tnum)==0)
\t请输入教师姓名:
jiaoshi.tname;
\t请输入教师职称:
jiaoshi.zhicheng;
增加教师操作成功!
\n\t
该教师已经存在,不能重复添加!
Delete()
{intn=0;
Teacher*js=head;
Teacher*q1=head,*q2=head->
charzh[10];
\t请输入您要删除的教师证号:
zh;
while(js!
if(strcmp(js->
jiaoshi.tnum,zh)==0)break;
js=js->
if(js==NULL)cout<
不存在该教师!
i++)
{q1=q2;
删除教师成功!
Search(charna[])
{Teacher*js=head;
while(js!
{if(strcmp(na,js->
jiaoshi.tname)==0)break;
js=js->
if(js!
教师证号"
setw(16)
教师姓名"
教师职称"
js->
jiaoshi.tnum<
left)
jiaoshi.tname<
jiaoshi.zhicheng<
没有该教师信息!
Display()
没有教师信息!
\n\n"
else{Teacher*k=head;
教师证号
jiaoshi.tnum
}
intJS:
Search1(charnu[])
{if(strcmp(nu,js->
jiaoshi.tnum)==0)break;
if(js==NULL)return0;
{Teacher*s=head;
charxs[]="
教师信息.dat"
fop.open(xs,ios:
教师信息.dat无法打开!
jiaoshi,sizeof(s->
jiaoshi)))
{s=s->
ReadFile()
{p=newTeacher;
//以二进制形式打开文件if(!
jiaoshi,sizeof(p->
jiaoshi)))
p=newTeacher;
////////////////定义学生信息类
structstudent
{charsnum[10];
charsname[20];
structStudent
{studentxuesheng;
Student*next;
classstu
Student*head;
Student*p;
//当前指针
stu(){head=p=NULL;
intSearch(charnu[],charna[]);
//
//增加学生
//删除学生
按学生学号和姓名查找
//按学生学号查找
//将所有学生的信息写入文件保存
//从文件读出学生信息
//显示所有学生
voidstu:
{p=newStudent;
\t请输入学号:
xuesheng.snum;
xuesheng.snum)==0)
\t请输入姓名:
xuesheng.sname;
增加学生操作成功!
//头插入建链表
\n\t该学生已经存在,不能重复添加!
Delete()//按学号删除
{if(head!
Student*q1=head,*q2=head->
charkh[10];
\t请输入您要删除的学生学号:
if(strcmp(kc->
xuesheng.snum,kh)==0)break;
kc=kc->
不存在该学生!
intstu:
Search(charnu[],charna[])
{Student*kc=head;
xuesheng.snum,nu)==0&
&
strcmp(kc->
xuesheng.sname,na)==0)break;
{if(strcmp(kc->
xuesheng.snum,nu)==0)break;
{Student*s=head;
学生信息.dat"
学生信息.dat无法打开!
xuesheng,sizeof(s->
xuesheng)))
s=s->
{p=newStudent;
xuesheng,sizeof(p->
p=newStudent;
{if(head==NULL)cout<
没有学生信息!
else{Student*k=head;
学生学号"
setw(20)<
学生
姓名"
xuesheng.snum<
xuesheng.sname<
/////////////////////////学生类
classXS
{charnum[10];
charname[20];
Course*head;
//已选课程
floattcredit;
XS(){head=p=NULL;
tcredit=0;
voidset(charnu[],charna[])
{strcpy(num,nu);
strcpy(name,na);
voidAddcourse(charnu[]);
//学生选课
//按课程号查找以选课程
voidDeletecourse(charnu[]);
//退选
voidShowcourse();
//显示已选课程
floatget_tcredit();
//获取已选课程总学分
voidReadFilecourse();
//读取已选课程
voidWriteFilecourse();
//将已选课程写入文件
friendvoidtuixuan(XSP,charnu[],charna[]);
voidXS:
Addcourse(charnu[])
{subjectsub;
sub.ReadFile();
p=newCourse;
if(sub.Search(nu)==1)
{if(Search(nu)==0)
{sub.p=sub.head;
while(sub.p!
{if(strcmp(sub.p->
sub.p=sub.p->
strcpy(p->
um,sub.p->
um);
ame,sub.p->
ame);
kecheng.cteacher,sub.p->
kecheng.cteacher);
kecheng.credit=sub.p->
kecheng.credit;
next=head;
选课成功!
elsecout<
此课