C++ 指出下面程序段中的错误并改正
#include<iostream.h>classshape{public:intarea(){return0;}};classrectangle:publicshape...
#include<iostream.h>
class shape{
public:
int area () {return 0;}
};
class rectangle:public shape{
public:
int a, b;
void setlenth (int x,inty){a=x;b=y}
int area () {return a*b;}};
void main() {
rectangle r;
r.setlength (3,5);
shape *s=r;
cout<<r.area () <<endl;
cout <<s.area () <<endl:
} 展开
class shape{
public:
int area () {return 0;}
};
class rectangle:public shape{
public:
int a, b;
void setlenth (int x,inty){a=x;b=y}
int area () {return a*b;}};
void main() {
rectangle r;
r.setlength (3,5);
shape *s=r;
cout<<r.area () <<endl;
cout <<s.area () <<endl:
} 展开
展开全部
又是考眼力的题,是有意考大家还是为啥呢?你在编译器里编译一下错误就都出来了啊,10来个错误吧,改完后是这样的
class shape{
public:
int area () {return 0;}
};
class rectangle:public shape{
public:
int a, b;
void setlength (int x,int y){a=x;b=y;}
int area () {return a*b;}};
void main() {
rectangle r;
r.setlength (3,5);
shape *s=&r;
cout<<r.area () <<endl;
cout <<s->area () <<endl;
}
class shape{
public:
int area () {return 0;}
};
class rectangle:public shape{
public:
int a, b;
void setlength (int x,int y){a=x;b=y;}
int area () {return a*b;}};
void main() {
rectangle r;
r.setlength (3,5);
shape *s=&r;
cout<<r.area () <<endl;
cout <<s->area () <<endl;
}
展开全部
程序 改完了,主要是 一些小错误,如:代码打错了等。
#include<iostream.h>
class shape
{
public:
int area ()
{return 0;}
};
class rectangle:public shape
{
public:
int a, b;
void setlength (int x,int y)
{a=x;b=y;}
int area ()
{return a*b;}
};
void main()
{
rectangle r;
r.setlength (3,5);
shape *s=&r;
cout<<r.area () <<endl;
cout <<s->area () <<endl;
}
#include<iostream.h>
class shape
{
public:
int area ()
{return 0;}
};
class rectangle:public shape
{
public:
int a, b;
void setlength (int x,int y)
{a=x;b=y;}
int area ()
{return a*b;}
};
void main()
{
rectangle r;
r.setlength (3,5);
shape *s=&r;
cout<<r.area () <<endl;
cout <<s->area () <<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |