急!!求C++高手来做几个改错题

来源:百度知道 编辑:UC知道 时间:2024/05/25 03:50:22
都是只改*****found******下一行有错
(3)要求输出结果The value is:10
// proj1.cpp
#include <iostream>
using namespace std;
class Member {
// ERROR ********found********
private:
Member(int val) : value(val) {}
int value;
};

class MyClass {
Member _m;
public:
// ERROR ********found********
MyClass(int val) {}
int GetValue() const { return _m.value; }
};

int main()
{
MyClass *obj = new MyClass(10);
// ERROR ********found******** 下列语句输出obj指向类中的value值
cout << "The value is: " << value << endl;
delete obj;
return 0;
}
(4)要求输出结果
“应发合计:3500 应扣合计:67.5 应发工资:3432.5”
#include<iostream>
using namespace std;

class Salary{
public:
Salary(const char *id, double the_base, double the_bonus, double the_tax)
// ERROR **********found**********
: the_base(base), the_bo

第一个错误:构造函数不能被定义成私用函数,将private改成public就行了,还要增加一个默认构造函数Member(){}。。
第二个错误:MyClass(int val){}改成MyClass(int val){_m.value=val;}
第三个错误:value改成obj->Getvalue();

#include<iostream>
using namespace std;

class Salary{
public:
Salary(const char *id, double the_base, double the_bonus, double the_tax)
// ERROR **********found**********
: base(the_base), bonus(the_bonus), tax(the_tax)
{
staff_id=new char[strlen(id)+1];
strcpy(staff_id,id);
}
// ERROR **********found**********
~Salary(){ delete staff_id; }
double getGrossPay()const{ return base+bonus; } //返回应发项合计
double getNetPay()const{ return getGrossPay()-tax; } //返回实发工资额
private:
char *staff_id; //职工号
double base; //基本工资
double bonus; //奖金
double tax; //代扣个人所得税
};

int main() {
Salary pay("888888", 3000.0, 500.0, 67.50);
cout<<&q