搜档网
当前位置:搜档网 › C++编写经典程序代码之学生管理系统

C++编写经典程序代码之学生管理系统

// Student1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
using std::vector;
class Student
{
public:
string name;
int ID;
public:
void show();
void setname(string name);
void setID(int ID);
string getname();
int getID();

};
string Student::getname()
{
return name;
}
int Student::getID()
{
return ID;
}
void Student::show()
{
cout<<" 名字:"<}
void Student::setID(int ID1)
{
ID=ID1;
}
void Student::setname(string name1)
{
name=name1;
}
int _tmain(int argc, _TCHAR* argv[])
{
vector X;
Student Y;
string name1,name2;
int s;
int ID1,ID2;
int i=0;
string y;
int n;
cout<<"学生信息管理"<cout<<"请选择操作"<begin:
cout<<"1.输入信息 2.查询信息 3.结束"<cout<<"-------------------------------------"<cin>>n;
switch(n)
{
case 1:
{
while(1)
{
Student Y;
cout<<"请输入姓名"<cin>>name1;
Y.setname(name1);
cout<<"请输入学生ID"<cin>>ID1;
Y.setID(ID1);
cout<<"请输入学生性别"<X.push_back(Y);
Y.show();
cout<<"是否还要添加学生资料 Y/N";
cin>>y;
if(y=="N"||y=="n")
goto begin;
}
break;
}
case 2:
{search:
cout<<"1.按姓名索引 2.按学号索引 3.返回"<cout<<"---------------------------------"<cin>>s;
if(s==1)
{
cout<<"输入学生姓名:"<cin>>name2;
for(vector::size_type ix=0;ix!=X.size();ix++ )
{
if(name2==X[ix].getname())
{
X[ix].show();
goto search;
}
}
}
if(s==2)
{
cout<<"输入学生学号:"<cin>>ID2;
for(vector::size_type ix=0;ix!=X.size();ix++ )
{
if(ID2==X[ix].getID())
{
X[ix].show();
goto search;
}
}
}
if(s==3)
goto begin;
if(s!=1&&s!=2&&s!=3)
{
cout<<"输入错误,请重新输入!"<goto search;
}
}
case 3:
{
cout<<"再见"<break;
}
default:
{
cout<<"输入错误!"<goto begin;

}

}
system("pause");
return 0;
}



相关主题