基于QT完成以下功能,完成代码并添加详细的注释文档 (1)建立学生数据结构体,结构含有姓名、学号、性别和年龄信息。 (2)建立一个结构数组放置10个学生信息。 (3)设计一个函数,实现输入10个学生的基本信息。 (4)编写一个函数,实现显示10个学生的基本信息。
时间: 2024-04-17 17:22:57 浏览: 19
Sure! Here's the code with detailed comments:
```cpp
#include <iostream>
#include <string>
// 定义学生数据结构体
struct Student {
std::string name;
std::string id;
std::string gender;
int age;
};
// 输入10个学生的基本信息
void inputStudentInfo(Student students[]) {
for (int i = 0; i < 10; i++) {
std::cout << "请输入第" << i+1 << "个学生的姓名: ";
std::cin >> students[i].name;
std::cout << "请输入第" << i+1 << "个学生的学号: ";
std::cin >> students[i].id;
std::cout << "请输入第" << i+1 << "个学生的性别: ";
std::cin >> students[i].gender;
std::cout << "请输入第" << i+1 << "个学生的年龄: ";
std::cin >> students[i].age;
std::cout << std::endl;
}
}
// 显示10个学生的基本信息
void displayStudentInfo(const Student students[]) {
for (int i = 0; i < 10; i++) {
std::cout << "第" << i+1 << "个学生的姓名: " << students[i].name << std::endl;
std::cout << "第" << i+1 << "个学生的学号: " << students[i].id << std::endl;
std::cout << "第" << i+1 << "个学生的性别: " << students[i].gender << std::endl;
std::cout << "第" << i+1 << "个学生的年龄: " << students[i].age << std::endl;
std::cout << std::endl;
}
}
int main() {
// 建立一个结构数组放置10个学生信息
Student students[10];
// 输入10个学生的基本信息
inputStudentInfo(students);
// 显示10个学生的基本信息
displayStudentInfo(students);
return 0;
}
```
这段代码实现了你所描述的功能,主要包括建立学生数据结构体,输入和显示10个学生的基本信息。通过调用 `inputStudentInfo` 函数,用户可以输入每个学生的姓名、学号、性别和年龄信息。然后,通过调用 `displayStudentInfo` 函数,程序会显示出每个学生的基本信息。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)