Chapter9——建立一个对象数组,内放5个学生的数据(学号,成绩),用指针指向数组首元素,输出第1,3,5学生的数据。

xiaoxiao2021-02-28  123

#include<iostream> #include<string> using namespace std; class student { public: student(string ="blank",float =0); void display(); private: string number; float grade; }; student::student(string num,float g) { number=num; grade=g; } void student::display() { cout<<number<<":"<<grade<<endl; } int main() { student person[]={ student("M2017001",87), student("M2017002",90), student("M2017003",80), student("M2017004",97), student("M2017005",93), }; student *p1=person; p1->display(); (p1+2)->display(); (p1+4)->display(); return 0; }
转载请注明原文地址: https://www.6miu.com/read-70138.html

最新回复(0)