#include<iostream>
using namespace std;
#include<string>
#include<ctime>
//老师结构体嵌套学生结构体,三个老师分别带五个学生
//学生的结构体
struct Student
{
//姓名
string sName;
//分数
int score;
};
//老师的结构体定义
struct Teacher
{
//姓名
string tName;
//学生数组
struct Student sArray[5];
};
//给老师和学生赋值的函数
void allocateSpace(struct Teacher tArray[],int len)
{
string nameSeed = "ABCDE";
//给老师开始赋值
for (int i = 0; i < len; i++)
{
tArray[i].tName = "T_";
tArray[i].tName += nameSeed[i];
//通过循环给每名老师所带的学生赋值
for (int j = 0; j < 5; j++)
{
tArray[i].sArray[j].sName = "S_";
tArray[i].sArray[j].sName += nameSeed[i];
int random = rand() % 61 + 40;//40~100
tArray[i].sArray[j].score = random;
}
}
}
//打印所有信息
void printInfo(struct Teacher tArray[], int len)
{
for (int i = 0; i < len; i++)
{
cout << "老师姓名: " << tArray[i].t
C++_结构体(结构体嵌套)_(利用结构体中的属性进行排序)
最新推荐文章于 2024-05-30 18:06:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)