c++的STL的list实现简单的学生管理系统(数据没保存在文件中)

#include<iostream>
#include<list>
#include<string> 
#include<cstdlib>
using namespace std;
//使用list(双向链表)容器对象实现简单的学生管理系统 
//list简单使用 

class Student{    //学生基本信息结构 
	public:
		string num; //学号 
		string name;  //姓名 
		string sex;  //性别 
		int age; 	//年龄 
		
};

int main()
{
	Student stu;
	list<Student> L;
	list<Student>::iterator pos;
	char ch;
	cout<<"\t\t\t\t\t**********学生信息管理系统********"<<endl;
	while(1){
		cout<<"\t\t\t\t\t\t1.追加学生信息"<<endl;
		cout<<"\t\t\t\t\t\t2.删除最后一个学生的信息"<<endl;
		cout<<"\t\t\t\t\t\t3.显示学生信息"<<endl;
		cout<<"\t\t\t\t\t\t4.删除所有学生信息"<<endl;
		cout<<"\t\t\t\t\t\t5.统计学生个数"<<endl;
		cout<<"\t\t\t\t\t\t0.退出"<<endl;
		cout<<"\t\t\t\t\t请输入操作序号:";
		cin>>ch;
		switch(ch){
			case '1':{
				system("cls");
				cout<<"\t\t\t\t\t************追加学生信息的界面************"<<endl;
				Student s;
				int n;
				cout<<"\t\t\t\t\t\t请输入要追加的学生个数:";
				cin>>n;
				if(n>0){
					cout<<"\t\t\t\t\t学号,学生姓名,学生性别,学生年龄:\n";
				}
				for(int i=0;i<n;i++){	
					cout<<"\t\t\t\t\t";
					cin>>s.num>>s.name>>s.sex>>s.age; 
					L.push_back(s);
				}
				cout<<"\t\t\t\t\t";
				system("pause");
				system("cls");
				break;
			}
			case '2':{
				system("cls");
				cout<<"\t\t\t\t*********删除最后一个学生的信息界面************"<<endl;
				if(!L.empty()){
					L.pop_back();
					cout<<"\t\t\t\t\t删除成功!"<<endl;
				}else{
					cout<<"\t\t\t\t\t数据库为空!"<<endl; 
				}
				cout<<"\t\t\t\t";
				system("pause");
				system("cls");
				break;
			}
			case '3':{
				system("cls");
				cout<<"\t\t\t\t\t*********显示学生信息的界面*********"<<endl;
				if(L.empty()){
					cout<<"\t\t\t\t数据库为空,无法显示!"<<endl;
				}else{
					int i=1;
					for(list<Student>::iterator it=L.begin();it!=L.end();it++,i++){
						cout<<"\t\t\t"<<i<<". 学号:"<<(*it).num<<"\t"<<"学生姓名:"<<(*it).name<<"\t\t"<<"学生性别:"<<(*it).sex<<"\t\t"<<"学生年龄:"<<(*it).age<<endl;
					}
				} 
				cout<<"\t\t\t";
				system("pause");
				system("cls");
				break;
			}
			case '4':{
				system("cls");
				cout<<"\t\t\t\t*********删除所有学生信息的界面*********"<<endl;
				if(L.empty()){
					cout<<"\t\t\t\t\t数据库为空!"<<endl;
				} else{
					L.clear();
					cout<<"\t\t\t\t\t删除成功!"<<endl; 
				}
				cout<<"\t\t\t\t";
				system("pause");
				system("cls");
				break;
			}
			case '5':{
				system("cls");
				cout<<"\t\t\t\t*********统计学生人数界面********"<<endl;
				cout<<"\t\t\t\t\t学生总人数为:"<<L.size()<<endl;
				cout<<"\t\t\t\t";
				system("pause");
				system("cls");
				break;
			}
			case '0':{ 
				cout<<"\t\t\t\t\t是否退出?(y是,n不是):";
				cin>>ch;
				switch(ch){
					case 'y':{
						exit(0);
						break;
					}
					case 'n':{
						system("cls");
						break;
					}
				} 
				break;
			}
		} 
	}
	return 0;
}

  

posted @ 2021-02-16 23:28  nanfengnan  阅读(80)  评论(0编辑  收藏  举报