#include<iostream>
using namespace std;
#include<string>
#include<ctime>
struct student {
string sName;
int score;
};
struct teacher {
string tName;
struct student sArray[5];
};
void allowcatespace(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(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
<<" 成绩:" <<tArray[i].sArray[j].score<< endl;
}
}
}
int main() {
srand((unsigned int)time(NULL));
struct teacher tArray[3];
int len = sizeof(tArray) / sizeof(tArray[0]);
allowcatespace(tArray, len);
printinfo(tArray, len);
return 0;
}
结构体案例1
最新推荐文章于 2024-06-13 14:18:54 发布