#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cstdlib>
#include <windows.h>
const int INC=20;
using namespace std;
class Course{
//课程编号、课程名称、学分、总学时、理论学时、实验学时、开课学期、起止周、课容量、选课人数(初始为0)
private:
string num;
string title;
float credit;
int period;
int theory_period;
int experiment_period;
string term;
string week;
int course_people;
int people;
public:
Course(string num0="BF002345",string title0="Web3D技术",float credit0=3,
int period0=54,int theory_period0=28,int experiment_period0=26,string term0="2016-2017-1",string week0="1-14",int course_people0=9,int people0=0)
{ num=num0;title=title0;credit=credit0;period=period0;theory_period=theory_period0;experiment_period=experiment_period0;term=term0;week=week0;course_people=course_people0;people=people0;}
void setNum(string num0){num=num0;}
void setTitle(string title0){title=title0;}
void setCredit(float credit0){credit=credit0;}
void setPeriod(int period0){period=period0;}
void setTheory_period(int theory_period0){theory_period=theory_period0;}
void setExperiment_period(int experiment_period0){experiment_period=experiment_period0;}
void setTerm(string term0){term=term0;}
void setWeek(string week0){week=week0;}
void setCourse_people(int course_people0){course_people=course_people0;}
void setPeople(int people0){people=people0;}
string getNum(){return num;}
string getTitle(){return title;}
float getCredit(){return credit;}
int getPeriod(){return period;}
int getTheory_period(){return theory_period;}
int getExperiment_period(){return experiment_period;}
string getTerm(){return term;}
string getWeek(){return week;}
int getCourse_people(){return course_people;}
int getPeople(){return people;}
void dispACourse(){
cout <<num<< '\t'<<title<< '\t'<<credit<< '\t'<<period<< '\t'<<theory_period<< '\t'<<experiment_period<< '\t'<<term<< '\t'<<week<< '\t'<<course_people<< '\t'<<people<<'\n';
}
friend class InCourse;
friend class StudentSelectCourse;
};
class Student{
//学号、姓名、学院、专业班级
private:
string num;
string name;
string college;
string classno;
public:
Student(string num0="20136954",string name0="汤武",string college0="资源与环境学院",string classno0="地信13-1"){
num=num0;name=name0;college=college0; classno=classno0;}
void setNum(string num0){num=num0;}
void setName(string name0){name=name0;}
void setCollege(string college0){college=college0;}
void setClassno(string classno0){classno=classno0;}
string getNum(){return num;}
string getName(){return name;}
string getCollege(){return college;}
string getClassno(){return classno;}
void dispAStudent(){
cout <<num<< '\t'<<name<< '\t'<<college<< '\t'<<classno<< '\n';
}
friend class Instudent;
friend class StudentSelectCourse;
};
class SelectCourse{
//学号、姓名、学院、课程编号、课程名称、开课学期、退选标志(0-已选,1-推选)
private:
string num;
string name;
string coursenum;
string coursetitle;
string term;
int choice;
public:
SelectCourse(string num0="20132947",string name0="李桂花",string coursenum0="BF002345",
string coursetitle0="Web3D技术",string term0="2016-2017-1",int choice0=0)
{
num=num0;name=name0;coursenum=coursenum0;coursetitle=coursetitle0;term=term0;choice=choice0;
}
void setNum(string num0){num=num0;}
void setName(string name0){name=name0;}
void setCourseNum(string coursenum0){coursenum=coursenum0;}
void setCourseTitle(string coursetitle0){coursetitle=coursetitle0;}
void setTerm(string term0){term=term0;}
void setChoice(int choice0){choice=choice0;}
string getNum(){return num;}
string getName(){return name;}
string getCourseNum(){return coursenum;}
string getCourseTitle(){return coursetitle;}
string getTerm(){return term;}
int getChoice(){return choice;}
void dispSelectCourse(){
cout <<num<< '\t'<<name<< '\t'<< '\t'<<coursenum<< '\t'<<coursetitle<< '\t'<<term<<'\t'<<choice<<'\n';
}
friend class InSelectCourse;
friend class StudentSelectCourse;
};
class InCourse{
public:
Course *course;int coursecount;
void write2Coursefile(){
string num;
string title;
float credit;
int period;
int theory_period;
int experiment_period;
string term;
string week;
int course_people;
int people;
ofstream outf( "course.txt", ios::out ) ;
//写入的文件名应该与读出的文件名相同;调试时可以取不同的文件名,以免覆盖掉原文件
if ( !outf )
{ cerr << "File could not be open." << endl ; }
outf<<"课程信息\n";
for(int i=0;i<coursecount;i++)
{
outf<<course[i].getNum()<< '\t'<<course[i].getTitle()<< '\t';
outf<<course[i].getCredit()<< '\t'<<course[i].getPeriod()<< '\t';
outf<<course[i].getTheory_period()<<'\t'<<course[i].getExperiment_period()<<'\t';
outf<<course[i].getTerm()<< '\t'<<course[i].getWeek()<< '\t' ;
outf<<course[i].getCourse_people()<< '\t'<<course[i].getPeople()<< '\n' ;
}
outf.close() ;
}
int incourseFile( char * fileName, int delLine)
{
int i;
string num;
string title;
float credit;
int period;
int theory_period;
int experiment_period;
string term;
string week;
int course_people;
int people;
ifstream inf( fileName, ios::in ) ;
if ( !inf )
{ cerr << "File could not be open." << endl ; return 1; }
char s[80];
int a;
float b;
for ( i=1; i <= delLine; i++ )
inf.getline( s,80 ) ;
i=0;
while( inf>>num>>title>>credit>>period>>theory_period>>experiment_period>>term>>week>>course_people>>people ) //{ inf.getline( s, 80 ) ; cout << s << endl ; }
{
//inf,getchar();
if(title.length()>0) i++;
}
coursecount=i;
//cout<<coursecount<<endl;
inf.clear();
inf.seekg(0,ios::beg);
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
course=new Course[coursecount+INC];
for ( i=0; i <coursecount; i++ )
{
inf>>num>>title>>credit>>period>>theory_period>>experiment_period>>term>>week>>course_people>>people;
if(title.length()>0){
if(num[0]==10) num=num.substr(1);
course[i]=Course();
course[i].setNum(num);
course[i].setTitle(title);
course[i].setCredit(credit);
course[i].setPeriod(period);
course[i].setTheory_period(theory_period);
course[i].setExperiment_period(experiment_period);
course[i].setTerm(term);
course[i].setWeek(week);
course[i].setCourse_people(course_people);
course[i].setPeople(people);
}
}
inf.close() ;
return coursecount;
}
friend class StudentSelectCourse;
int addcourse(string num,string title,float credit,int period,int theory_period,int experiment_period,string term,string week,int course_people,int people){
int i=coursecount;
course[i]=Course();
course[i].setNum(num);
course[i].setTitle(title);
course[i].setCredit(credit);
course[i].setPeriod(period);
course[i].setTheory_period(theory_period);
course[i].setExperiment_period(experiment_period);
course[i].setTerm(term);
course[i].setWeek(week);
course[i].setCourse_people(course_people);
course[i].setPeople(people);
++coursecount;
return coursecount;
}
void searchcoursebynum(string num){//模糊查找包含num的串
bool found=false;
for(int i=0;i<coursecount;i++)
if((course[i].getNum()).find(num)!= string::npos) {
//cout<<course[i].getNum()<< course[i].getNum().find(num)<<endl;
cout<<i<<"\t";
course[i].dispACourse();
found=true;
// return i;
}
if(!found)cout<<"course num:"<<num<<" not found."<<endl;
// return -1;
}
int searchcoursebynump(string num){//精确查找等于num的串
for(int i=0;i<coursecount;i++)
if((course[i].getNum())==num) {
//cout<<course[i].getNum()<< course[i].getNum().find(num)<<endl;
cout<<i<<"\t";
course[i].dispACourse();
return i;
}
return -1;
}
void searchcoursebytitle(string title){
bool found=false;
for(int i=0;i<coursecount;i++)
if((course[i].getTitle()).find(title)!= string::npos) {
//cout<<course[i].getTitle()<< course[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
course[i].dispACourse();
found=true;
//return i;
}
if(!found)cout<<"course title:"<<title<<" not found."<<endl;
//return -1;
}
int searchcoursebytitlep(string title){
for(int i=0;i<coursecount;i++)
if(course[i].getTitle()==title) {
//cout<<course[i].getTitle()<< course[i].getTitle().find(title)<<endl;
cout<<i<<"\t";
course[i].dispACourse();
return i;
}
cout<<"course title:"<<title<<" not found."<<endl;
return -1;
}
void sortcoursebynum(){
for(int i=0;i<coursecount;i++){
int k=i;
for(int j=i+1;j<coursecount;j++)
if(course[j].getNum()<course[k].getNum()) k=j;
//cout<<k<<" k&i "<<i<<" :"<<course[i].getNum()<<"---"<<course[k].getNum()<<endl;
if(k!=i){
Course t=course[i];course[i]=course[k];course[k]=t;
}
}
}
void sortcoursebytitle(){
for(int i=0;i<coursecount;i++){
int k=i;
for(int j=i+1;j<coursecount;j++)
if(course[j].getTitle()<course[k].getTitle()) k=j;
if(k!=i){
Course t=course[i];course[i]=course[k];course[k]=t;
}
}
}
void changecoursebynum(string oldnum,string newnum){
int k=searchcoursebynump(oldnum);
if(k>=0) {
course[k].setNum(newnum);
cout<<"changecoursebynum successed:"<<endl;
course[k].dispACourse();
}
else cout<<"changecourse failed. No course of num="<<oldnum<<endl;
}
void deletecoursebynum(string num){
int k=searchcoursebynump(num);
if(k>=0) {
cout<<"Course to be deleted :"<<endl;
course[k].dispACourse();
course[k]=course[coursecount-1];
cout<<"deletecoursebynum successed:"<<endl;
coursecount--;
//return coursecount;
}
else cout<<"deletecourse failed. No course of num="<<num<<endl;
}
void changecoursebytitle(string oldtitle,string newtitle){
int k=searchcoursebytitlep(oldtitle);
if(k>=0) {
course[k].setTitle(newtitle);
cout<<"changecoursebytitle successed:"<<endl;
course[k].dispACourse();
}
else cout<<"changecourse failed. No course of title="<<oldtitle<<endl;
}
void deletecoursebytitle(string title){
int k=searchcoursebytitlep(title);
if(k>=0) {
cout<<"Course to be deleted :"<<endl;
course[k].dispACourse();
course[k]=course[coursecount-1];
cout<<"deletecoursebytitle successed:"<<endl;
coursecount--;
//return bookcount;
}
else cout<<"deletecourse failed. No course of title="<<title<<endl;
}
};
class InStudent{
public:
Student *student;int studentcount;
string a[100];
void write2Studentfile(){
}
int instudentFile( char * fileName, int delLine)
{
string num,name,college,classno;
int i;
ifstream inf( fileName, ios::in ) ;
if ( !inf )
{ cerr << "File could not be open." << endl ; return 1; }
char s[80];
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
i=0;
while( !inf.eof() ) //{ inf.getline( s, 80 ) ; cout << s << endl ; }
{
inf.getline( s, 80,'\t' ) ;//num=s;
inf.getline( s, 80,'\t' ) ;name=s;
inf.getline( s, 80,'\t' ) ;//college=s;
inf.getline( s, 80 ) ;//classno=s;
if(name.length()>0) i++;
}
studentcount=i;
//cout<<studentcount<<endl;
inf.clear();
inf.seekg(0,ios::beg);
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
student=new Student[studentcount+INC];
for ( i=0; i <studentcount; i++ )
{
inf.getline( s, 80,'\t' ) ;num=s;
inf.getline( s, 80,'\t' ) ;name=s;
inf.getline( s, 80,'\t' ) ;college=s;
inf.getline( s, 80 ) ;classno=s;
if(name.length()>0){
if(num[0]==10)num=num.substr(1);
student[i]=Student();
student[i].setNum(num);
student[i].setName(name);
student[i].setCollege(college);
student[i].setClassno(classno);
}
}
inf.close() ;
return studentcount;
}
int addstudent(string num,string name,string college,string classno){
int i=studentcount;
student[i]=Student();
student[i].setNum(num);
student[i].setName(name);
student[i].setCollege(college);
student[i].setClassno(classno);
++studentcount;
return studentcount;
}
//通过学号查询学生信息
void searchstudentbynum(string num){
bool found=false;
for(int i=0;i<studentcount;i++)
if((student[i].getNum()).find(num)!= string::npos) {
cout<<i<<"\t";
student[i].dispAStudent();
found=true;
//return i;
}
if(!found)cout<<"student of num: "<<num<<" not found"<<endl;
//return -1;
}
int searchstudentbynump(string num){
for(int i=0;i<studentcount;i++)
if(student[i].getNum()==num) {
cout<<i<<"\t";
student[i].dispAStudent();
return i;
}
return -1;
}
//通过姓名查询学生信息
void searchstudentbyname(string name){
bool found=false;
for(int i=0;i<studentcount;i++)
if((student[i].getName()).find(name)!= string::npos) {
//cout<<student[i].getName()<< student[i].getName().find(name)<<endl;
cout<<i<<"\t";
student[i].dispAStudent();
found=true;
//return i;
}
if(!found)cout<<"student name:"<<name<<" not found."<<endl;
//return -1;
}
int searchstudentbynamep(string name){
for(int i=0;i<studentcount;i++)
if(student[i].getName()==name) {
//cout<<student[i].getName()<< student[i].getName().find(Name)<<endl;
cout<<i<<"\t";
student[i].dispAStudent();
return i;
}
cout<<"student name:"<<name<<" not found."<<endl;
return -1;
}
//通过专业班级查询学生信息
void searchstudentbyclassno(string classno){
bool found=false;
for(int i=0;i<studentcount;i++)
if((student[i].getClassno()).find(classno)!= string::npos) {
cout<<i<<"\t";
student[i].dispAStudent();
found=true;
//return i;
}
if(!found)cout<<"student of classno: "<<classno<<" not found"<<endl;
//return -1;
}
int searchstudentbyclassnop(string classno){
for(int i=0;i<studentcount;i++)
if(student[i].getClassno()==classno) {
cout<<i<<"\t";
student[i].dispAStudent();
return i;
}
return -1;
}
//通过学号升序排序学生信息
void sortstudentbynum(){
for(int i=0;i<studentcount;i++){
int k=i;
for(int j=i+1;j<studentcount;j++)
if(student[j].getNum()<student[k].getNum()) k=j;
//cout<<k<<" k&i "<<i<<" :"<<student[i].getNum()<<"---"<<student[k].getNum()<<endl;
if(k!=i){
Student t=student[i];student[i]=student[k];student[k]=t;
}
}
}
//通过学院升序排序学生信息
void sortstudentbycollege(){
for(int i=0;i<studentcount;i++){
int k=i;
for(int j=i+1;j<studentcount;j++)
if(student[j].getCollege()<student[k].getCollege()) k=j;
if(k!=i){
Student t=student[i];student[i]=student[k];student[k]=t;
}
}
}
//通过学号+姓名修改学生信息
void changestudentbynumname(string oldnum,string oldname,string newnum,string newname){
int k=searchstudentbynump(oldnum);
int j=searchstudentbynamep(oldname);
if(k>=0&&j>=0) {
student[k].setNum(newnum);
student[j].setName(newname);
cout<<"changestudentbynum+name successed:"<<endl;
student[k].dispAStudent();
}
else cout<<"changestudent failed. No reader of num+name="<<oldnum<<" "<<oldname<<endl;
}
//通过学号+姓名删除学生信息
void deletestudentbynumname(string num,string name){
int k=searchstudentbynump(num);
int j=searchstudentbynamep(name);
if(k>=0&&j>=0) {
cout<<"Student to be deleted :"<<endl;
student[j].dispAStudent();
student[j]=student[studentcount-1];
cout<<"deletestudentbynumname successed:"<<endl;
studentcount--;
//return studentcount;
}
}
friend class StudentSelectCourse;
};
class InSelectCourse{
public:
SelectCourse *selectcourse;int selectcoursecount;
void write2SelectCoursefile(){
}
int inselectcourseFile( char * fileName, int delLine)
{
string num,name,coursenum,coursetitle,term;
int choice;
int i;
ifstream inf( fileName, ios::in ) ;
if ( !inf )
{ cerr << "File could not be open." << endl ; return 1; }
char s[80];
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
i=0;
while( !inf.eof() )
{
inf.getline( s, 80,'\t') ;
inf.getline( s, 80,'\t' ) ;
inf.getline( s, 80,'\t' ) ;
inf.getline( s, 80,'\t' ) ;
inf.getline( s, 80 ) ;
inf>>choice;
if(strlen(s)>1) i++;
}
selectcoursecount=i;
//cout<<selectcoursecount<<endl;
inf.clear();
inf.seekg(0,ios::beg);
for ( i=1; i <= delLine; i++ )
inf.getline( s, 80 ) ;
selectcourse=new SelectCourse[selectcoursecount+INC];
for ( i=0; i <selectcoursecount; i++ )
{
inf.getline( s, 80,'\t' ) ;num=s;
inf.getline( s, 80,'\t' ) ;name=s;
inf.getline( s, 80,'\t' ) ;coursenum=s;
inf.getline( s, 80,'\t' ) ;coursetitle=s;
inf.getline( s, 80,'\t' ) ;term=s;
inf>>choice;
if(name.length()>0){
if(num[0]==10)num=num.substr(1);
selectcourse[i]=SelectCourse();
selectcourse[i].setNum(num);
selectcourse[i].setName(name);
selectcourse[i].setCourseNum(coursenum);
selectcourse[i].setCourseTitle(coursetitle);
selectcourse[i].setTerm(term);
selectcourse[i].setChoice(choice);
}
}
inf.close() ;
return selectcoursecount;
}
void searchbynum(string num){
bool found=false;
for(int i=0;i<selectcoursecount;i++)
if((selectcourse[i].getNum()).find(num)!= string::npos) {
//cout<<selectcourse[i].getNum()<< selectcourse[i].getNum().find(num)<<endl;
cout<<i<<"\t";
selectcourse[i].dispSelectCourse();
found=true;
//return i;
}
if(!found)cout<<"selectcourse num:"<<num<<" not found."<<endl;
//return -1;
}
int searchbynump(string num){
for(int i=0;i<selectcoursecount;i++)
if(selectcourse[i].getNum()==num) {
//cout<<selectcourse[i].getNum()<< selectcourse[i].getNum().find(num)<<endl;
cout<<i<<"\t";
selectcourse[i].dispSelectCourse();
return i;
}
cout<<"selectcourse num:"<<num<<" not found."<<endl;
return -1;
}
void searchbycoursenum(string coursenum){
bool found=false;
for(int i=0;i<selectcoursecount;i++)
if((selectcourse[i].getCourseNum()).find(coursenum)!= string::npos) {
//cout<<selectcourse[i].getCourseNum()<< selectcourse[i].getCourseNum().find(coursenum)<<endl;
cout<<i<<"\t";
selectcourse[i].dispSelectCourse();
found=true;
//return i;
}
if(!found)cout<<"selectcourse coursenum:"<<coursenum<<" not found."<<endl;
//return -1;
}
int searchbycoursenump(string coursenum){
for(int i=0;i<selectcoursecount;i++)
if(selectcourse[i].getCourseNum()==coursenum) {
//cout<<selectcourse[i].getCourseNum()<< selectcourse[i].getNum().find(coursenum)<<endl;
cout<<i<<"\t";
selectcourse[i].dispSelectCourse();
return i;
}
cout<<"selectcourse coursenum:"<<coursenum<<" not found."<<endl;
return -1;
}
void searchbyclassno(string classno){
int i,k;
InStudent b;
b.instudentFile("student.txt",1);
int j=0;
for(i=0;i<b.studentcount;i++){
if((b.student[i].getClassno()).find(classno)!= string::npos) {
b.a[j]=b.student[i].getNum();
j++;
}
}
if(j==0)
cout<<"该专业班级学生无选课记录"<<endl;
for(int k=0;k<j;k++)
searchbynum(b.a[k]);
}
};
class StudentSelectCourse{
InCourse cr;
InStudent st;
InSelectCourse sc;
public:
void write2file(){
cr.write2Coursefile();
st.write2Studentfile();
sc.write2SelectCoursefile();
}
void init(){
cr.incourseFile( "course.txt", 1);
st.instudentFile( "student.txt", 1);
sc.inselectcourseFile( "studcourse.txt", 1);
}
void dispCourse(){
for ( int i=0; i <cr.coursecount; i++ )
{cout<<i<<":";
cr.course[i].dispACourse();}
}
void dispStudent(){
for ( int i=0; i <st.studentcount; i++ )
{cout<<i<<":";
st.student[i].dispAStudent();}
}
void dispSelectCourse(){
for ( int i=0; i <sc.selectcoursecount; i++ )
{cout <<i<<":";
sc.selectcourse[i].dispSelectCourse();}
}
void dispCount(){
cout<<cr.coursecount<<endl;
cout<<st.studentcount<<endl;
cout<<sc.selectcoursecount<<endl;
}
void addcourse(){
string num,title,term,week;
float credit;
int period,theory_period,experiment_period,course_people,people;
char num0[80],tit[80],ter[80],wee[80];
cout<<"课程编号、课程名称、课程性质、总学时、理论学时、实验学时、开课学期、起止周、课容量、选课人数"<<endl;
string num1="BF002357",title0="大数据分析",term0="11-14",week0="清华大学出版社";
float credit0=2.5;
int period0=54;
int theory_period0=27;
int experiment_period0=27;
int course_people0=45;
int people0=25;
cr.addcourse(num1,title0,credit0,period0,theory_period0,experiment_period0,term0,week0,course_people0,people0);
int i=cr.coursecount-1;
cout <<i<<":";
cr.course[i].dispACourse();
}
void addstudent(){
string num,name,college,classno;
char num0[80],nam[80],coll[80],clas[80];
cout<<"学号、姓名、学院、专业班级:"<<endl;
string num1="20151000",name0="王涛",college0="computer",class0="network class 1";
st.addstudent(num1,name0,college0,class0);
int i=st.studentcount-1;
cout <<i<<":";
st.student[i].dispAStudent();
}
void searchcourse(){
cout<<"2.课程信息查询:分别按课程编号、课程名称等进行查询。"<<endl;
char tit[80];
string num="BF002345", title="Web3D技术";
int i,j,k,select;
while(1){
cout<<"课程信息查询:"<<endl;
cout<<"1.按课程编号查询"<<endl;
cout<<"2.按课程名称查询"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"课程编号:";
getline(cin,num,'\n');
cr.searchcoursebynum(num);
break;
case 2:
cout<<"课程名称:";
getline(cin,title,'\n');
cr.searchcoursebytitle(title);
break;
case 0:return;
}
}
}
void sortcourse(){
int select;
cout<<"3.课程信息排序:按课程编号、课程名称等按升序进行排序。"<<endl;
cout<<"课程信息排序:"<<endl;
cout<<"1.按课程编号排序"<<endl;
cout<<"2.按课程名称排序"<<endl;
cout<<"0. return"<<endl;
cin>>select;
switch(select){
case 1:
cout<<"课程编号:";
cr.sortcoursebynum();
dispCourse();
break;
case 2:
cout<<"课程名称:";
cr.sortcoursebytitle();
dispCourse();
break;
case 0:return;
}
}
void editcourse(){
string oldnum="BF002345",oldtitle="Web3D技术",newnum="BF002357",newtitle="Linux操作系统";
int select;
cout<<"4.课程信息的修改、删除:按课程编号、课程名称进行课程的修改和删除。"<<endl;
while(1){
cout<<"课程信息的修改、删除:"<<endl;
cout<<"1.按课程编号修改"<<endl;
cout<<"2.按课程编号删除"<<endl;
cout<<"3.按课程名称修改"<<endl;
cout<<"4.按课程名称删除"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"old课程编号:";
getline(cin,oldnum,'\n');
cout<<"new课程编号:";
getline(cin,newnum,'\n');
cout<<"changecoursebynum: "<<oldnum<<" to "<<newnum<<endl;
cr.changecoursebynum(oldnum,newnum);
//dispCourse();
break;
case 2:
cout<<"delete课程编号:";
getline(cin,oldnum,'\n');
cout<<"delete课程编号:"<<oldnum<<endl;
cr.deletecoursebynum(oldnum);
//dispcourse();
break;
case 3:
cout<<"old课程名称:";
getline(cin,oldtitle,'\n');
cout<<"new课程名称:";
getline(cin,newtitle,'\n');
cout<<"changecoursebytitle: "<<oldtitle<<" to "<<newtitle<<endl;
cr.changecoursebytitle(oldtitle,newtitle);
//dispCourse();
break;
case 4:
cout<<"delete课程名称:";
getline(cin,oldtitle,'\n');
cout<<"deletecoursebytitle: "<<oldtitle<<endl;
cr.deletecoursebytitle(oldtitle);
//dispCourse();
break;
case 0:return;
}
}
}
void searchstudent(){
cout<<"6.学生信息查询:分别按学号、姓名、专业班级等进行查询。"<<endl;
char tit[80];
string num="20136954",name="汤武",classno="地信13-1";
int i,j,k,select;
while(1){
cout<<"学生信息查询:"<<endl;
cout<<"1.按学号查询"<<endl;
cout<<"2.按姓名查询"<<endl;
cout<<"3.按专业班级查询"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"学号:";
getline(cin,num,'\n');
st.searchstudentbynum(num);
break;
case 2:
cout<<"姓名:";
getline(cin,name,'\n');
st.searchstudentbyname(name);
break;
case 3:
cout<<"专业班级:";
getline(cin,classno,'\n');
st.searchstudentbyclassno(classno);break;
case 0:return;
}
}
}
void sortstudent(){
int select;
cout<<"7.学生信息排序:按学号、学院等按升序进行排序。"<<endl;
cout<<"读者信息排序:"<<endl;
cout<<"1.按学号排序"<<endl;
cout<<"2.按学院排序"<<endl;
cout<<"0. return"<<endl;
cin>>select;
switch(select){
case 1:
cout<<"学号:";
st.sortstudentbynum();
dispStudent();
break;
case 2:
cout<<"学院:";
st.sortstudentbycollege();
dispStudent();
break;
case 0:return;
}
}
void editstudent(){
string oldnum="2015000000",newnum="20076954",oldname="Noname",newname="汤武";
int select;
cout<<"8.学生信息的修改、删除:按学号+姓名进行读者信息的修改和删除。"<<endl;
while(1){
cout<<"学生信息的修改、删除:"<<endl;
cout<<"1.按学号+姓名修改"<<endl;
cout<<"2.按学号+姓名删除"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"old学号+姓名:";
getline(cin,oldnum,'\n');
getline(cin,oldname,'\n');
cout<<"new学号+姓名:";
getline(cin,newnum,'\n');
getline(cin,newname,'\n');
cout<<"changestudentbynumname: "<<oldnum<<" "<<oldname<<" to "<<newnum<<" "<<newname<<endl;
st.changestudentbynumname(oldnum,oldname,newnum,newname);
//dispStudent();
break;
case 2:
cout<<"delete学号+姓名:";
getline(cin,oldnum,'\n');
getline(cin,oldname,'\n');
cout<<"delete学号+姓名:"<<oldnum<<" "<<oldname<<endl;
st.deletestudentbynumname(oldnum,oldname);
//dispStudent();
break;
case 0:return;
}
}
}
void studentselectacourse(){
cout<<"9.学生选课:输入学号+课程编号,如果该课程的课程信息表中的课容量大于选课人数,则可以选课。"<<endl;
string stnum="20132947",coursenum="BF002345",stname,coursetitle,term;
int choice;
int select,stpos,coursepos;
while(1){
cout<<"学生选课:"<<endl;
cout<<"1.选课"<<endl;
cout<<"0.return"<<endl;
cin>>select;
cin.get();
if(select==0)return;
cout<<"select学号:";
getline(cin,stnum,'\n');
cout<<"select课程编号:";
getline(cin,coursenum,'\n');
coursepos=cr.searchcoursebynump(coursenum);
stpos=st.searchstudentbynump(stnum);
if(coursepos>=0&&stpos>=0){
int hm=cr.course[coursepos].getCourse_people();
int hn=cr.course[coursepos].getPeople();
if(hm>hn){
stname=st.student[stpos].getName();
coursetitle=cr.course[coursepos].getTitle();
term=cr.course[coursepos].getTerm();
choice=0;
cr.course[coursepos].setPeople(hn+1); //修改课程信息表中的选课人数
sc.selectcourse[sc.selectcoursecount].setNum(stnum);
sc.selectcourse[sc.selectcoursecount].setName(stname);
sc.selectcourse[sc.selectcoursecount].setCourseNum(coursenum);
sc.selectcourse[sc.selectcoursecount].setCourseTitle(coursetitle);
sc.selectcourse[sc.selectcoursecount].setTerm(term);
sc.selectcourse[sc.selectcoursecount].setChoice(choice);
sc.selectcoursecount++;
sc.selectcourse[sc.selectcoursecount-1].dispSelectCourse();
cout<<"选课成功"<<endl;
}
else cout<<coursenum<<" 课程容量<=选课人数"<<". can't be selected. "<<endl;
}
else{
if(coursepos<0)cout<<"No course "<<coursenum<<". can't select!"<<endl;
if(stpos<0)cout<<"No student "<<stnum<<". can't select!"<<endl;
}
}
}
void studentdropacourse(){
cout<<"10.学生退课:输入学号+课程编号,修改课程信息表中的选课人数-1,在学生选课表中设置该学号同学对课程的退选"<<endl;
string stnum="20132947",coursenum="BF002345",stname,coursetitle,term;
int choice;
int select,stpos,coursepos,stcoursepos;
while(1){
cout<<"学生退课:"<<endl;
cout<<"1.退课"<<endl;
cout<<"0.return"<<endl;
cin>>select;
cin.get();
if(select==0)return;
cout<<"return学号:";
getline(cin,stnum,'\n');
cout<<"return课程编号:";
getline(cin,coursenum,'\n');
coursepos=cr.searchcoursebynump(coursenum);
stpos=st.searchstudentbynump(stnum);
stcoursepos=sc.searchbynump(stnum);
if(coursepos>=0&&stpos>=0&&stcoursepos>=0){
choice=1;
cr.course[coursepos].setPeople(cr.course[coursepos].getPeople()-1);
sc.selectcourse[stcoursepos].setChoice(choice);
sc.selectcourse[stcoursepos].dispSelectCourse();
cout<<"退课成功"<<endl;
}
else{
if(coursepos<0)cout<<"No course "<<coursenum<<". can't drop!"<<endl;
if(stpos<0)cout<<"No student "<<stnum<<". can't drop!"<<endl;
}
}
}
void searchstudentselectcourse(){
cout<<"11.学生选课查询:分别按学号、课程编号、专业班级等进行查询。"<<endl;
char tit[80];
string num="20136954",coursenum="BF002345",classno="地信13-1";
int i,j,k,select;
while(1){
cout<<"学生选课查询:"<<endl;
cout<<"1.按学号查询"<<endl;
cout<<"2.按课程编号查询"<<endl;
cout<<"3. 按专业班级查询"<<endl;
cout<<"0. return"<<endl;
cin>>select;
cin.get();
switch(select){
case 1:
cout<<"学号:";
getline(cin,num,'\n');
sc.searchbynum(num);
break;
case 2:
cout<<"课程编号:";
getline(cin,coursenum,'\n');
sc.searchbycoursenum(coursenum);
break;
case 3:
cout<<"专业班级:";
getline(cin,classno,'\n');
sc.searchbyclassno(classno);
break;
case 0:return;
}
}
}
};
int main()
{
StudentSelectCourse ssc;
ssc.init();
ssc.dispCourse();
ssc.dispStudent();
ssc.dispSelectCourse();
ssc.dispCount();
int select;
while(1){
cout<<"菜单选择功能:"<<endl;
cout<<"1.课程信息添加功能:包括课程编号、课程名称、课程性质、总学时、理论学时、实验学时、开课学期、起止周、课容量、选课人数等"<<endl;
cout<<"2.课程信息查询:分别按课程编号、课程名称等进行查询。"<<endl;
cout<<"3.课程信息排序:按课程编号,按课程名称等按升序进行排序。"<<endl;
cout<<"4.课程信息的修改、删除:课程编号,按课程名称进行图书的修改和删除。"<<endl;
cout<<"5.学生信息添加功能:包括学号、姓名、学院、专业班级等。"<<endl;
cout<<"6.学生信息查询:分别按学号、姓名、班级等进行查询。"<<endl;
cout<<"7.学生信息排序:按学号、学院等按升序进行排序。"<<endl;
cout<<"8.学生信息的修改、删除:按学号+姓名进行学生信息的修改和删除。"<<endl;
cout<<"9.学生选课:输入学号+课程编号,如果该课程的课程信息表中的课容量大于选课人数,则可以选课,选课后修改课程信息表中的选课人数+1,在学生选课表添加该同学的选课。"<<endl;
cout<<"10.学生退课:输入学号+课程编号,在学生选课表查找该学号学生对课程编号的选课,如果存在,则修改课程信息表中的选课人数-1,在学生选课表中设置该学号同学对课程的退选(退选标志设为1)。"<<endl;
cout<<"11.学生选课查询:分别按学号、课程编号、专业班级等进行查询。"<<endl;
cout<<"0. exit"<<endl;
cin>>select;
switch(select){
case 1:ssc.addcourse(); ssc.dispCount();break;
case 2:ssc.searchcourse();break;
case 3:ssc.sortcourse();break;
case 4:ssc.editcourse();break;
case 5:ssc.addstudent(); ssc.dispCount();break;
case 6:ssc.searchstudent();break;
case 7:ssc.sortstudent();break;
case 8:ssc.editstudent();break;
case 9:ssc.studentselectacourse();break;
case 10:ssc.studentdropacourse();break;
case 11:ssc.searchstudentselectcourse();break;
case 0:ssc.write2file();exit(0);
}
}
return 0;
}
学生选课系统(山东农业大学课程设计)
最新推荐文章于 2024-01-02 20:28:19 发布