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

来源:互联网 发布:帅气警花走红网络 编辑:程序博客网 时间:2024/05/23 11:32
#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;
}
0 0
原创粉丝点击