哪错了???

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 Stockade_cost;
float Passage_cost;
cout << "输入半径:";
cin >> R;
cal pool(R);
cal maxpool(R + 3);
Stockade_cost = maxpool.perimeter()*Stockade_cost;
cout << "栅栏造价:" << Stockade_cost << endl;
Passage_cost = (maxpool.area() - pool.area())*Passage_cost;
cout << "过道造价:" << Passage_cost << endl;
system("pause");
return 0;
}
...全文
203 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2017-11-07
  • 打赏
  • 举报
回复
#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 Stockade_cost;
    float Passage_cost;
    cout << "输入半径:";
    cin >> R;
    cal pool(R);
    cal maxpool(R + 3);
    Stockade_cost = maxpool.perimeter()*Stockade_cost;
    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;
这两个变量没有初始化,将会是随机值
赵4老师 2017-11-07
  • 打赏
  • 举报
回复
偶遇到类似问题都是用 “每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。” 的方法解决的。
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;}
错了,声明在哪儿? 函数括号了?
大米粥哥哥 2017-11-05
  • 打赏
  • 举报
回复
类}后面少个 ;

64,685

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧