123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include <iostream>
- #include <ctime>
- #if(0)
- struct Student
- {
- std::string SName;
- int score;
- };
- struct Teacher
- {
- std::string TName;
- struct Student SArray[5];
- };
- void allocateSpace(struct Teacher TArray[] , int len)
- {
- std::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++)
- {
- std::cout << "老师姓名:" << TArray[i].TName << std::endl;
- for (int j = 0; j < 5; j++)
- {
- std::cout << "\t学生姓名:" << TArray[i].SArray[j].SName << "考试分数:" << TArray[i].SArray[j].score << std::endl;
- }
- }
- }
- int main()
- {
-
- srand((unsigned int)time(NULL));
-
- struct Teacher TArray[3];
-
- int len = sizeof(TArray) / sizeof(TArray[0]);
- allocateSpace(TArray, len);
-
- printInfo(TArray, len);
- system("pause");
- return 0;
- }
- #endif
|