课程信息管理源代码

#include<iostream>
#include<fstream>
#include<cstring>
#include<stdlib.h>//for atoi();
#include<stdio.h>//for getchar();
#include<iomanip>//for setw();
#include<conio.h>

using namespace std;


ifstream fin("in.txt");
ofstream fout("out.txt");
ifstream in("student.txt");

//const int MAXINT = 100;
int Total=0;//设定Total为全局变量,用来记录当前课程总数

//////////////////////////////////////////////////////////////////////
class student
{
private:
string names;
string nums;
public:
student(){}
void initstudent()
{
in>>names;
in>>nums;
}
string getnames()
{
return this->names;
}
string getnums()
{
return this->nums;
}

};


class course
{
private:
string number; //课程代号
string name; //课程名字
string classroom;//上课教室
string teacher; //授课教师
string day; //时刻时间
string time;
string names;
string nums;
//授课具体时间
public:
course() {}
void InitCourse() //课程信息初始化
{
fin>>number;
fin>>name;
fin>>classroom;
fin>>teacher;
fin>>day;
fin>>time;
//fin>>names;
//fin>>nums;
}
void AddCourse() //添加课程信息
{
cout<<endl<<endl;
cout << endl<<"\t\t"<<"课程代号:";
cin >>number;
cout<<"\t\t"<<"课程名为:";
cin>>name;
cout<<"\t\t"<<"上课教室:";
cin >> classroom;
cout<<"\t\t"<<"授课教师:";
cin >> teacher;
cout<<"\t\t"<<"上课时间:";
cin >> day;
cout<<"\t\t"<<"第几节课:";
cin >> time;
}
///////////////////////////////////////////////////////////////////////////////////
void PrintCourse() //打印课程信息
{
cout<<" "<<number<<"\t"<<name<<"\t"<<classroom<<"\t "<< teacher<<" "<<day<<"\t "<<time<<endl;
fout<<setw(10)<<number<<setw(10)<<name<<setw(10)<<classroom<<setw(10)<<teacher<<setw(10)<<day<<setw(10)<<time<<setw(10)<<endl;
}

string getname()//获取该类中的私有数据成员
{

return this->name;
}
string getnumber()
{

return this->number;
}
string getteacher()
{

return this->teacher;
}

};



/////////////////////////////////////////////////////////////////////////////////////
typedef struct LNode //使用单向链表作为存储结构
{
course data;
student data1;
struct LNode* next;
} LNode,*LinkList;

LNode* first=NULL;



void Manager(LinkList L);
void Manager_MemuList(

);
void numbersearch();
void namesearch();
void teachersearch();
void ChangeItem();
void delcourse();
void nmberchange();
void namechange();
void teacherchange();
void numberdel();
void namedel();
void teacherdel();
void DelItem();


//////////////////////////////////////////////////////////////////////////////
void InitLinkList() //链表初始化
{
int i;
for (i=1; i<=Total; i++) //使用尾插法经行初始化
{
course cs;
cs.InitCourse();
student stu;
stu.initstudent();
LNode* newlink=new LNode;
newlink->data=cs;
newlink->data1=stu;
newlink->next=first;
first=newlink;
}
}


///////////////////////////////////////////////////////////////////////////////////
void InsertLinkList() //添加课程
{
course cs;
cs.AddCourse();
LNode* newlink=new LNode;
newlink->data=cs;
newlink->next=first;
first=newlink;
Total++;//课程总数加1;
cout<<"\n 添加完毕"<<endl;
cout<<Total<<endl;
}



//////////////////////////////////////////////////////////////////////////////////////
int SearchCourse() //寻找课程名为"ch"的全部信息
{

// int i=0;
int opt;
cout<<endl<<endl;
cout<<"\t\t\t "<<"查询的项目菜单"<<endl;//选择要查询的项目
cout<<"————————————————————————————————————————"<<endl<<endl;

cout<<"\t "<<"1.\t按课程号查询";
cout<<"\t\t"<<"2.\t按课程名查询"<<endl;
cout<<"\t "<<"———————————";
cout<<"\t"<<"———————————"<<endl;
cout<<endl;
cout<<"\t "<<"3.\t按教师姓名查询";
cout<<"\t\t"<<"4.\t返回主菜单"<<endl;
cout<<"\t "<<"———————————";
cout<<"\t"<<"———————————"<<endl;
cout<<"\n请选择查询的项目:";
cin>>opt;

switch(opt)
{
case 1:
system("cls");
cout<<endl;
cout<<"\t请输入课程代号:"<<endl;
cout<<"————————————————————————————————————————"<<endl;
numbersearch();
//system("PAUSE");
break;
case 2:
system("cls");
cout<<endl;
cout<<"\t请输入课程名称:"<<endl;
cout<<"————————————————————————————————————————"<<endl;
namesearch();
// system("PAUSE&

quot;);
break;
case 3:
system("cls");
cout<<endl;
cout<<"\t请输入教师名称:"<<endl;
cout<<"————————————————————————————————————————"<<endl;
teachersearch();
//system("PAUSE");
break;
case 4:
Manager_MemuList();
break;
default:
system("cls");
cout<<"您输入错误!"<<endl;
break;

}

return -1;
}



///////////////////////////////////////
/////////////////////////////////
void numbersearch()//按课程代号查询
{
// course cou;
//int i=0;
int flag=0;
string ch;
LNode* current=first;
cin>>ch;
while(current!=NULL)
{
if(ch==current->data.getnumber())
{

current->data.PrintCourse();//打印当前课的信息
//current=current->next;
//return i;
flag=1;
}

current=current->next;
}
if(flag!=1)
{
cout<<"您输入错误!"<<endl;
system("PAUSE");
Manager_MemuList() ;

}

//
//i++;
//return -1;
}


///////////////////////////////////////////////////////////////////////////////
void namesearch()//按课程名称查询
{
int flag=0;
string ch;
LNode* current=first;
cin>>ch;
while(current!=NULL)
{
if(ch==current->data.getname())
{

current->data.PrintCourse();//打印当前课的信息
//current=current->next;
//return i;
flag=1;
}
current = current->next;
}
if(flag!=1)
{
cout<<"您输入错误!"<<endl;
system("PAUSE");
Manager_MemuList() ;

}
}

/////////////////////////////////////////////////////////////////////////////
void teachersearch()//按教师查询
{
int flag=0;//做标记

//int i=0;
string ch;
LNode* current=first;
cin>>ch;
while(current!=NULL)
{
if(ch==current->data.getteacher())
{
current->data.PrintCourse();//打印当前课的信息
flag=1;
//current=current->next;
//return i;
}
current = current->next;
//i++;
}
if(flag!=1)
{
cout<<"您输入错误!"<<endl;
system("PAUSE");
Manager_MemuList() ;

}

//return -1;
}


//////////////////////////////////////////////////////////////////////////////////////////
void ChangeItem() //修改课程信息实际操作
{
string ch;
cout<<"\n确认修改该课程(y/n):";
cin>>ch;
if (ch=="y") //修改该课程;
{
LNode* current = first;
//int j=0;
while( current->next!=NULL )
{
current=current->next;

}
current->data.AddCourse();
cout<<"\n修改成功\n";
}
else if(ch=="n")
{
cout<<"修改操作取消\n";
system("PAUSE");
Manager_MemuList();//回到主菜单界面;

}
else
{
cout<<"您输入错误!"<<endl;
system("PAUSE");
Manager_Mem

uList();//回到主菜单界面;
}

}

//////////////////////////////////////////////////////////////
void numberchange()//按课程代号查询
{
// course cou;
//int i=0;
int flag=0;
string ch;
LNode* current=first;

cin>>ch;
while(current!=NULL)
{
if(ch==current->data.getnumber())
{

current->data.PrintCourse();//打印当前课的信息
//current=current->next;
//return i;
flag=1;
}

current=current->next;
}
if(flag!=1)
{
cout<<"输入错误!"<<endl;
system("PAUSE");
Manager_MemuList() ;

}
else
{
ChangeItem();
}

}


//////////////////////////////////////////////////////////////////
void namechange()//按姓名查询
{
int flag=0;
string ch;
LNode* current=first;
cin>>ch;
while(current!=NULL)
{
if(ch==current->data.getname())
{

current->data.PrintCourse();//打印当前课的信息
//current=current->next;
//return i;
flag=1;
}
current = current->next;
}
if(flag!=1)
{
cout<<"输入错误!"<<endl;
system("PAUSE");
Manager_MemuList() ;

}
else
{
cout<<endl;
cout<<"请在以上课程中选择你要修改课程的编号:";
numberchange();
}

}

///////////////////////////////////////////////////////////////
void teacherchange()//按教师查询
{
int flag=0;

//int i=0;
string ch;
LNode* current=first;
cin>>ch;
while(current!=NULL)
{
if(ch==current->data.getteacher())
{
current->data.PrintCourse();//打印当前课的信息
flag=1;
//current=current->next;
//return i;
}
current=current->next;
//i++;
}

if(flag!=1)
{
cout<<"您输入错误!"<<endl;
system("PAUSE");
Manager_MemuList() ;
}
else
{
cout<<endl;
cout<<"请在以上课程中选择你要删除课程的编号:";
numberchange();
}
//return -1;
}



//////////////////////////////////////////////////////////////////////
void changecourse()//修改课程的主窗口
{
int opt;
cout<<endl<<endl;
cout<<"\t\t\t "<<"修改课程菜单"<<endl;//选择要查询的项目
cout<<"————————————————————————————————————————"<<endl<<endl;

cout<<"\t "<<"1.\t按课程代号修改";
cout<<"\t\t"<<"2.\t按课程名称修改"<<endl;
cout<<"\t "<<"———————————";
cout<<"\t"<<"———————————"<<endl;
cout<<endl;
cout<<"\t "<<"3.\t按教师姓名修改";
cout<<"\t\t"<<"4.\t返回主菜单"<<endl;
cout<<&quo

t;\t "<<"———————————";
cout<<"\t"<<"———————————"<<endl;
cout<<"\n\t请选择:";
cin>>opt;

switch(opt)
{
case 1:
system("c
ls");
cout<<"\t请输入课程代号:"<<endl;
cout<<"————————————————————————————————————————"<<endl;
numberchange();
break;
case 2:
system("cls");
cout<<"\t请输入课程名称:"<<endl;
cout<<"————————————————————————————————————————"<<endl;
namechange();
// system("PAUSE");
break;
case 3:
system("cls");
cout<<"\t请输入教师名称:"<<endl;
cout<<"————————————————————————————————————————"<<endl;
teacherchange();
//system("PAUSE");
break;
case 4:
Manager_MemuList();
break;
default:
system("cls");
cout<<"您输入有误!"<<endl;
break;

}

}


///////////////////////////////////////////////////////////////////////////////
void numberdel()//按编号删除
{
int flag=0;
string ch;
LNode* current=first;
cin>>ch;
while(current!=NULL)
{
if(ch==current->data.getnumber())
{

current->data.PrintCourse();//打印当前课的信息
//current=current->next;
//return i;
flag=1;
}

current=current->next;
}
if(flag!=1)
{
cout<<"输入错误!"<<endl;
system("PAUSE");
Manager_MemuList() ;

}
else
{
//cout<<"请在以上课程中选择你要删除课程的编号:";
DelItem();
}


}


//////////////////////////////////////////////////////////////////////////////
void namedel()//按课程名删除
{
int flag=0;
string ch;
LNode* current=first;
cin>>ch;
while(current!=NULL)
{
if(ch==current->data.getname())
{

current->data.PrintCourse();//打印当前课的信息
//current=current->next;
//return i;
flag=1;
}
current = current->next;
}
if(flag!=1)
{
cout<<"输入错误!"<<endl;
system("PAUSE");
Manager_MemuList() ;

}
else
{
cout<<endl;
cout<<"请在以上课程中选择你要修改课程的编号:";
numberdel();
}

}

/////////////////////////////////////////////////////////////////////
void teacherdel()//按教师删除
{
int flag=0;
string ch;
LNode* current=first;
cin>>ch;
while(current!=NULL)
{
if(ch==current->data.getteacher())
{
current->data.PrintCourse();//打印当前课的信息
flag=1;
//current=current->next;
//r

eturn i;
}
current = current->next;

//i++;
}

if(flag!=1)
{
cout<<"您输入错误!"<<endl;
system("PAUSE");
Manager_MemuList() ;
}
else
{
cout<<endl;
cout<<"请在以上课程中选择你要删除课程的编号:";
numberdel();
}
//return -1;
}

///////////////////////////////////////////////////////////////////////////////
void DelItem() //删除课程信息实际操作
{

string ch;
cout<<"\n确认删除该课程(y/n):";
cin>>ch;
if (ch=="y") //删除该课程;
{
LNode* current = first;
int j=0;
while( current->next!=NULL )
{
current=current->next;
j++;
}
LNode* q=current->next;
current->next=q->next;
delete q;
Total--;
cout<<"\n删除成功\n";
}
else if(ch=="n")
{
cout<<"删除操作取消\n";
system("PAUSE");
Manager_MemuList();//回到主菜单界面;
system("PAUSE");
}
else
{
cout<<"您输入有误!"<<endl;
system("PAUSE");
Manager_MemuList();//回到主菜单界面;

}


}

////////////////////////////////////////////////////////////////////////////
void delcourse()//删除课程的主窗口
{
int opt;
cout<<endl<<endl;
cout<<"\t\t\t "<<"删除课程菜单"<<endl;//选择要查询的项目
cout<<"————————————————————————————————————————"<<endl<<endl;

cout<<"\t "<<"1.\t按课代号删除";
cout<<"\t\t"<<"2.\t按课程名称删除"<<endl;
cout<<"\t "<<"———————————";
cout<<"\t"<<"———————————"<<endl;
cout<<endl;
cout<<"\t "<<"3.\t按教师姓删除";
cout<<"\t\t"<<"4.\t返回主菜单"<<endl;
cout<<"\t "<<"———————————";
cout<<"\t"<<"———————————"<<endl;
cout<<"\n请选择...:";
cin>>opt;

switch(opt)
{
case 1:
system("cls");
cout<<"\t请输入课程代号:"<<endl;
cout<<"————————————————————————————————————————"<<endl;
numberdel();
break;
case 2:
system("cls");
cout<<"\t请输入课程名称:"<<endl;
cout<<"————————————————————————————————————————"<<endl;
namedel()

;
break;
case 3:
system("cls");
cout<<"\t请输入教师名称:"<<endl;
cout<<"————————————————————————————————————————"<<endl;
teacherdel();
break;
case 4:
Manager_MemuList();

break;
default:
system("cls");
cout<<"您输入有误!"<<endl;
break;

}

}



////////////////////////////////////////////////////////////////////////
void starline()//画线
{
int i;
for(i=0; i<40; i++)
{
cout<<"*";
}
cout<<endl;
}

/////////////////////////////////////////////////////////////////////////
void Manager_MemuList() //主菜单操作界面
{
cout<<endl;
system("cls");

cout<<endl<<endl;
cout<<"\t\t\t "<<"欢迎进入课程信息管理系统"<<endl;
cout<<"————————————————————————————————————————"<<endl;
cout<<endl;
cout<<endl;
// starline();

cout<<"\t\t"<<"1.安全退出系统"<<"\t\t";
cout<<"\t"<<"2.添加课程信息"<<endl;
cout<<"\t\t"<<"———————";
cout<<"\t\t\t"<<"———————"<<endl;
cout<<endl;
cout<<"\t\t"<<"3.查询课程信息"<<"\t\t";
cout<<"\t"<<"4.修改课程信息"<<endl;
cout<<"\t\t"<<"———————";
cout<<"\t\t\t"<<"———————"<<endl;
cout<<endl;
cout<<"\t\t"<<"5.删除课程信息"<<"\t\t";
cout<<"\t"<<"6.打印所有课程"<<endl;
cout<<"\t\t"<<"———————";
cout<<"\t\t\t"<<"———————"<<endl;
cout<<endl<<endl;
//cout<<"\t\t\t "<<"请输入要操作的序号:";

//starline();
}


//////////////////////////////////////////////////////////////////////////////////
void Manager(LinkList L) //操作系统
{
int opt = 1;
while (opt != 0) //管理员操作界面
{
Manager_MemuList();
cout<<"\t\t\t "<<"请输入要操作的序号:";
cin >> opt;
switch (opt)
{
case 1:
cout<<"\n 该账号已安全退出"<<endl;
exit(0);
break;
case 2:
system("cls");
InsertLinkList();
system("PAUSE");
break;
case 3:
system("cls");
SearchCourse();
system("PAUSE");
br

eak;//查看指定课程情况

case 4:
system("cls");
changecourse();
system("PAUSE");
break;//修改课程信息
case 5:
system("cls");
delcourse();
system("PAUSE");
break;//删除课程
case 6:
system("cls");
PrintItem();
system("PAUSE");
break;//打印课程
default:

break;
}
}
}

//////////////////////////////////////////////////////////////////////////
void student_login()//学生登录
{
LinkList L;
L=new LNode;


string ch1;
string ch2;
a:
cout<<endl<<endl<<endl;
cout<<"\t\t"<<"请输入姓名:";
cin>>ch1
;
cout<<endl;
cout<<"\t\t"<<"请输入学号:";
// cin>>ch2;
char ch;
while ((ch=_getch())!=13)
{
ch2+=ch;//string对象重载了+=
cout<<"*";
}

int flag=0;
LNode* current=first;
while(current!=NULL)
{
if((ch1==current->data1.getnames())&&(ch2==current->data1.getnums()))
{
Manager(L);
flag=1;
}
current=current->next;
//i++;
}

if(flag!=1)
{
cout<<endl;
cout<<"\t\t"<<"您输入错误!"<<endl;
cout<<"\t\t"<<"按任意键选择重新输入:"<<endl;
//cout<<ch2;
// cout<<"请重新输入...";
system("PAUSE");
system("cls");

goto a;
//Manager_MemuList() ;
}
//return 0;
}

//////////////////////////////////////////////////////////////////////////////////




相关文档
最新文档