#include<iostream>
using namespace std;
#include<string>
//学生结构体定义
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 = "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]";
tArray[i].sArray[j].score = 60;
}
}
}
void printfInfor(struct teacher tArray[], int len)
{
for (int i = 0; i < len; i++)
{
cout << "老师的姓名: " << tArray[i].tName[i]<<endl;
//int j;
for (int j = 0; j < 5;j++)
{
cout << "学生的姓名: " << tArray[i].sArray[j].sName <<
"考试的分数: " << tArray[i].sArray[j].score << endl;
}
}
}
int main()
{
//1、创建3名老师的数组
struct teacher tArray[3];
//2、通过函数给三名老师赋值,并给老师的学生赋值
int len = sizeof(tArray) / sizeof(tArray[0]);
allocateSpace(tArray,len);
//3、打印所有老师及所带学生的信息
printfInfor(tArray,len);
system("pause");
return 0;
}
全部评论
(1) 回帖