赞
踩
一个班有n个学生,需要把每个学生的简单材料(姓名和学号)输入计算机保存。然后可以通过输入某一学生的姓名查找其有关资料。当输入一个姓名后,程序就查找该班中有无此学生,如果有,则输出他的姓名和学号,如果查不到,则输出“本班无此人”。
- #include <iostream>
- using namespace std;
- #include <string>
- int main()
- {
- bool w = 0;
- int n, str_num, i, m=0;
- string s[99], ss;
- cout << "输入一共有多少个学生:" << endl;
- cin >> n;
- int num[99];
- for (i = 0; i < n; i++)
- {
- cout << "输入学生姓名:" << endl;
- cin >> s[i];
- cout << "输入学生学号:" << endl;
- cin >> num[i];
- }
- cout << "输入想查询的学生的学号:" << endl;
- cin >> str_num;
- for (i = 0; i < n; i++)
- {
- if (str_num != num[i])
- {
- w = 1;
- }
- else
- {
- m = num[i];
- ss = s[i];
- w = 0;
- }
- }
- if (!w)
- {
- cout << "本班无此人" << endl;
- }
- else
- {
- cout << "该学生的姓名是:" << ss << endl;
- cout << "该学生的学号是:" << m << endl;
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。