第五周C++上机报告(对象数组处理成绩)

来源:互联网 发布:iconkit windows 编辑:程序博客网 时间:2024/05/20 13:39
/** 程序的版权和版本声明部分* Copyright (c)2012, 烟台大学计算机学院学生* All rightsreserved.* 文件名称: object.cpp* 作者:王昕彤* 完成日期: 2013年  4  月1  日* 版本号: v1.0* 输入描述:无* 问题描述:建立包含学生信息的对象数组,处理学生成绩* 程序输出:无*/#include<iostream>using namespace std;class Student{public:Student(int n=1001,float s=60):num(n),score(s){}void show();int num;float score;};void Student::show(){cout<<num<<"     "<<score<<endl;}void max(Student *arr){float max=arr[0].score;int a=0,i;for(i=0;i<5;i++)if(arr[i].score>max)  {  max=arr[i].score;  a=i;  }  cout<<"最高分的学号为:"<<arr[a].num<<"  "<<"成绩是"<<max<<endl;}int main(){Student stu[5]={Student(1001,99),Student(1003,70),Student(1004,87),Student(1007,98.5),Student(1010,80.5)};stu[0].show();stu[2].show();stu[4].show();void max(Student*);Student *p=&stu[0];max(p);    return 0;}


输出结果: