一、结构体案例
#include<iostream>
#include<stdio.h>
#include<ctime>
using namespace std;
struct student
{
string name;
int score
};
struct teacher
{
string name;
struct student stu[5];
};
void printinfo(struct teacher tea,int len)
{
for (int i = 0; i < len; i++)
{
cout <<"老师的姓名:"<< tea[i].name << endl;
for (int j = 0; j < 5; j++)
{
cout <<"\t学生的姓名:"<< tea[i].stu[j].name << " 分数:" << tea[i].stu[j].score << endl;
}
}
}
void allocateSpace(struct teacher tea[],int len)
{
string nameSeed = "ABCDE";
for (int i = 0; i < len; i++)
{
tea[i].name = "teacher_";
tea[i].name += nameSeed[i]
for (int j = 0; j < 5; j++)
{
tea[i].stu[j].name = "student_";
tea[i].stu[j].name += nameSeed[j];
int random = rand % 61 + 40;
tea[i].stu[j].score = radom
}
}
}
int main()
{
srand((unsigned int)time(NULL));
struct teacher tea[3];
int len = sizeof(tea)/sizeof(tae[0]);
allocateSpace(tea,len);
printinfo(struct teacher tea,int len)
return 0;
}