| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1022 人关注过本帖
标题:[求助]一些c++的问题
取消只看楼主 加入收藏
cl_zdl
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2006-10-11
收藏
 问题点数:0 回复次数:1 
[求助]一些c++的问题

本人由于水平有限,希望大家帮我解决一下,谢谢了!
#include <iostream>
#include<cmath>
using namespace std;
class point {
private:
int x;
int y;
public :point (int a,int b){x=a;y=b;}
int getx(){return x;}
int gety(){return y;}
point (point &m)
{x=m.x;
y=m.y;}
};
class Base
{public: virtual float area(){};
};

class triangle:public Base
{private: point A1,A2,A3;
float area;
public:triangle(point a,point b,point c):A1(a),A2(b)A3(c){}

float area(){int m1=sqrt((A1.x-A2.x)*(A1.x-A2.x)+(A1.y-A2.y)*(A1.y-A2.y));
int m2=sqrt((A1.x-A3.x)*(A1.x-A3.x)+(A1.y-A3.y)*(A1.y-A2.y));
int m3=sqrt((A2.x-A3.x)*(A2.x-A3.x)+(A2.y-A3.y)*(A2.y-A3.y));
int n=(m1+m2+m3)/2;
cout<<"Èý½ÇÐεÄÃæ»ýÊÇ:"<<endl;
return area=sqrt(n*(n-m1)*(n-m2)*(n-m3));

}
};
class rectangle:public Base
{private: point A1,A2;
float area;
public:
rectangle(point a,point b):A1(a),A2(b){}
float area(){int a=A1.x-A2.x;
int b=A1.y-A2.y;
cout <<"¾ØÐεÄÃæ»ýÊÇ:"<<endl;
return area=a*b;
}
};
class circle :public Base
{private: int radius;
float area;
public :
circle(int n){radius=n;}
float area(){
cout <<"Ô²ÐεÄÃæ»ýÊÇ:"<<endl;
return area=3.14*radius*radius;
}
};
void main()
{int *c;
int x1,x2,x3,y1,y2,y3;
for(int i=0;i<20;i++)
{
c=int(rand*2+1);
Base a[20];
switch(c)
{case '1':

{cout<<"ÇëÊäÈëÈý¸öµãµÄ×ø±ê:"<<endl;
cin>>x1;
cin>>x2;
cin>>x3;
cin>>y1;
cin>>y2;
cin>>y3;
point m1(x1,y1),m2(x2,y2),m3(x3,y3);
triangle tr(m1,m2,m3);
a[i]=tr;
break;}
case '2':

{cout<<"ÇëÊäÈëÁ½¸öµãµÄ×ø±ê:"<<endl;
cin>>x1;
cin>>x1;
cin>>y1;
cin>>y2;
point a1(x1,y1),a2(x2,y2);
rectangle rec(a1,a2);
a[i]=rec;
break;}
case '3':
{int m;
cout<<"ÇëÊäÈë°ë¾¶:"<<endl;
cin>>m;
circle cir(m);
a[i]=cir;
break;}
}
}
for( i=0;i<20;i++)
cout <<a[i].area()<<endl;
}

错误调试:
ompiling...
3333.cpp
d:\33333\3333.cpp(24) : error C2040: 'area' : 'float (void)' differs in levels of indirection from 'float'
d:\33333\3333.cpp(38) : error C2040: 'area' : 'float (void)' differs in levels of indirection from 'float'
d:\33333\3333.cpp(49) : error C2040: 'area' : 'float (void)' differs in levels of indirection from 'float'
d:\33333\3333.cpp(59) : error C2296: '*' : illegal, left operand has type 'int (__cdecl *)(void)'
d:\33333\3333.cpp(59) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Ö´ÐÐ cl.exe ʱ³ö´í.

3333.obj - 1 error(s), 0 warning(s)

搜索更多相关主题的帖子: int public class Base include 
2006-10-30 22:18
cl_zdl
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2006-10-11
收藏
得分:0 
乱码是一些输出提示!
2006-10-30 22:19
快速回复:[求助]一些c++的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016982 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved