⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manager.cpp

📁 一个有用的学生管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
              temp3=front;  
           }
	   if(temp2==NULL) {temp3=p; continue;}           
	
      temp4=temp2->NextNode();
      temp1->InsertAfter(temp4);
      temp2->InsertAfter(p);
      temp3->InsertAfter(temp2);
      p=temp2;
      temp2=NULL;  
      temp3=p;
	  if(p->NextNode()->NextNode()==NULL){
               p->data.GotName(name);
               temp4=p->NextNode();
               temp4->data.GotName(tempname);
               if(strcmp(name,tempname)>0)
                              { temp4=p->NextNode();
			                    temp1->InsertAfter(temp4);
                               temp4=p->NextNode();
                               temp4->InsertAfter(p);
                                break;
                               }
	  }
//	            temp4=p->NextNode();
//          temp4->data.GotName(tempname);
//          if(strcmp(name,tempname)>0){ 
//				   front=temp4;
//				   temp4=p->NextNode();
//			       temp4->InsertAfter(p);
//				   p->InsertAfter(temp);
//                   }
   
   
   }

}
#endif
//菜单模块声明
#ifndef FUCSHOWMENU
#define FUCSHOWMENU
template <class T>
//添加到某一指定结点子菜单
void minmenu( LiskList<T> &L){
	char x;
	int n;
	bool quit=false;
	while(!quit){
		minShowMenu();
		cin>>x;
		switch(x){
		case '0':
			quit=true; //退出
			break;
		case '1':
			cout<<"请输入要添加的数据"<<endl;  //添加信息到头结点之前
			L.InsertFront();
			break;
		case '2':
		L.InsertRear();  //添加信息到尾结点之后
		break;
		case '3':
			cout<<"请指定结点位置"<<endl;  //添加信息到指定结点
			cin>>n;
			L.Reset(n);
			L.InsertAfter();
			break;
		default:
			cout<<"您输错了!!!"<<endl;
			break;
		}
	}
}
//功能菜单模块
template <class T>
void sonmenu( LiskList<T> &L){
		int i;
    char sure,b[4]={'Y','y','N','n'};
    bool suredoor=false;
	char x;
	bool quit=false;
	while(!quit){
		sonShowMenu();  //显示提示信息
		cin>>x;
		switch(x){
		case '0':
			quit=true;  //退出 
			break;
		case '1':
			L.InsertFront();//默认添加信息到头结点之前
			break;
		case '2':
			cout<<"请输入要修改的数据"<<endl;
			L.Modify();  //修改信息
			break;
		case '3':
			L.Delete();  //删除某一信息
			break;
		case '4':
			cout<<"    姓名   "<<"     学号    "<<"语文  "<<"  英语  "<<"  数学  "<<"  总分  "<<"平均分  "<<endl;
			L.ListAll();//显示所有信息
			break;
		case '5':
	cout<<"确定要删除全部吗,是请输入Y(y),否则输入N(n):  ";
	do{cin>>sure;
		for(i=0;i<4;i++)
			if(b[i]==sure)  suredoor=true;
			    if(suredoor==false)
						cout<<"输入错误,请重新输入 ?_?:  ";
		}while(!suredoor);
	if(IsSure(sure)){
		    L.ClearList();
			cout<<"删除成功"<<endl;
		}
	else cout<<"取消删除操作"<<endl;		
		break;
		case '6':
			L.Find();  //查找信息
			break;
		case '7':
				L.sorted();
			break;
		case '8':
			minmenu(L);//添加信息到指定结点 
			break;
		default:
			cout<<"您输错了!!!"<<endl;
			break;
		}

	}
}
#endif
//显示添加到指定结点菜单提示信息
void minShowMenu(){
	cout<<"\n************\n";
	cout<<"1.添加到头结点"<<endl;
	cout<<"2.添加到尾结点"<<endl;
	cout<<"3.添加指定结点"<<endl;
	cout<<"0.退出"<<endl;
	cout<<"请输入0~3"<<"  ";
}
//功能菜单提示信息
void sonShowMenu(){
	cout<<"\n***************\n";
	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<<"0.退出"<<endl;
	cout<<"请选择0~7"<<"  ";
}
class Student{
private:
	char name[15];//姓名
	int Age;//年龄
	double Chinese;//语文成绩
	double English;//英语成绩
	double Math;//数学成绩
	char SNo[8];//学号
	double Total;//总分
	double Average;//平均分
	void CalTotal();//计算总分
	void CalAverage();//计算平均分
public:
	Student(){}
	~Student(){}
	char *GetName();//返回姓名值
	void SetName(const char *s);//设置姓名
	int GetAge();//返回年龄值
	void SetAge(int i);//设置年龄值
	double GetChinese();//返回语文成绩值
	void SetChinese(double i);//设置语文成绩值
	double GetEnglish();//返回英语成绩值
	void SetEnglish(double i);//设置英语成绩值
	double GetMath();//返回数学成绩值
	void SetMath(double i);//设置数学成绩值
	char *GetSNo();//返回学号值
	void SetSNo(const char *s);//设置学号
	double GetTotal();//计算总分
	double GetAverage();//计算平均分
	void GotName(char a[]);//得到姓名值
	friend istream &operator <<(istream &acin,Student &S);//重载输入
	friend ostream &operator >>(ostream &acout,Student &S);//重载输出
};
void Student::CalTotal (){
	Total=Math+Chinese+English;
}
void Student::CalAverage (){
	Average=(Math+Chinese+English)/3;
}
char *Student::GetName (){
	return name;
}
void Student::SetName (const char *s){
	strcpy(name,s);
}

int Student::GetAge (){
	return Age;
}
void Student::SetAge (int i){
    Age=i;
}
double Student::GetChinese (){
	return Chinese;
}
void Student::SetChinese (double i){
	Chinese=i;
}

double Student::GetEnglish (){
	return English;
}
void Student::SetEnglish (double i){
	English=i;
}
double Student::GetMath (){
	return Math;
}
void Student::SetMath (double i){
	Math=i;
}
char *Student::GetSNo(){
	return SNo;
}
void Student::SetSNo(const char *s){
	strcpy(SNo,s);
}
double Student::GetTotal(){
	CalTotal();
	return Total;
}
double Student::GetAverage (){
    CalAverage();
	return Average;
}
void Student::GotName(char a[]){
	strcpy(a,name);
}
istream &operator >>(istream &acin,Student &S){
	string temp;bool OrRight=false;
	double i;
	const char *c;
	cout<<"请输入姓名:  ";
	acin>>temp;S.SetName(temp.c_str());
	cout<<"请输入学号(8位数字):  ";
	do{
	acin>>temp;
	if(IsSNo(temp.c_str())){
		S.SetSNo(temp.c_str());
		OrRight=true;
	}
	else cout<<"输入错误,请重新输入:  ";
	}while(!OrRight);
	OrRight=false;
	cout<<"请输入语文成绩(0~150):  ";
	do{
	acin>>temp;
	if(IsNumber(temp.c_str())){
		c=temp.c_str();
		i=atof(c);
		if(Scores(i)){
	    S.SetChinese(i);
	    OrRight=true;
		}
		else cout<<"输入错误,请重新输入:  ";
	}
	else cout<<"输入错误,请重新输入:  ";
	}while(!OrRight);
	OrRight=false;
	cout<<"请输入英语成绩(0~150):  ";
    do{
	acin>>temp;
	if(IsNumber(temp.c_str())){
		     c=temp.c_str();
			 i=atof(c);
			 if(Scores(i)){
	         S.SetEnglish (i);
			 OrRight=true;
			 }
			 else cout<<"输入错误,请重新输入:  ";
			 }
	else cout<<"输入错误,请重新输入:  ";
	}while(!OrRight);
	OrRight=false;
	cout<<"请输入数学成绩(0~150):  ";
	do{
	acin>>temp;
	if(IsNumber(temp.c_str())){
		     c=temp.c_str();
			 i=atof(c);
             if(Scores(i)){
	         S.SetMath(i);
			 OrRight=true;
			 }
			 else cout<<"输入错误,请重新输入:  ";
	}
	else cout<<"输入错误,请重新输入:  "<<endl;
	}while(!OrRight);
	S.GetTotal ();
	S.GetAverage ();
	return acin;
}
ostream &operator <<(ostream &acout,Student &S){
	acout<<setw(8)<<S.GetName()<<"  "<<setw(10)<<S.GetSNo()<<"  "<<setw(6)<<S.GetChinese()<<"  "<<setw(6)<<S.GetEnglish()<<"  "<<setw(6)<<S.GetMath()<<"  "<<setw(6)<<S.GetTotal ()<<"  "<<setw(6)<<S.GetAverage ();
	return acout;
}
void main(){
LiskList<Student> Class;
ifstream *infile=new ifstream;//输入文件流
ofstream *ofile=new ofstream;//输出文件流
int i=0;
char sure,b[4]={'Y','y','N','n'};
bool suredoor=false;//确定"门"
Student  temp;
bool ExistData=false;//是否修改数据
char filename[40]="",TXT[5]=".txt";//文件名
char Title[40]="title ";
	char x;//选择字符
	bool quit=false;
	system("title 欢迎使用学生成绩信息管理系统");
	while(!quit){
		cout<<"\n*****************"<<endl;
		cout<<"1.新建文件"<<endl;
		cout<<"2.打开文件"<<endl;
		cout<<"3.保存文件"<<endl;
		cout<<"4.继续当前文件编辑"<<endl;
		cout<<"0.退出"<<endl;
		cout<<"请输入0~4  ";
		cin>>x;
		switch(x){
		case '0':
			quit=true; //退出
			if(ExistData){
				if(strlen(filename))
				   cout<<"文件"<<filename<<"  未保存,是否保存。请输入Y(y)保存,否则输入N(n):  ";
				else cout<<"文件  未命名.txt 未保存,是否保存。请输入Y(y)保存,否则输入N(n):  ";
				do{cin>>sure;
				for(i=0;i<4;i++)
					if(b[i]==sure)  suredoor=true;
					if(suredoor==false)
						cout<<"输入错误,请重新输入 ?_?:  ";
				}while(!suredoor);
			if(IsSure(sure)){
				if(!strlen(filename))  {
			         cout<<"请输入文件名:   ";
		          	  cin>>filename;
					  strcat(filename,TXT);
				}
			ofile->open(filename,ios_base::binary);
			for(i=0;i<Class.ListSize();i++)  
				ofile->write((char *) &Class.Reset(i)->data,sizeof(Class.Reset(i)->data));
			cout<<"保存成功"<<endl;ofile->close();
			}
			else cout<<"取消保存操作"<<endl;
			}
			Class.ClearList();
			break;
		case '1':
			if(ExistData){
				cout<<"文件"<<filename<<"  未保存,是否保存。请输入Y(y)保存,否则输入N(n):  ";
				do{cin>>sure;
				for(i=0;i<4;i++)
					if(b[i]==sure)  suredoor=true;
					if(suredoor==false)
						cout<<"输入错误,请重新输入 ?_?:  ";
				}while(!suredoor);
			if(IsSure(sure)){
				if(!strlen(filename))  {
			         cout<<"请输入文件名:   ";
		          	  cin>>filename;
					  strcat(filename,TXT);
				}
			ofile->open(filename,ios_base::binary);
			for(i=0;i<Class.ListSize();i++)  
				ofile->write((char *) &Class.Reset(i)->data,sizeof(Class.Reset(i)->data));
			ofile->close();
			cout<<"保存成功"<<endl;
			}
			else cout<<"取消保存操作"<<endl;
			}
			system("title 未命名");
			ExistData=true;
			strcpy(filename,"");
			i=0;
			Class.ClearList();
			sonmenu(Class);
			break;
		case '2':
           if(ExistData){
				if(strlen(filename))
				   cout<<"文件"<<filename<<"  未保存,是否保存。请输入Y(y)保存,否则输入N(n):  ";
				else cout<<"文件  未命名.txt 未保存,是否保存。请输入Y(y)保存,否则输入N(n):  ";
				do{cin>>sure;
				for(i=0;i<4;i++)
					if(b[i]==sure)  suredoor=true;
					if(suredoor==false)
						cout<<"输入错误,请重新输入 ?_?:  ";
				}while(!suredoor);
			if(IsSure(sure)){
				if(!strlen(filename))  {
			         cout<<"请输入文件名:   ";
		          	  cin>>filename;
					  strcat(filename,TXT);
				}
			ofile->open(filename,ios_base::binary);
			for(i=0;i<Class.ListSize();i++)  
				ofile->write((char *) &Class.Reset(i)->data,sizeof(Class.Reset(i)->data));
			cout<<"保存成功"<<endl;ofile->close();
			}
			else cout<<"取消保存操作"<<endl;
		   }  
    		ExistData=true;
			strcpy(filename,"");
			i=0;
			Class.ClearList();
			strcpy(filename,"");
			cout<<"请输入文件名:   ";
			cin>>filename;
			strcat(filename,TXT);//strcpy(Title,"");
			strcat(Title,filename);
			system(Title);
			infile->open(filename,ios_base::binary);
			while(infile->good()){
				infile->read((char *)&temp,sizeof(temp));
				Class.InsertFront(temp);	
			}
			infile->close();
			if(!infile)   cout<<"文件不存在"<<endl;
			else {
				sonmenu(Class);
			}
			i=0;
		break;
		case '3':
			if(ExistData==0) cout<<"无数据"<<endl;
			else {
			if(!strlen(filename)){   
		    cout<<"请输入文件名:   ";
			cin>>filename;
			strcat(filename,TXT);
			}
			ofile->open(filename,ios_base::binary);
			strcat(Title,filename);
			system(Title);
			for(i=0;i<Class.ListSize();i++)  
				ofile->write((char *) &Class.Reset(i)->data,sizeof(Class.Reset(i)->data));
			cout<<"文件保存完毕"<<endl;
			ofile->close();
			ExistData=false;
			}
			break;
		case '4':
			if(ExistData||strlen(filename)){
				sonmenu(Class);
			}
			cout<<"数据不存在"<<endl;
		default:
			cout<<"您输错了!!!"<<endl;
			break;
		}
	}
	cout<<"欢迎下次再使用学生成绩信息管理系统^_^,BYE-BYE...."<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -