#include <iostream>
using namespace std;
#include<string>
typedef struct student {
string name;
int score;
}stu;
typedef struct teacher {
string name;
struct student a[5];
}tea;
void SetInit(tea t[], int length) {
srand((unsigned int)time(NULL));
string s = "ABCDE";
string name = "teacher_";
string name1 = "student_";
for (int i = 0; i < length; i++) {
//生成老师的名字
t[i].name = name + s[i];
for (int j = 0; j < 5; j++) {
int num = rand() % 100;
//生成学生的名字
t[i].a[j].name = name1 + s[j];
//生成学生的成绩
t[i].a[j].score = num;
}
}
}
void Get(tea t[], int length) {
for (int i = 0; i < length; i++) {
for (int j = 0; j < 5; j++) {
cout << t[i].name << "的学生" << t[i].a[j].name << "考到了" << t[i].a[j].score << "分" << endl;
}
}
}
int main() {
tea t[3];
int length = end(t) - begin(t);
SetInit(t, length);
Get(t, length);
return 0;
}
结构体嵌套结构体
于 2023-04-19 13:16:09 首次发布