#include<iostream>
#include "ctime"
using namespace std;
struct Student {
string sname;
int score;
};
struct Teacher {
string tname;
struct Student sArray[5];
};
void allocate(struct Teacher tArray[] ,int len) {
string nameSeed = "ABCDE";
for (int i = 0; i < len; i++) {
tArray[i].tname = "Teacher_";
tArray[i].tname += nameSeed[i];
for (int j = 0; j < 5;j++) {
tArray[i].sArray[j].sname = "Student_";
tArray[i].sArray[j].sname += nameSeed[j];
int random = rand() % 61 + 40;
tArray[i].sArray[j].score = random;
}
}
}
void printInfo(struct Teacher tArray[], int len) {
for (int i = 0; i < len; i++) {
cout << "教师姓名:" << tArray[i].tname << endl;
for (int j = 0; j < 5; j++) {
cout << "\t带教学生:" << tArray[i].sArray[j].sname;
cout << "\t学生成绩:" << tArray[i].sArray[j].score << endl;
}
}
}
int main(){
srand((unsigned int)time(NULL));
struct Teacher tArray[3];
int len = sizeof(tArray) / sizeof(tArray[0]);
allocate(tArray,len);
printInfo(tArray,len);
system("pause");
return 0;
}
运行结果: