C++编程作业:简单的学生管理系统

一、问题描述

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: koalazb
 */
#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);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值