|
|
发表于 2021-9-6 18:21:35
|
显示全部楼层
本帖最后由 jhq999 于 2021-9-6 18:49 编辑
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct Student
- {
- char studentName[24];
- int score;
- };
- struct Team
- {
- char teacher[24];
- struct Student std[3];
- };
- void getinfo(struct Team *p, int len)
- {
- int i, j;
- for (i = 0; i < len; i++)
- {
- cout << "请输入指导老师的姓名: ";
- cin >> p[i].teacher;
- for (j = 0; j < 3; j++)
- {
- cout << "学生"<<j+1<<endl;
- cout << "姓名: ";
- cin >> p[i].std[j].studentName;
- cout << "分数: ";
- cin >> p[i].std[j].score;
- }
- cout << endl;
- }
- cout << endl;
- cout << "--------信息录入完毕!--------" << endl;
- cout << endl;
- }
- void print(struct Team *p, int len)
- {
- int i, j;
- for (i = 0; i < len; i++)
- {
- cout << "指导老师: ";
- cout << p[i].teacher<<endl;
- for (j = 0; j < 3; j++)
- {
- cout << "学生" << j+1 << endl;
- cout << "姓名:";
- cout << p[i].std[j].studentName<<"----";
- cout << "分数:";
- cout << p[i].std[j].score <<endl;
- }
- cout << endl;
- }
- }
- int main(void)
- {
- int len;
- struct Team team[3];//只给个菜单不上菜怎么行?或者 struct Team* team=new struct Team[3];后面别忘了delete的好习惯
- len = sizeof(team) / sizeof(team[0]);
- getinfo(team, len);
- print(team, len);
- system("pause");
- return 0;
- }
复制代码 |
|