定义一个学生类,其中有3个数据成员学号、姓名、成绩,以及若干成员函数实现对学生数据的赋值和输出
在主函数中定义一个对象数组,完成对数组中每个对象的赋值。定义一个函数找出成绩最高的学生的学号和姓名,该函数的形式参数为对象指针...
在主函数中定义一个对象数组,完成对数组中每个对象的赋值。定义一个函数找出成绩最高的学生的学号和姓名,该函数的形式参数为对象指针
展开
1个回答
展开全部
#include<iostream>
#include<string>
using namespace std;
class student{
private:
int xuehao;
string xingming;
int nianling;
public:
student(int XUEHAO,string XINGMING,int NIANLING)
{
xuehao=XUEHAO;xingming=XINGMING;nianling=NIANLING;
cout<<"学号:"<<xuehao<<"姓名:"<<xingming<<"年龄:"<<nianling<<endl;
}
~student()
{
cout<<"学号:"<<xuehao<<"姓名:"<<xingming<<"年龄:"<<nianling<<endl;
}
};
int main()
{
student s1(1542,"jializhu",54);
student s2(2553,"jialiniu",65);
student s3(2154,"jialigou",48);
return 0;
}
#include<string>
using namespace std;
class student{
private:
int xuehao;
string xingming;
int nianling;
public:
student(int XUEHAO,string XINGMING,int NIANLING)
{
xuehao=XUEHAO;xingming=XINGMING;nianling=NIANLING;
cout<<"学号:"<<xuehao<<"姓名:"<<xingming<<"年龄:"<<nianling<<endl;
}
~student()
{
cout<<"学号:"<<xuehao<<"姓名:"<<xingming<<"年龄:"<<nianling<<endl;
}
};
int main()
{
student s1(1542,"jializhu",54);
student s2(2553,"jialiniu",65);
student s3(2154,"jialigou",48);
return 0;
}
追问
怎么没对象数组和对象指针的应用啊??
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询