//学生类:#ifndef H_STUDENT_H_NNN
#define H_STUDENT_H_NNN
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
class Student{
protected:
string name;
string sex;
string phone;
string id;
long num;
int x,y,z,AA;
public:
virtual void dispaly()
{cout<<name<<sex<<phone<<num<<x<<y<<z<<AA<<endl;}
Student(string sname,string ssex,string sphone,long snum,int sx,int sy,int sz)
{ name=sname;
sex=ssex;
phone=sphone;
num=snum;
x=sx;
y=sy;
z=sz;
}
Student() {}
~Student() {}
};
#endif
//本科生#ifndef H_COLLEGE_H_NNN
#define H_COLLEGE_H_NNN
#include"Student.h"
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
class College:public Student{
protected:
string id;
public:
College *next;
string subject;
void display();
friend ostream& operator<<(ostream&,const College&);
friend istream& operator>>(istream&,College&);
College () {}
~College() {}
College(string sname,string ssex,string sphone,string ssubject,long snum,int sx,int sy,int sz ):Student( sname, ssex, sphone, snum,sx, sy, sz)
{ id="undergraduate";
subject=ssubject;
}
College(College &a):Student( a.name, a.sex, a.phone, a.num,a.x, a.y, a.z)
{ this->id=a.id;
this->subject=a.subject;
}
friend class Clas;
} ;
#endif
//研究生类:#ifndef H_GRADUATE_H_NNN
#define H_GRADUATE_H_NNN
#include"Student.h"
class Graduate:public Student{
protected:
string id;
public:
Graduate *next;
string subject;
void display();
Graduate () {}
~Graduate() {}
friend ostream& operator<<(ostream&,const Graduate&);
friend istream& operator>>(istream&,Graduate&);
Graduate(string sname,string ssex,string sphone,string ssubject,long snum,int sx,int sy,int sz ):Student( sname, ssex, sphone, snum,sx, sy, sz)
{ id="graduate";
subject=ssubject;
}
Graduate(Graduate &a):Student( a.name, a.sex, a.phone, a.num,a.x, a.y, a.z)
{ this->id=a.id;
this->subject=a.subject;
}
friend class Clas;
};
#endif
//管理学生信息类:#ifndef H_CLASS_H_NNN
#define H_CLASS_H_NNN
#include<iostream>
#include"College.h"
#include"Graduate.h"
#include<string.h>
#include<string>
using namespace std;
class Clas{
private:
College *Col;
Graduate *Gra;
static string password;
public:
Clas()
{ Col=0;
Gra=0;
sload();
}
~Clas()
{ College *p;
p=Col;
while(p)
{ p=p->next;
delete Col;
Col=p;
}
Col=0;
Graduate *p1;
p1=Gra;
while(p1)
{ p1=p1->next;
delete Gra;
Gra=p1;
}
Gra=0;
}
string getpassword()
{return password;}
void menuselect();//菜单
void sadd(); //添加
void sremove(); // 删除
void samend(); // 修改
void ssearch(); // 查询
void staxis(); // 排序
void ssave(); //保存
void sload();//读取
//排序函数
void pxh();
void psx();
void pyw();
void pyy();
void pAA();
};
#endif
//本科生类.cpp
#include"College.h"
#include"Student.h"
#include<string.h>
#include<string>
#include<iostream>
using namespace std;
void College::display()
{cout<<"学位"<<id<<"姓名"<<name<<"性别"<<sex<<"学号"<<num<<"专业"<<subject<<"数学"<<x<<"计算机 "<<y<<" 英语"<<z<<"总分"<<AA<<endl;}
istream& operator>>(istream& in,College& right)
{in>>right.name>>right.sex>>right.phone>>right.subject>>right.num>>right.x>>right.y>>right.z;
return in;
}
ostream& operator<<(ostream& out,const College& right)
{ cout<<"学历 "<<"姓名 "<<" 性别 "<<"专业 "<<"学号 "<<" 数学成绩 "<<" 计算机成绩 "<<"英语成绩 "<<"总成绩"<<endl;
out<<right.id<<" "<<right.name<<" "<<right.sex<<" "<<right.subject<<" "<<right.num<<" "<<right.x<<" "<<right.y<<" "<<right.z<<" "<<right.AA<<endl;
return out;
}
//研究生类.cpp
#include"Graduate.h"
#include"Student.h"
#include<string.h>
#include<string>
#include<iostream>
using namespace std;
void Graduate::display()
{cout<<"学位"<<id<<"姓名"<<name<<"性别"<<sex<<"学号"<<num<<"专业"<<subject<<"数学"<<x<<"计算机 "<<y<<" 英语"<<z<<"总分"<<AA<<endl;}
istream& operator>>(istream& in,Graduate& right)
{in>>right.name>>right.sex>>right.phone>>right.subject>>right.num>>right.x>>right.y>>right.z;
return in;
}
ostream& operator<<(ostream& out,const Graduate& right)
{out<<right.id<<" "<<right.name<<" "<<right.sex<<" "<<right.subject<<" "<<right.num<<" "<<right.x<<" "<<right.y<<" "<<right.z<<""<<right.AA<<endl;
return out;
}
//学生信息管理类.cpp
#include"Clas.h"
#include<iostream>
#include<string.h>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
//增加学生信息
string Clas::password="123456";
void Clas::sadd()
{ system("cls");
cout<<"\n** 增加学生的信息**\n"<<endl;
cout<<"请输入增加学生信息的类型"<<endl;
cout<<"1.增加本科生的信息"<<endl;
cout<<"2.增加研究生的信息"<<endl;
cout<<"3.返回"<<endl;
char c;cin>>c;
cout<<"请输入数据\n"<<endl;
if(c=='3') return ;
string sname,ssex,sphone,ssubject;
long snum;
int sx,sy,sz;
cout<<"姓名"<<" "<<"性别"<<" "<<"电话"<<" "<<"专业"<<" "<<"学号 "<<" 数学成绩"<<" "<<"计算机成绩"<<" "<<"英语成绩"<<endl;
//cin>>sname>>ssex>>sphone>>ssubject>>snum>>sx>>sy>>sz;
if(c=='1') { College d,*q;
cin>>d;
q=new College(d);
q->AA=d.x+d.y+d.z ;
//q=new College(sname,ssex,sphone,ssubject,snum,sx,sy,sz);
//q->AA=sx+sy+sz;
q->next=0;
if(Col)
{ College *t;
t=Col;
if(t->num==snum)
{ cout<<"学号已经存在,请重新输入"<<endl;
return;
}
while(t->next)
{ if(t->num==snum)
{ cout<<"学号已经存在,请重新输入"<<endl;
return;
}
t=t->next;
}
t->next=q;
}
else Col=q;
cout<<"输入完毕!"<<endl;return;
}
else if(c=='2'){
Graduate *q,d;
cin>>d;
q=new Graduate(d);
//q=new Graduate(sname,ssex,sphone,ssubject,snum,sx,sy,sz);
q->AA=d.x+d.y+d.z;
q->next=0;
if(Gra)
{ Graduate *t;
t=Gra;
if(t->num==snum)
{ cout<<"学号已经存在,请重新输入"<<endl;
return;
}
while(t->next)
{ if(t->num==snum)
{ cout<<"学号已经存在,请重新输入"<<endl;
return;
}
t=t->next;
}
t->next=q;
}
else Gra=q;
cout<<"输入完毕!"<<endl;return;
}
}
//删除学生信息
void Clas::sremove()
{ system("cls");
cout<<"\n** 删除学生的信息**\n"<<endl;
int num1;
cout<<"请输入要删除学生的学号"<<endl;
cin>>num1;
cout<<"请输入要删除学生信息的类型"<<endl;
cout<<"1.删除本科生的信息"<<endl;
cout<<"2.删除研究生的信息"<<endl;
cout<<"3.返回"<<endl;
char c;cin>>c;
if(c=='3') return ;
if(c=='1') { College *p1,*p2;
p1=Col;
while(p1)
{ if(p1->num==num1)
break;
else{ p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{ p1->display();
cout<<"确定要删除吗?[Y/N]"<<endl;
char ch;cin>>ch;
if(toupper(ch)!='Y') return;
if(p1==Col)
{ Col=p1->next;
delete p1;
}
else { p2->next=p1->next;
delete p1;
}
cout<<"找到学号为"<<num1<<"的本科生,并删除\n ";
}
else cout<<"没有找到要删除本科生的信息\n";
}
else if(c=='2') { Graduate *p1,*p2;
p1=Gra;
while(p1)
{ if(p1->num==num1)
break;
else{ p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{ p1->display();
cout<<"确定要删除吗?[Y/N]"<<endl;
char ch;cin>>ch;
if(toupper(ch)!='Y') return;
if(p1==Gra)
{ Gra=p1->next;
delete p1;
}
else { p2->next=p1->next;
delete p1;
}
cout<<"找到学号为"<<num1<<"的研究生的信息,并删除\n ";
}
else cout<<"没有找到要删除研究生的信息\n";
}
cout<<"删除完毕!"<<endl;
return;
}
void Clas::samend()
{ system("cls");
cout<<"\n** 修改学生的信息**\n"<<endl;
int num1;
cout<<"请输入要修改学生的学号"<<endl;
cin>>num1;
cout<<"请输入要修改学生信息的类型"<<endl;
cout<<"1.修改本科生的信息"<<endl;
cout<<"2.修改研究生的信息"<<endl;
cout<<"3.返回"<<endl;
char c;cin>>c;
if(c=='1') { College *p1,*p2;
p1=Col;
while(p1)
{ if(p1->num==num1) break;
else { p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{ cout<<"学号是"<<num1<<"本科生的信息"<<endl;
cout<<"姓名"<<p1->name<<"性别"<<p1->sex<<"电话"<<p1->phone<<"专业"<<p1->subject<<"数学"<<p1->x<<"计算机 "<<p1->y<<"英语 "<<p1->z<<endl;
cout<<"请输入要修改的信息,姓名,学号,数学,计算机,英语成绩"<<endl;
cin>>p1->name>>p1->num>>p1->x>>p1->y>>p1->z;
p1->AA=p1->x+p1->y+p1->z;
cout<<"修改成功"<<endl;
}
else{ cout<<"未找到\n";}
}
if(c=='2') { Graduate *p1,*p2;
p1=Gra;
while(p1)
{ if(p1->num==num1) break;
else { p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{ cout<<"学号是"<<num1<<"研究生的信息"<<endl;
cout<<"姓名"<<p1->name<<"性别"<<p1->sex<<"电话"<<p1->phone<<"专业"<<p1->subject<<"数学 "<<p1->x<<"计算机 "<<p1->y<<"英语 "<<p1->z<<endl;
cout<<"请输入要修改的信息,姓名,学号,数学,计算机,英语成绩"<<endl;
cin>>p1->name>>p1->num>>p1->x>>p1->y>>p1->z;
p1->AA=p1->x+p1->y+p1->z;
cout<<"修改成功"<<endl;
}
else{ cout<<"未找到\n";}
}
if(c=='3')return;
}
void Clas::ssearch()
{ system("cls");
cout<<"\n** 查找学生的信息**\n"<<endl;
cout<<"请输入查找学生信息的类型"<<endl;
cout<<"1.查找本科生的信息"<<endl;
cout<<"2.查找研究生的信息"<<endl;
cout<<"3.返回"<<endl;
char c;cin>>c;
if(c=='3')return;
cout<<"输入查询方式"<<endl;
cout<<"1.按学号查询"<<endl;
cout<<"2.按姓名查找"<<endl;
cout<<"3.返回"<<endl;
char ch;cin>>ch;
switch(ch)
{ case '1':
{if(c=='1'){ College *p1,*p2;
p1=Col;
long num1;
cout<<"请输入要查询的学号"<<endl;
cin>>num1;
while(p1)
{ if(p1->num==num1)
break;
else{ p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{ cout<<"学号为"<<num1<<"本科生的信息"<<endl;
cout<<"姓名"<<p1->name<<"性别"<<p1->sex<<"电话"<<p1->phone<<"专业"<<p1->subject<<"数学 "<<p1->x<<"计算机 "<<p1->y<<"英语 "<<p1->z<<endl;
cout<<"查询完毕。。。。"<<endl;
}
else cout<<"没有查找到!"<<endl;
}
if(c=='2')
{ Graduate *p1,*p2;
p1=Gra;
long num1;
cout<<"请输入要查询的学号"<<endl;
cin>>num1;
while(p1)
{ if(p1->num==num1)
break;
else{ p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{ cout<<"学号为"<<num1<<"研究生的信息"<<endl;
cout<<"姓名"<<p1->name<<"性别"<<p1->sex<<"电话"<<p1->phone<<"专业"<<p1->subject<<"数学 "<<p1->x<<"计算机 "<<p1->y<<"英语 "<<p1->z<<endl;
cout<<"查询完毕。。。。"<<endl;
}
else cout<<"没有查找到!"<<endl;
}
break;
}
case '2':
{ if(c=='1'){ College *p1,*p2;
p1=Col;
string sname;
cout<<"请输入要查询的姓名"<<endl;
cin>>sname;
while(p1)
{ if(p1->name==sname)
break;
else{ p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{ cout<<"姓名为"<<sname<<"本科生的信息"<<endl;
cout<<"学号"<<p1->num<<"性别"<<p1->sex<<"电话"<<p1->phone<<"专业"<<p1->subject<<"数学 "<<p1->x<<"计算机 "<<p1->y<<"英语 "<<p1->z<<endl;
cout<<"查询完毕。。。。"<<endl;
}
else cout<<"没有查找到!"<<endl;
}
if(c=='2')
{ Graduate *p1,*p2;
p1=Gra;
string sname;
cout<<"请输入要查询的姓名"<<endl;
cin>>sname;
while(p1)
{ if(p1->name==sname)
break;
else{ p2=p1;
p1=p1->next;
}
}
if(p1!=NULL)
{ cout<<"姓名为"<<sname<<"研究生的信息"<<endl;
cout<<"学号"<<p1->num<<"性别"<<p1->sex<<"电话"<<p1->phone<<"专业"<<p1->subject<<"数学 "<<p1->x<<"计算机 "<<p1->y<<"英语 "<<p1->z<<endl;
cout<<"查询完毕。。。。"<<endl;
}
else cout<<"没有查找到!"<<endl;
}
break;
}
case '3':return;
}
}
// 按学号进行排序
void Clas::pxh()
{ system("cls");
cout<<"\n** 按学号对学生的信息进行排序**\n"<<endl;
cout<<"选择排序类型"<<endl;
cout<<"1.对本科生进行排序"<<endl;
cout<<"2.对研究生进行排序"<<endl;
cout<<"3.返回"<<endl;
char ch;cin>>ch;
if(ch=='3')return;
if(ch=='1'){
College *p1,*p2;
p1=Col;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Col;
for( i=1;i<n;++i)
{ p1=Col;
if(p1->num>p1->next->num)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Col=p2;
}
p1=Col;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->num>p1->next->num)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Col;
do{ College d;
d=*p1;
//p1->display();
cout<<d;
p1=p1->next;
}while(p1);
}
else if(ch=='2'){ Graduate *p1,*p2;
p1=Gra;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Gra;
for( i=1;i<n;++i)
{ p1=Gra;
if(p1->num>p1->next->num)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Gra=p2;
}
p1=Gra;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->num>p1->next->num)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Gra;
do{
p1->display();
p1=p1->next;
}while(p1);
}
cout<<"排序完毕.....\n";return;
}
//按数学成绩进行排序
void Clas::psx()
{ system("cls");
cout<<"\n** 按成绩对学生的信息进行排序**\n"<<endl;
cout<<"选择排序类型"<<endl;
cout<<"1.对本科生进行排序"<<endl;
cout<<"2.对研究生进行排序"<<endl;
cout<<"3.返回"<<endl;
char ch;cin>>ch;
if(ch=='3')return;
if(ch=='1'){
College *p1,*p2;
p1=Col;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Col;
for( i=1;i<n;++i)
{ p1=Col;
if(p1->x>p1->next->x)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Col=p2;
}
p1=Col;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->x>p1->next->x)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Col;
do{
p1->display();
p1=p1->next;
}while(p1);
}
else if(ch=='2'){ Graduate *p1,*p2;
p1=Gra;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Gra;
for( i=1;i<n;++i)
{ p1=Gra;
if(p1->x>p1->next->x)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Gra=p2;
}
p1=Gra;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->x>p1->next->x)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Gra;
do{
p1->display();
p1=p1->next;
}while(p1);
}
cout<<"排序完毕.....\n";return;
}
//按计算机成绩进行排序
void Clas::pyw()
{ system("cls");
cout<<"\n** 按计算机成绩对学生的信息进行排序**\n"<<endl;
cout<<"选择排序类型"<<endl;
cout<<"1.对本科生进行排序"<<endl;
cout<<"2.对研究生进行排序"<<endl;
cout<<"3.返回"<<endl;
char ch;cin>>ch;
if(ch=='3')return;
if(ch=='1'){
College *p1,*p2;
p1=Col;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Col;
for( i=1;i<n;++i)
{ p1=Col;
if(p1->y>p1->next->y)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Col=p2;
}
p1=Col;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->y>p1->next->y)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Col;
do{
p1->display();
p1=p1->next;
}while(p1);
}
else if(ch=='2'){ Graduate *p1,*p2;
p1=Gra;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Gra;
for( i=1;i<n;++i)
{ p1=Gra;
if(p1->y>p1->next->y)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Gra=p2;
}
p1=Gra;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->y>p1->next->y)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Gra;
do{
p1->display();
p1=p1->next;
}while(p1);
}
cout<<"排序完毕.....\n";return;
}
//按英语成绩进行排序
void Clas::pyy()
{ system("cls");
cout<<"\n** 按英语成绩对学生的信息进行排序**\n"<<endl;
cout<<"选择排序类型"<<endl;
cout<<"1.对本科生进行排序"<<endl;
cout<<"2.对研究生进行排序"<<endl;
cout<<"3.返回"<<endl;
char ch;cin>>ch;
if(ch=='3')return;
if(ch=='1'){
College *p1,*p2;
p1=Col;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Col;
for( i=1;i<n;++i)
{ p1=Col;
if(p1->z>p1->next->z)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Col=p2;
}
p1=Col;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->z>p1->next->z)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Col;
do{
p1->display();
p1=p1->next;
}while(p1);
}
else if(ch=='2'){ Graduate *p1,*p2;
p1=Gra;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Gra;
for( i=1;i<n;++i)
{ p1=Gra;
if(p1->z>p1->next->z)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Gra=p2;
}
p1=Gra;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->z>p1->next->z)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Gra;
do{
p1->display();
p1=p1->next;
}while(p1);
}
cout<<"排序完毕.....\n";return;
}
//按总成绩进行排序
void Clas::pAA()
{ system("cls");
cout<<"\n** 按总成绩对学生的信息进行排序**\n"<<endl;
cout<<"选择排序类型"<<endl;
cout<<"1.对本科生进行排序"<<endl;
cout<<"2.对研究生进行排序"<<endl;
cout<<"3.返回"<<endl;
char ch;cin>>ch;
if(ch=='3')return;
if(ch=='1'){
College *p1,*p2;
p1=Col;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Col;
for( i=1;i<n;++i)
{ p1=Col;
if(p1->AA>p1->next->AA)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Col=p2;
}
p1=Col;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->AA>p1->next->AA)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Col;
do{
p1->display();
p1=p1->next;
}while(p1);
}
else if(ch=='2'){ Graduate *p1,*p2;
p1=Gra;
if(!p1) {cout<<"还没有存入信息,请存入信息后再进行操作。。。。\n";return;}
int n=1,i;
while(p1->next)
{ n++;p1=p1->next;}
cout<<"共有"<<n<<"条信息。。。"<<endl;
p1=Gra;
for( i=1;i<n;++i)
{ p1=Gra;
if(p1->AA>p1->next->AA)
{ p2=p1->next;
p1->next=p1->next->next;
p2->next=p1;
Gra=p2;
}
p1=Gra;
while(p1->next->next)
{ p2=p1;
p1=p1->next;
if(p1->AA>p1->next->AA)
{ p2->next=p1->next;
p1->next=p1->next->next;
p2->next->next=p1;
p1=p2->next;
}
}
}
p1=Gra;
do{
p1->display();
p1=p1->next;
}while(p1);
}
cout<<"排序完毕.....\n";return;
}
void Clas::staxis()
{ system("cls");
char c;
cout<<"请选择以何种方式排序:"<<endl;
cout<<"1......以学号方式排序"<<endl;
cout<<"2......以数学成绩排序"<<endl;
cout<<"3......以计算机成绩排序"<<endl;
cout<<"4......以英语成绩排序"<<endl;
cout<<"5......以总分排序"<<endl;
cout<<"6......返回"<<endl;
cout<<".......请选择(1-6)"<<endl;
cin>>c;
switch(c)
{ case '1':pxh();break;
case '2':psx();break;
case '3':pyw();break;
case '4':pyy();break;
case '5':pAA();break;
case '6':return;
}
}
void Clas::ssave()
{ system("cls");
char c;
cout<<"\n保存学生信息(将要覆盖原来的文件),是否继续?[Y/N]: ";cin>>c;
if(toupper(c)!='Y') return;
cout<<"选择保存类型"<<endl;
cout<<"1.对本科生的信息进行保存"<<endl;
cout<<"2.对研究生的信息进行保存"<<endl;
cout<<"3.返回"<<endl;
char ch;cin>>ch;
if(ch=='3') return;
if(ch=='1'){
College *p=Col;
if(!p) {cout<<"还没有信息哦。。请输入信息后在进行保存。。\n";return;}
cout<<"下面开始保存本科生的信息"<<endl;
ofstream cfile("c:\\cdate.txt",ios_base::binary);
while(p)
{ p->display();
cfile<<p->name<<"\t"<<p->sex<<"\t"<<p->phone<<"\t"<<p->subject<<"\t"<<p->num<<"\t"<<p->x<<"\t"<<p->y<<"\t"<<p->z;
cfile<<endl;
p=p->next;
}
cfile.close();
cout<<"本科生信息保存完毕......"<<endl;
}
if(ch=='2'){
Graduate *p1=Gra;
if(!p1) {cout<<"还没有信息哦。。请输入信息后在进行保存。。\n";return;}
cout<<"下面开始保存研究生的信息"<<endl;
ofstream gfile("c:\\gdate.txt",ios_base::binary);
while(p1)
{ p1->display();
gfile<<p1->name<<"\t"<<p1->sex<<"\t"<<p1->phone<<"\t"<<p1->subject<<"\t"<<p1->num<<"\t"<<p1->x<<"\t"<<p1->y<<"\t"<<p1->z;
p1=p1->next;
}
gfile.close();
cout<<"研究生信息保存完毕......"<<endl;
}
}
void Clas::sload()
{ College *p;
p=Col;
while(p)
{ Col=p->next;
delete p;
p=Col;
}
Graduate *p1;
p1=Gra;
while(p1)
{ Gra=p1->next;
delete p1;
p1=Gra;
}
ifstream cfile("c:\\cdate.txt",ios_base::binary);
ifstream gfile("c:\\gdate.txt",ios_base::binary);
cout<<"加入本科生信息。。。\n" ;
string ssubject,sname,sphone,ssex;
int sx,sy,sz;
long snum;
cfile>>sname>>ssex>>sphone>>ssubject>>snum>>sx>>sy>>sz;
while(cfile.good())
{ College *s;
s=Col;
s=new College(sname,ssex,sphone,ssubject,snum,sx,sy,sz);
s->display();
s->next=0;
s->AA=sx+sy+sz;
if(Col)
{ College *s1;
s1=Col;
while(s1->next)
{ s1=s1->next;}
s1->next=s;
}
else { Col=s;}
cfile>>sname>>ssex>>sphone>>ssubject>>snum>>sx>>sy>>sz;
}
cfile.close();
cout<<"本科生信息加入完毕。。。\n";
cout<<"加入研究生信息。。。。\n" ;
gfile>>sname>>ssex>>sphone>>ssubject>>snum>>sx>>sy>>sz;
while(gfile.good())
{ Graduate *s;
s=Gra;
s=new Graduate(sname,ssex,sphone,ssubject,snum,sx,sy,sz);
s->display();
s->next=0;
s->AA=sx+sy+sz;
if(Gra)
{ Graduate *s1;
s1=Gra;
while(s1->next)
{ s1=s1->next;}
s1->next=s;
}
else { Gra=s;}
gfile>>sname>>ssex>>sphone>>ssubject>>snum>>sx>>sy>>sz;
}
gfile.close();
cout<<"研究生信息加入完毕。。。\n";
}
void Clas::menuselect()
{ while(true)
{char c;
cout<<"\n\t\t\t\t高校学生信息管理系统 \n";
cout<<"\t\t\t**********************************\n";
cout<<"\t\t\t*******10级+计科(1)班******\n";
cout<<"\t\t\t1..........增加学生信息...........\n";
cout<<"\t\t\t2...........删除学生信息..........\n";
cout<<"\t\t\t3...........修改学生信息..........\n";
cout<<"\t\t\t4...........查询学生信息..........\n";
cout<<"\t\t\t5................排序.............\n";
cout<<"\t\t\t6............保存信息.............\n";
cout<<"\t\t\t7.............读取信息............\n";
cout<<"\t\t\t8.................退出............\n";
cout<<"\t\t\t**********************************\n";
cout<<"\t\t\t\t请选择(1-8):";
cin>>c;
switch(c)
{ case '1': sadd();break;
case '2': sremove();break;
case '3': samend();break;
case '4': ssearch();break;
case '5': staxis();break;
case '6': ssave();break;
case '7': sload();break;
case '8': exit(0);
}
}
}
//主函数:
#include<iostream>
#include<string.h>
#include<string>
#include<fstream>
#include<iomanip>
#include"College.h"
#include"Student.h"
#include"Graduate.h"
#include"Clas.h"
#include<windows.h>
using namespace std;
int main()
{ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN);
cout<<"\n\t\t\t\t请输入密码(*^__^*) \n" ;
string ss;
cin>>ss;
Clas a;
if(ss==a.getpassword()) a.menuselect();
else exit(1);
return 0;
}
c++课程设计
最新推荐文章于 2022-06-09 20:14:54 发布