上机内容:处理成绩
main.cpp
/*
* 程序的版权和版本声明部分
* Copyright (c)2012, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: fun.cpp
* 作 者:黄兆宽
* 完成日期:2013 年 4 月 03 日
* 版本号: v1.0
* 对任务及求解方法的描述部分:处理成绩
* 输入描述:略
* 问题描述:略
* 程序输出:如下
*/
#include <iostream>
#include "Student.h"
using namespace std;
double max(Student *arr); //自定义函数声明
double num1(Student *a);
int m=1; //定义全局变量,保存对应的坐标
double max(Student *arr)
{
int j;
double max=arr[0].seatch2();
for(j=1;j<5;j++)
{
if(arr[j].seatch2()>max)
max=arr[j].seatch2();
m=j;
}
return max; //返回最大成绩
};
double num1(Student *a)
{
return a[m].seatch1(); //返回学号
};
int main(Student *arr)
{
Student p[5]={Student(4301,80),Student(4302,95.5),Student(4303,89),Student(4304,90.5),Student(4305,85.5)};
int i;
for( i=0;i<5;i++)
{
cout<<"第"<<i+1<<"个";
p[i].play();
}
cout<<endl<<"其中最高成绩为:"<<max(p)<<"对应的学号为:"<<num1(p)<<endl;
system("pause");
}
Student.cpp
#include<iostream>
#include "Student.h"
using namespace std;
double Student::seatch1()
{
return num;
}
double Student::seatch2()
{
return score;
}
void Student::play()
{
cout<<"学生的相关信息为:"<<num<<" "<<score<<endl;
}
Student.h
class Student
{
private :
double num;
double score;
public :
Student(double n=100000,double s=100):num(n),score(s){};
void play();
double seatch1();
double seatch2();
};
运行结果: