一个C++小程序老调不好

来源:百度知道 编辑:UC知道 时间:2024/06/11 14:23:04
#include<iostream>
#include<cmath>
using namespace std;
class Right_Angled_Triangle //声明类
{ private: //以下为私有部分
float right_a;
float right_b;
float hypotenuse;
public: //以下为公有部分
void set_rights()
{cout<<"input right_a and right_b:";
cin>>right_a;
cin>>right_b;
}
void out_hypotenuse() //定义公共函数out_hypotenuse()
{hypotenuse=sqrt(right_a* right_a+right_b* right_b);
cout<<"hypotenuse="<<hypotenuse<<endl;
};
};
Right_Angled_Triangle triangle1,triangle2; //定义Right_Angled_Triangle的两个变量int main()
{ triangle1.set_rights();

triangle2.out_hypotenuse();
return 0;
}
输入一个Rt三角形的两条直角边长,计算并输出斜边长。

改了一下,错误的地方标出来了,你对比一下就知道了
#include<iostream>
#include<cmath>
using namespace std;
class Right_Angled_Triangle //声明类
{
private: //以下为私有部分
float right_a;
float right_b;
float hypotenuse;
public: //以下为公有部分
void set_rights()
{
cout<<"input right_a and right_b:";
cin>>right_a;
cin>>right_b;
}
void out_hypotenuse() //定义公共函数out_hypotenuse()
{
hypotenuse=sqrt(right_a* right_a+right_b* right_b);
cout<<"hypotenuse="<<hypotenuse<<endl;
} //你的这地方多了个分号
};
int main()//你的缺了这一行。
{//这个左大括号是从下面提上来的。当然,下面的两个变量也可以定义到main()前面。
Right_Angled_Triangle triangle1,triangle2; //定义Right_Angled_Triangle的两个变量int main()

triangle1.set_rights();

triangle2.out_hypotenuse();
return 0;
}

也不说明具体什么问题,仍一堆代码算什么意思呢

你想调出什么来