#include
using namespace std;
#include
//学生的结构体
struct student
{
string sName;
int score;
};
//老师的结构体定义
struct Teacher
{
string tName;
//学生
struct Student sArray[5];
};
//给老师和学生赋值
void allocateSpace(struct Tecaher 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.sName = "Student_";
tArray[i].sArray[j].sName += nameSeed[j];
tArray[i].sArray[j].score = 60;
}
}
}
//打印信息
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 << "学生姓名:" << tArray[i].sArray[j].sName << "考试分数:" << tArray[i].sArray[j].score << endl;
}
}
}
int main() {
//创建三名老师的数组
struct Teacher tArray[3];
//赋值
int len = sizeof(tArray) / sizeof(tArray[0]);
allocateSpace(tArray,len);
//打印信息
printInfo(tArray, len);
system("pause");
return 0;
}