# 哪错了？？？

travelerl 2017-11-05 04:01:44
#include <iostream>
#include <windows.h>
using namespace std;
const double PI = 3.14159;
const float Stockade_cost = 35; //每米的栅栏价格
const float Passage_cost = 20; //过道价格
class cal
{
public:
cal(float r); //构造函数
float perimeter ; //栅栏长度
float area ; //过道面积
private:
float R; //半径
}
cal::cal(float r)
{
R = r;
}
float cal::perimeter
{return 2 * PI * R; }
float cal::area const
{return PI * R * R;}
int main()
{
float R;
float Passage_cost;
cout << "输入半径：";
cin >> R;
cal pool(R);
cal maxpool(R + 3);
cout << "栅栏造价:" << Stockade_cost << endl;
Passage_cost = (maxpool.area() - pool.area())*Passage_cost;
cout << "过道造价：" << Passage_cost << endl;
system("pause");
return 0;
}
...全文
160 7 打赏 收藏 举报

7 条回复

``````#include <iostream>
//#include <windows.h>
using namespace std;

const double PI = 3.14159;
const float Stockade_cost = 35;  //每米的栅栏价格
const float Passage_cost = 20;   //过道价格

class cal
{
public:
cal(float r);       //构造函数
float perimeter() ;   //栅栏长度
float area() const ;        //过道面积
private:
float R;            //半径
};

cal::cal(float r)
{
R = r;
}

float cal::perimeter()
{
return 2 * PI * R;
}

float cal::area()const
{
return PI * R * R;
}

int main()
{
float R;
float Passage_cost;
cout << "输入半径：";
cin >> R;
cal pool(R);
cal maxpool(R + 3);
cout << "栅栏造价:" << Stockade_cost << endl;
Passage_cost = (maxpool.area() - pool.area())*Passage_cost;
cout << "过道造价：" << Passage_cost << endl;
//system("pause");
return 0;
}
``````

``````   float Stockade_cost;
float Passage_cost;``````

• 打赏
• 举报

• 打赏
• 举报

destory27 2017-11-07
class cal { }; float cal::perimeter（） {return 2 * PI * R; } float cal::area（） const {return PI * R * R;}
• 打赏
• 举报

tomyalonso 2017-11-07
perimeter是函数吧？应该写成perimeter（），还有area也一样，类的声明最后的｝后面要加分号；
• 打赏
• 举报

FoolCarpe 2017-11-05
``````float cal::perimeter
{return 2 * PI * R; }
float cal::area const
{return PI * R * R;}``````

• 打赏
• 举报

das白 2017-11-05

• 打赏
• 举报

6.1w+

C++ 语言相关问题讨论，技术干货分享，前沿动态等

2017-11-05 04:01