3.定义一个学生类,内有数据成员(学号、姓名、成绩),定义一个对象数组,设立一个函数max,用指向对象的指针作为函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。
(1)定义一个学生类,内有数据成员(学号、姓名、成绩),有update函数、display函数,可实现数据成员设置、显示;
(2)定义无参数的构造函数和带参数的构造函数Student(string xh,string name,float sc);
(3)定义一个对象数组stu[5],求出成绩最好者的学号、姓名。
这个应该具体从哪个地方开始思考,怎样才是正确的写法呀(语言-c++)
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 浪客 2022-03-23 17:11关注
大概这样子
#include <iostream> #include <string> using namespace std; class Student { private: string xh, name; float sc; public: void update(); void display(); float getsc(); Student(string xh, string name, float sc); Student() { xh = name = "", sc = 0; }; }; Student::Student(string xh, string name, float sc) { this->xh = xh; this->name = name; this->sc = sc; } void Student::update() { cin >> xh >> name >> sc; } void Student::display() { cout << xh << "\t" << name << endl; } float Student::getsc() { return sc; } void max(Student *stu) { float max = 0; int index = 0; for (int i = 0; i < 5; i++) { if (max < (stu + i)->getsc()) { max = (stu + i)->getsc(); index = i; } } (stu + index)->display(); } int main() { Student stu[5]; for (int i = 0; i < 5; i++) { stu[i].update(); } max(stu); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用
悬赏问题
- ¥30 深度学习,前后端连接
- ¥15 孟德尔随机化结果不一致
- ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
- ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
- ¥15 谁有desed数据集呀
- ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
- ¥15 关于#hadoop#的问题
- ¥15 (标签-Python|关键词-socket)
- ¥15 keil里为什么main.c定义的函数在it.c调用不了
- ¥50 切换TabTip键盘的输入法