永发信息网

C++程序输出

答案:1  悬赏:0  手机版
解决时间 2021-04-13 02:23
  • 提问者网友:疯孩纸
  • 2021-04-12 13:18

#include<iostream>
using namespace std;
class woman
{
public:
void get_stature();
void get_age();
void get_bust();
void get_weight(){cout<<weight;}
void set_stature(float x);
void set_age(int y);
void set_bust(float a);
void set_weight(int b)
private:
float stature();
int age();
float bust();
int weigh()t;
};
void woman::get_stature()
{
cout<<stature;
}
void woman::set_stature(float x)
{
stature=x;
}
void woman::get_age()
{
cout<<age;
}
void woman::set_age(int y)
{
age=y;
}
void woman::get_bust()
{
cout<<bust;
}
void woman::set_bust(float a)
{
bust=a;
}
void main()
{
woman xh;
xh.set_stature(1.65);
cout<<"小红身高的:";
xh.get_stature();
cout<<endl;
xh.set_age(27);
cout<<"小红的年龄: ";
xh.get_age();
cout<<endl;
xh.set_bust(33);
cout<<"小红的胸围: ";
xh.get_bust();
cout<<endl;
xh.set_weight(51);
cout<<"小红的体重: ";
xh.get_weight();

}

不能通过编译,请高手帮我修改下。

最佳答案
  • 五星知识达人网友:春色三分
  • 2021-04-12 14:42

#include<iostream>
using namespace std;
class woman
{
public:
void get_stature();
void get_age();
void get_bust();
void get_weight(){cout<<weight;}
void set_stature(float x);
void set_age(int y);
void set_bust(float a);
void set_weight(int b){weight=b;}
private:
float stature;
int age;
float bust;
int weight;
};
void woman::get_stature()
{
cout<<stature;
}
void woman::set_stature(float x)
{
stature=x;
}
void woman::get_age()
{
cout<<age;
}
void woman::set_age(int y)
{
age=y;
}
void woman::get_bust()
{
cout<<bust;
}
void woman::set_bust(float a)
{
bust=a;
}
void main()
{
woman xh;
xh.set_stature(1.65);
cout<<"小红身高的:";
xh.get_stature();
cout<<endl;
xh.set_age(27);
cout<<"小红的年龄: ";
xh.get_age();
cout<<endl;
xh.set_bust(33);
cout<<"小红的胸围: ";
xh.get_bust();
cout<<endl;
xh.set_weight(51);
cout<<"小红的体重: ";
xh.get_weight();


}


修改该了。错误1:void set_weight(int b) 你没有{weight=b;}


错误2:private:
float stature();
int age();
float bust();
int weigh();


这样写是错误的 后面的括号不能要 因为在private中是私有数据不是函数。我开始也犯这样的错,多练习就好了。

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯