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

📄 test.cpp

📁 学生信息管理系统 姓名 年龄 性别 学号 成绩
💻 CPP
字号:
#include <iostream>
#include "linkstudent.h"
#include "student.h"
#include "liststudent.h"
#include "mainmenu.h"
#include "findmenu.h"
const static NAME = 40;
const static SNO = 20;
using namespace std;

int main()
{	
	//创建学生信息
	Student stu[6] = {
			Student("shen","1004",21,'m'),
			Student("chen","1003",22,'m'),
			Student("jiang","1002",23,'m'),
			Student("zhou","1001",22,'m'),
			Student("fan","1000",22,'m'),
			Student("qian","1005",22,'f')
	};
	//添加学生成绩
	stu[0].set_pfm(80,90,73);
	stu[1].set_pfm(75,69,63);
	stu[2].set_pfm(90,96,84);
	stu[3].set_pfm(76,80,84);
	stu[4].set_pfm(60,74,88);
	stu[5].set_pfm(78,88,98);
	Liststudent list;//学生链表

	//添加学生信息到链表
	for(int i = 0; i < 5; i++)
		list.insert(stu[i]);
	list.append(stu[5]);

	//进入主菜单循环
	while(true )
	{
		m_menu();//显示主菜单
		char option; //主菜单选项
		cout << "Enter your choice(q to quit):";
		cin >> option;
		if (option == 'q')
			break;			//退出主程序
		switch(option)
		{
////////////////////当选查看学生信息的操作////////////////
			case '1':
				
				{	
																									
					while(true)
					{	
						mfindstu();
						char op;
						cout << "Enter your choice(q to 上一层):";
						cin >> op;
						if('q' == op)
							break;
						cin.get();
						if(op == '1')
							list.show_all();
						else if('2' == op)
						{	
							char na[NAME];
							cout << "\n请输入待查学生姓名(quit to quit):";
							cin.getline(na,NAME);
							
							while(strcmp(na,"quit"))
							{
								Linkstudent * t = list.find_n(na);
								if(t != NULL)
								t->stu.showall();	
							else cout<<" \nthere isn't the student!"<<endl;
							cin.clear();
							cin.sync();
							cout << "请输入待查学生姓名(quit to quit):" << endl;
							cin>>na;
							cin.get();
							}//end while
 
						}//end if
						else if('3' == op)
						{
							char snu[20];
							cout << "请输入待查学生学号:";
							cin>>snu;
							cin.get();
							while(strcmp(snu,"quit"))
							{
								Linkstudent * t = list.find_sn(snu);
							if(t != NULL)
								t->stu.showall();
								
							else cout<<" there isn't the student!"<<endl;
							cin.clear();
							cin.sync();
							cout << "Enter quit to quit:";
							cin>>snu;
							cin.get();
							}
						}//endif			
					} //end while
				}   //end case 1

				break;								
/////////////////////修改学生信息的操作////////////////////////////	    
			case '2':
				{
				cin.get();
				char modify_sn[SNO];
				list.show_all();
				cout << endl << endl;
				cout << "请输入所修改学生学号:";
				
				cin.getline(modify_sn,SNO);
				Linkstudent *modify_st = list.find_sn( modify_sn );
				if(modify_st)
				{

					cout << "所修改学生信息为:" << endl;
					modify_st->stu.showall();
					cout << endl << endl;
					cout << "请选择所修改信息:" << endl << endl;
					cout << "1 学号\t2 姓名\t3 性别\t4 年龄\t5 语文\t6 数学\t7 英语"<<endl<<endl;
					cout << "(q to quit)!:";
					
					while(true)
					{
						char modify_op;
						cin >> modify_op;
						
						if('q' == modify_op)
							break;
						//while(cin && cin.get() != '\n')
							//continue;

						switch(modify_op)
						{
						case '1':
							{

								char modi_sn[SNO];
								cin.get();
								cout << "请输入新学号:";
								cin.getline(modi_sn,SNO);
								modify_st->stu.set_sn(modi_sn);
								cout << "修改后学生信息为:\n";
								modify_st->stu.showall();
								cout << endl << endl;
								
							}break;

						case '2':
							{
								char modi_n[NAME];
								cin.get();
								cout << "请输入新姓名:";
								cin.getline(modi_n,NAME);
								modify_st->stu.set_name(modi_n);
								cout <<endl;
								cout << "修改后学生信息为:\n";
								modify_st->stu.showall();
								cout << endl;

							}break;
						case '3':
							{
								
								
								while(true)
								{
									cin.get();
									cout << "请输入新性别(f or m):";
									char modi_s;
									cin >> modi_s;
									if(modi_s == 'f' || modi_s == 'm')
									{
										cout << endl;
										modify_st->stu.set_sex(modi_s);
										cout << "修改后学生信息为:\n";
										modify_st->stu.showall();
										cout << endl << endl;
										break;
									}

								}//end while

							}break; //end case '3'
						case '4':
							{
								while(true)
								{
									cin.get();
									cout << "请输入新年龄(2 to 98):";
									int modi_a;
									cin >> modi_a;
									if(modi_a >= 2 && modi_a <=98)
									{
										modify_st->stu.set_age(modi_a);
										break;
									}
								}// end while
							}break;//end case '4'
						case '5':
							{
								while(true)
								{
									cin.get();
									cout << "请输入新语文成绩(0 to 100):";
									int modi_y;
									cin >> modi_y;
									if(modi_y >= 0 && modi_y <=100)
									{
										modify_st->stu.set_yuwen(modi_y);
										break;
									}
								}// end while
							}break;//end case '5'
						case '6':
							{
								while(true)
								{
									cin.get();
									cout << "请输入新数学成绩(0 to 100):";
									int modi_m;
									cin >> modi_m;
									if(modi_m >= 0 && modi_m <=100)
									{
										modify_st->stu.set_math(modi_m);
										break;
									}
								}// end while
							}break;//end case '6'
						case '7':
							{
								while(true)
								{
									cin.get();
									cout << "请输入新英语成绩(0 to 100):";
									int modi_e;
									cin >> modi_e;
									if(modi_e >= 0 && modi_e <=100)
									{
										modify_st->stu.set_english(modi_e);
										break;
									}
								}// end while
							}break;//end case '7'
						}//end switch
						cout << "请选择所修改信息:" << endl;
						cout << "1 学号\t2 姓名\t3 性别\t4 年龄\t5 语文\t6 数学\t7 英语"<<endl;
						cout << "(q to quit)!:";

					}// end while
				}//end if
				}//end case 2
				break;
/////////////////////////添加学生信息的操作////////////////////////////
			case '3':
				{ 
					char insert_sn[SNO];
					char insert_n[NAME];
					int   insert_a;
					char   insert_s;
					int	  insert_y = 0;
					int   insert_m = 0;
					int   insert_e = 0;
					while(cin && cin.get() != '\n')
					cin.get();
					cout << "请输入学号:" ;
					cin.getline(insert_sn,SNO);

					while( list.find_sn(insert_sn) )
					{
						cout << "该学号已存在,请重新输入:";
						cin.getline(insert_sn,SNO);
					}
					
					cout << "请输入姓名:";
					cin.clear();
					cin.sync();
					cin.getline(insert_n,NAME);
					cout << "请输入年龄:";
					cin >> insert_a;
					
					while(insert_a < 2 || insert_a > 98)
					{
						cout << "该年龄无效,请重新输入:";
						    cin.clear();
							cin.sync();
						cin >> insert_a;
					}
					cout << "请输入性别(M or F):";
					cin >> insert_s;
					while(insert_s != 'f' && insert_s != 'm')
					{
						cout << "再仔细想一下你的性别吧(M or F):";
							cin.clear();
							cin.sync();
						cin >> insert_s;
					}
					char answer;
					cout << "要输入分数么?(Y or N)";
					cin >> answer;
					while(true)
					{
						if( answer == 'y')
						{
							cin.clear();
							cin.sync();
							cout << "请输入语文分数(0~~~100):";
							cin >> insert_y;
							while(insert_y < 0  || insert_y > 100)
							{

								cout << "靠,有这样的分数么,重输!(0~~~100):";
								cin.clear();
								cin.sync();
								cin >> insert_y;
							}

							cout << "请输入数学分数(0~~~100):";
							cin >> insert_m;
							while(insert_m < 0  || insert_m > 100)
							{
								cout << "靠,有这样的分数么,重输!(0~~~100):";
								cin.clear();
								cin.sync();
								cin >> insert_m;
							}

							cout << "请输入英语分数(0~~~100):";
							cin >> insert_e;
							
							while(insert_e < 0  || insert_e > 100)
								
							{
								
								
								cout << "靠,有这样的分数么,重输!(0~~~100):";
								cin.clear();
								cin.sync();
								cin >> insert_e;

							}
							break;
						}//endif
						else if( answer == 'n')
						{
							cin.clear();
							cin.sync();
							break;
						}
						cout << "y or n:";
						cin.clear();
						cin.sync();
						cin >> answer;
					}//end while
					Student insert_stu(insert_n,insert_sn,insert_a,insert_s,insert_y,insert_m,insert_e);
					list.insert(insert_stu);
					cout << "所添加学生信息是:" << endl;
					insert_stu.showall();	
				}  //end case 3

				break;
////////////////////////删除学生信息的操作////////////////////////////
			case '4':
				{
					cin.get();
					int dele_op;
					cout << "1 按学号删除:" << endl;
					cout << "2 按姓名删除:" << endl;
					cin >> dele_op;
					if(dele_op == 1)//按照学号删除学生信息
					{
						char dele_sn[SNO];
						cout << "请输入待删学号:";
						cin.get();
						cin.getline(dele_sn,SNO);
						Linkstudent * t = list.find_sn(dele_sn);
						if( t )
						{
							cout << "该学生信息为:"<<endl;
							t->stu.showall();
							char dele_an;
							cout << "确定要删除么?(y or n)";
							cin >> dele_an;
							while(true)
							{
								if(dele_an == 'y')
								{
									list.remvoe_sn(dele_sn);
									break;
								}
								else if(dele_an == 'n')
									break;
								else
								{
									cout << "确定要删除么?(y or n)";
									cin >> dele_an;
								}

							}//endwhile


						}//endif
						else
							cout << "没有该学生!"<<endl;
							
					}//endif
					if(2 == dele_op)// 按照姓名删除学生信息
						{
						char dele_n[NAME];
						cout << "请输入待删姓名:";
						cin.get();
						cin.getline(dele_n,NAME);
						Linkstudent * t = list.find_n(dele_n);
						if( t )
						{
							cout << "该学生信息为:"<<endl;
							t->stu.showall();
							char dele_an;
							cout << "确定要删除么?(y or n)";
							cin >> dele_an;
							while(true)
							{
								if(dele_an == 'y')
								{
									list.remove_n(dele_n);
									break;
								}
								else if(dele_an == 'n')
									break;
								else
								{
									cout << "确定要删除么?(y or n)";
									cin >> dele_an;
								}

							}//endwhile

						}//endif
						else
							cout << "没有该学生!" << endl;							
					}//endif

					
				}//end case 4
				break;
				
			}//end switch
		
	}//end while	
	cout << "Bye~~~~" << endl;		
	return 0;
}

⌨️ 快捷键说明

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