• [置顶] 第五周项目四:学生类


    // gdgd.cpp : 定义控制台应用程序的入口点。
    //
    /*  
    * 程序的版权和版本声明部分  
    * Copyright (c)2013, 烟台大学计算机学院学生  
    * All rightsreserved.  
    * 文件名称: object.cpp  
    * 作者:李蒙  
    * 完成日期: 2013年  4  月 5日  
    * 版本号: v1.0  
    * 输入描述:无  
    * 问题描述:学生类  
    * 程序输出:  
    */  
    #include "stdafx.h"
    #include <iostream>
    using namespace std;  
    class Student  
    {  
    public:  
        Student(int n,double s):num(n),score(s){}  
        void display();  
        int getNum(){return num;}  
        double getScore(){return score;}  
    private:  
        int num;  
    	double score;  
    };  
    
    void Student::display()  
    {  
        cout<<num<<" "<<score<<endl;  
    }  
    
    int max(Student *arr);  
    
    int main()  
    {  
        Student stud[5]={  
            Student(01,90),Student(02,88),Student(03,100),  
    		Student(04,95),Student(05,99)};  
            for(int i=0;i<5;i+=2)  
            {  
                cout<<"学生"<<i+1<<": ";  
                stud[i].display();  
            }  
            cout<<"5个学生中成绩最高者的学号为: "<<max(stud)<<endl;;  
            return 0;  
    }  
    
    int max(Student *arr)//用私有成员函数调用   
    {      int k; 
    double max_score=arr[0].getScore(); 
    for(int i=1;i<5;i++) 
    if(arr[i].getScore()>max_score)   
    {  
    	max_score=arr[i].getScore();  
    	k=i;
    }  
    return arr[k].getNum();
    }  
    
    


    输出结果:

  • 相关阅读:
    ajax
    cookie
    JavaScript基本语法
    HTML css 格式布局
    HTML 表单
    html 一般标签 常用标签 表格
    WinForm——操作word文档
    WinForm进程 线程
    音乐
    注册 传值
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3000823.html
Copyright © 2020-2023  润新知