简单的学生管理系统##
题目为:
Design a program which can implement the following functions:
Get the student information data, which includes name, ID, age and so on, from the standard input stream;
Output these information into the standard output stream according to the specific student’s id.
- vector are recommended as the data type for the container of student information.
/*
* student.cpp
*
* Created on: 2015-9-25
* Author:
*/
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string> stu_name;//定义string类型的vector容器 存放学生姓名
vector<int> stu_id;//存放学生ID
vector<int> stu_age;//存放学生年龄
void Info_input(void);//函数 录入学生信息
void Info_output(void);//函数 输出学生信息
int main()
{
int select=0;
do
{
Info_input();
Info_output();
cout<<"----------Enter 1 to close the project, 2 to continue the project.----------"<<endl;
cin>>select;
}
while(select!=1);
cout<<"-------------Hoping to see you again------------"<<endl;
return 0;
}
void Info_input()
{
int id=0,age=0;
string name;
cout<<"----------Enter the number of students----------"<<endl;
int count=0;
cin>>count;
cout<<"-------Enter the students' name,ID and age-------"<<endl;
int i=1;
for(i=1;i<=count;i++)
{
cout<<"-----------------Enter the "<<i<<" 'student's Info.-----------------"<<endl;
cout<<"Student's Name:"<<endl;
cin>>name;
cout<<"Student's ID:"<<endl;
cin>>id;
cout<<"Student's Age:"<<endl;
cin>>age;
//将姓名、ID、年龄分别压入各个vector的末尾
stu_name.push_back(name);
stu_id.push_back(id);
stu_age.push_back(age);
}
}
void Info_output(void)
{
int seek;
int key=2;
int flag=0;
do
{
cout<<"---------Enter the student's ID you want to looking for:---------"<<endl;
cin>>seek;
vector<string>::iterator i=stu_name.begin();
vector<int>::iterator j=stu_age.begin();
vector<int>::iterator k=stu_id.begin();
for(;k!=stu_id.end();i++,j++,k++)
{
//*k取当前下标的vector中的值
if(seek==*k)
{
cout <<"-------------------The student is found!-----------------"<<endl;
cout <<"Name: "<< *i << "\n"
<<"Age: "<<*j << "\n"
<<"Student ID:"<<*k <<endl;
flag=1;
break;
}
else
{
flag=0;
continue;
}
}
if(flag==0)
cout<<"---------- Sorry, not founded "<<seek<<" ----------"<<endl;
cout<<"----------Enter 1 to continue,2 to break."<<"----------"<<endl;
cin>>key;
}while(key!=2);
}