C++第三章课后作业答案及解析---指针的使用
今天继续完成上周没有完成的习题---C++第三章课后作业,本章题涉及指针的使用,有指向对象的指针做函数参数,对象的引用以及友元类的使用方法等 它们具体的使用方法在下面的题目中会有具体的解析(解析标注在代码中)。 题目: 1.建立一个对象数组,内放5个学生数据(学号,成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。 1 #include <iostream> 2 #include<stdlib.h> 3 using namespace std; 4 class Student 5 {public: 6 //定义学生数据函数 7 Student(int n,float s):num(n),score(s){} 8 int num; 9 float score; 10 }; 11 12 void main() 13 { 14 //构建五个学生数据信息 15 Student stud[5]={ 16 Student(101,78.5),Student(102,85.5),Student(103,98.5), 17 Student(104,100.0),Student(105,95.5)}; 18 void max(Student* );//定义max函数 19 Student *p=&stud[0];//p指向数组第一个元素