第四章作业:4.17:建立一个对象数组,内放6个学生的数据(学号,成绩),用指针向数组首元素,输出第2,4,6个学生的数据。

来源:互联网 发布:淘宝网装饰腰带 编辑:程序博客网 时间:2024/06/04 10:19


#include<iostream> 

#include<string> 

using namespace std; 

class student  { 

public: 

     void show1(); 

       student (string a,double b) 

   {   score=b; 

       name=a; 

    } 

    private: 

        string name; 

       double score; 

}; 

   void student:: show1() 

   { 

    cout<<name<<"   "<<score<<endl; 

    void show(student q) 

    q.show1(); 

}     

int main() 

    student stu[6]={student("小明",67),student("小红",88),student("小芳",70),student("小俊",100), 

        student("小兰",79),student("小军",98)}; 

    for(int i=1;i<6;i+=2) 

    { 

        show(stu[i]); 

    }      return 0; 



0 0