编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩教师数据有编号、姓名、职称和部门。要求将编号、姓名的输入和显示设计成
时间: 2023-05-31 19:05:44 浏览: 129
编写一个学生和教师数据输入和显示程序
函数,班号、成绩、职称、部门可以直接在主函数中输入和显示。
以下是示例代码:
```c++
#include <iostream>
#include <string>
using namespace std;
struct Student {
int id;
string name;
int classNum;
double score;
};
struct Teacher {
int id;
string name;
string title;
string department;
};
void inputIdAndName(int& id, string& name) {
cout << "请输入编号:";
cin >> id;
cout << "请输入姓名:";
cin >> name;
}
void displayIdAndName(int id, string name) {
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
}
int main() {
Student stu;
Teacher tea;
// 输入学生数据
cout << "请输入学生数据:" << endl;
inputIdAndName(stu.id, stu.name);
cout << "请输入班号:";
cin >> stu.classNum;
cout << "请输入成绩:";
cin >> stu.score;
// 显示学生数据
cout << "学生数据:" << endl;
displayIdAndName(stu.id, stu.name);
cout << "班号:" << stu.classNum << endl;
cout << "成绩:" << stu.score << endl;
// 输入教师数据
cout << "请输入教师数据:" << endl;
inputIdAndName(tea.id, tea.name);
cout << "请输入职称:";
cin >> tea.title;
cout << "请输入部门:";
cin >> tea.department;
// 显示教师数据
cout << "教师数据:" << endl;
displayIdAndName(tea.id, tea.name);
cout << "职称:" << tea.title << endl;
cout << "部门:" << tea.department << endl;
return 0;
}
```
阅读全文