1 #include<iostream>
2 #include<string>
3 using namespace std;
4
5
6 struct Student
7 {
8 int s_id;
9 string s_name;
10 int s_phonenum;
11 };
12
13 struct Teacher
14 {
15 int m_id;
16 string m_name;
17 Student m_stu;//班长
18 Student starr[50];//班级学生
19 };
20 void showinfo1(const Teacher *ter)//指针形参,加了const修饰指针,保证该函数不修改实参的值
21 {
22 cout << "老师姓名: " << ter->m_name << endl;
23 cout << "班级1号学生的电话: " << ter->starr[0].s_phonenum << endl;
24 }
25
26 void showinfo2( Teacher &ter)//引用传参
27 {
28 cout << "老师姓名: " << ter.m_name << endl;
29 cout << "班级1号学生的电话: " << ter.starr[0].s_phonenum << endl;
30 }
31
32 int main()
33 {
34 Student stu = { 1,"zhangsan",1467888 };
35 Student syuarr[3] =
36 {
37 {2,"2hao同学",12222222},
38 {3,"3#tongxue",1333333},
39 {4,"4#tongxue",1444443}
40 };
41
42 Teacher ter;
43 ter.m_id = 12;
44 ter.m_name = "wang";
45 ter.m_stu = stu;
46 ter.starr[0] = syuarr[1];
47
48 showinfo1(&ter);
49 showinfo2(ter);
50
51 system("pause");
52 return 0;
53 }