面向对象程序设计大作业------学生信息管理系统学院名称专业班级学生姓名 ____学号指导教师 ___完成时间:年月日学生信息管理系统1.编程目的模仿日常生活中所用的信息管理系统,自行设计一个简单的学生信息管理系统,要求能实现简单的增加,删除,查找学生信息的功能以及能显示学生的基本信息(包括姓名,学号,性别,家庭住址等),在窗口中显示运行结果。
2.系统简介程序正常运行后,屏幕上显示一个文字菜单(根据序号选定相应的操作项目),当用户选定操作项目所对应的序号时,根据应用程序的提示信息,从键盘上输入相应的数据。
应用程序正常运行后,要在屏幕上显示一个文字菜单;要求用户输入数据时,要给出清晰、明确的提示信息。
3.编程思路为各项操作功能设计一个菜单,应用程序运行后,先显示这个菜单,然后用户通过菜单项选择希望进行的操作项目。
4.总体设计为各项操作功能设计一个菜单,应用程序运行后,先显示这个菜单,然后用户通过菜单项选择希望进行的操作项目。
5.关键技术说明将学生信息定义为一个类,采用多文件保存不同的信息数据。
6.源代码#include<iostream>#include<fstream>#include<string>static int N;using namespace std;void add(){int num;string name,politic,address;char sex;ofstream outfile("student1.txt",ios::out);if(!outfile){cerr<<"open file error!";exit(1);} while(1){cout<<" ★请输入学生信息:\n\n\n"<<endl;cout<<" ◆请输入学号:\n"<<endl;cin>>num;if(num==0)break;cout<<" \n ◆请输入姓名:\n"<<endl;cin>>name;cout<<" \n ◆请输入性别:\n"<<endl;cin>>sex;cout<<" \n ◆请输入政治面貌:\n"<<endl; cin>>politic;cout<<" \n ◆请输入家庭住址:\n"<<endl;cin>>address;cout<<"\n";outfile<<num<<" "<<name<<" "<<sex<<" "<<politic<<" "<<address<<endl;N++;}outfile.close();}void change(){int num[200];string name[200],politic[200],address[200];char sex[200];int n;string nam,poli,addr;char s;ifstream infile("student1.txt",ios::in);if(!infile){cerr<<"open file error!";exit(1);}for(int i=0;i<N;i++){infile>>num[i]>>name[i]>>sex[i]>>politic[i]>>address[i] ; }infile.close();ofstream outfile("student1.txt",ios::out);if(!outfile){cerr<<"open file error!";exit(1);}while(1){cout<<" !注意输入学号为0是停止输入!\n"<<endl;cout<<" ★请输入你要修改学生的学号:\n"<<endl;cin>>n;cout<<"\n";if(n==0)break;cout<<"\n ★请输入修改后的姓名:\n"<<endl;cin>>nam;cout<<"\n";cout<<" ★请输入修改后的性别:\n"<<endl;cin>>s;cout<<"\n";cout<<" ★请输入修改后的政治面貌:\n"<<endl;cin>>poli;cout<<"\n";cout<<" ★请输入修改后家庭住址:\n"<<endl;cin>>addr;cout<<"\n";for(int i=0;i<N;i++){if(num[i]==n){name[i]=nam;sex[i]=s;politic[i]=poli;addr ess[i]=addr;}outfile<<num[i]<<" "<<name[i]<<" "<<sex[i]<<""<<politic[i]<<" "<<address[i]<<endl; }outfile.close();cout<<"修改完毕!\n"<<endl;}}void search(){int num[200];string name[200],politic[200],address[200];char sex[200];int n;ifstream infile("student1.txt",ios::in);if(!infile){cerr<<"open file error!";exit(1);}for(int i=0;i<N;i++){infile>>num[i]>>name[i]>>sex[i]>>politic[i]>>address[i] ;}infile.close();while(1){cout<<"请输入按何种方式查找:"<<endl;cout<<"---------------------------------"<<endl;cout<<" | ";cout<<"1.按学号查找 "; cout<<" |"<<endl;cout<<" | ";cout<<"2.按姓名查找 "; cout<<" |"<<endl;cout<<" | ";cout<<"3.按性别查找 "; cout<<" |"<<endl;cout<<" | ";cout<<"4.按政治面貌查找";cout<<" |"<<endl;cout<<" | ";cout<<"5.按家庭住址查找";cout<<" |"<<endl;cout<<" | ";cout<<"6.返回主菜单 "; cout<<" |"<<endl;cout<<" | ";cout<<"0.退出查找 "; cout<<" |"<<endl;cout<<"---------------------------------\n\n"<<endl;cin>>n;cout<<"\n";if(n==6)break;switch(n){case 1:while(1){cout<<"请输入你要查找的学号(输入0返回查找方式):"<<endl;cin>>num[199];if(num[199]==0)break;for(int i=0;i<N;i++){if(num[i]==num[199]){cout<<"查找结果为:"<<endl;cout<<"学号姓名性别政治面貌家庭住址"<<endl;cout<<num[i]<<" "<<name[i]<<" "<<sex[i]<<" "<<politic[i]<<" "<<""<<address[i]<<endl<<endl;}}cout<<"查找完毕!\n"<<endl;}break;case 2:while(1){cout<<"请输入你要查找的姓名(输入0返回查找方式):"<<endl;cin>>name[199];if(name[199]=="0")break;for(int i=0;i<N;i++){if(name[i]==name[199]){cout<<"查找结果为:"<<endl;cout<<"学号姓名性别政治面貌家庭住址"<<endl;cout<<num[i]<<" "<<name[i]<<" "<<sex[i]<<" "<<politic[i]<<" "<<""<<address[i]<<endl<<endl;}}cout<<"查找完毕!\n"<<endl;};break;case 3:while(1){cout<<"请输入你要查找的性别(输入0返回查找方式):"<<endl;cin>>sex[199];if(sex[199]=='0')break;for(int i=0;i<N;i++){if(sex[i]==sex[199]){cout<<"查找结果为:"<<endl;cout<<"学号姓名性别政治面貌家庭住址"<<endl;cout<<num[i]<<" "<<name[i]<<" "<<sex[i]<<" "<<politic[i]<<" "<<""<<address[i]<<endl<<endl;}}cout<<"查找完毕!\n"<<endl;}break;case 4:while(1){cout<<"请输入你要查找的政治面貌(输入0返回查找方式):"<<endl;cin>>politic[199];if(politic[199]=="0")break;for(int i=0;i<N;i++){if(politic[i]==politic[199]){cout<<"查找结果为:"<<endl;cout<<"学号姓名性别政治面貌家庭住址"<<endl;cout<<num[i]<<" "<<name[i]<<" "<<sex[i]<<" "<<politic[i]<<" "<<""<<address[i]<<endl<<endl;}}cout<<"查找完毕!\n"<<endl;}break;case 5:while(1){cout<<"请输入你要查找的家庭住址(输入0返回查找方式):"<<endl;cin>>address[199];if(address[199]=="0")break;for(int i=0;i<N;i++){if(address[i]==address[199]){cout<<"查找结果为:"<<endl;cout<<"学号姓名性别政治面貌家庭住址"<<endl;cout<<num[i]<<" "<<name[i]<<" "<<sex[i]<<" "<<politic[i]<<" "<<""<<address[i]<<endl<<endl;}}cout<<"查找完毕!\n"<<endl;}break;default:cout<<"输入错误!\n"<<endl;break;}}}void del(){int num[200],n;string name[200],politic[200],address[200];char sex[200];ifstream infile("student1.txt",ios::in);if(!infile){cerr<<"open file error!";exit(1);}cout<<" 学号姓名性别政治面貌家庭住址"<<endl;for(int i=0;i<N;i++){infile>>num[i]>>name[i]>>sex[i]>>politic[i]>>address[i];cout<<" "<<num[i]<< " "<<name[i]<<" "<<sex[i]<<" "<<politic[i]<<" "<<""<<address[i]<<endl<<endl;}infile.close();ofstream outfile("student1.txt",ios::out);if(!outfile){cerr<<"open file error!";exit(1);}while(1){cout<<"\n\n!注意输入学号为0是停止删除!\n"<<endl;cout<<"★请输入你要删除学生的学号:"<<endl;cin>>n;if(n==0)break;for(int i=0;i<N;i++){if(num[i]!=n)outfile<<num[i]<<" "<<name[i]<<""<<sex[i]<<" "<<politic[i]<<" "<<address[i]<<endl;}cout<<"删除完毕!"<<endl;N--;}outfile.close();}void show(){ int num;string name,politic,address;char sex;ifstream infile("student1.txt",ios::in);if(!infile){cerr<<"open file error!";exit(1);}cout<<"学号姓名性别政治面貌家庭住址"<<endl;for(int i=0;i<N;i++){infile>>num>>name>>sex>>politic>>address;cout<<num<<" "<<name<<" "<<sex<<" "<<politic<<" "<<address<<endl<<endl;}}int main(){int n;while(1){cout<<"---------------------------------"<<endl;cout<<" | ";cout<<"1.增加学生记录~";cout<<" |"<<endl;cout<<" | ";cout<<"2.删除学生记录~";cout<<" |"<<endl;cout<<" | ";cout<<"3.修改学生记录~";cout<<" |"<<endl;cout<<" | ";cout<<"4.查找学生记录~";cout<<" |"<<endl;cout<<" | ";cout<<"5.显示学生记录~";cout<<" |"<<endl;cout<<" |";cout<<"(注意:输入学号为0时退出输入!)";cout<<"|"<<endl;cout<<"---------------------------------\n\n"<<endl;cout<<" ☆请选择:\n"<<endl;cin>>n;cout<<"\n";if(n==0)break;switch(n){case 1:add();break;case 2:del();break;case 3:change();break;case 4:search();break;case 5:show();break;default:break;}}}7.测试(主界面及各功能模块的运行图及说明)一:主界面二:增加学生记录:三:删除学生记录:四:修改学生记录:五:查找学生记录:六:显示学生记录8.系统评价及展望系统能实现简单的增加,删除,修改,查找学生信息,但是如果不按要求输入的时候可能会出现系统崩溃,得不到运行结果。