急!急!求C++高手帮做几道改错题 20

都是只改*****found******下一行(1)要求输出结果p1=(8,4)p2=(3,5)#include<iostream>#include<cmath>usin... 都是只改*****found******下一行
(1)要求输出结果p1=(8,4) p2=(3,5)
#include<iostream>
#include<cmath>
using namespace std;

class Point{
double x,y;
public:
Point(double x=0.0, double y=0.0)
// ERROR **********found**********
{ x=x; y=y;}
double getX()const{ return x; }
double getY()const { return y; }
// ERROR **********found**********
void show()const{ cout<<'('<<x<<','<<y<<')' }
};

class Line{
Point p1,p2;
public:
Line(Point pt1, Point pt2)
// ERROR **********found**********
{ pt1=p1; pt2=p2; }
Point getP1()const{ return p1; }
Point getP2()const{ return p2; }
};

int main(){
Line line(Point(8,4), Point(3,5));
cout<<"p1=";
line.getP1().show();
cout<<"p2=";
line.getP2().show();
cout<<endl;
return 0;
}
(2)要求输出结果this object is no.1
//proj1.cpp
#include <iostream>
using namespace std;
class MyClass
{
public:
MyClass():count(0) { cout<<"This object is "; }
// ERROR ********found********
void Inc() const
{ cout<<"no. "<<++count<<endl; }
private:
// ERROR ********found********
int count=0;
};

int main()
{
MyClass *obj=new MyClass;
// ERROR ********found********
*obj.Inc();
return 0;
}
展开
 我来答
Lcisware
2008-09-19 · TA获得超过619个赞
知道小有建树答主
回答量:846
采纳率:50%
帮助的人:373万
展开全部
this.x=x;this.y=y;
漏';'
p1=pt1;p2=pt2;
去掉const
int cout;不能在类声明中初始化变量,可以初始化常量,不过也要看编译器。
obj->Inc();或(*obj).Inc();
zzz2003526
2008-09-19 · TA获得超过411个赞
知道答主
回答量:215
采纳率:0%
帮助的人:235万
展开全部
自己仔细看吧,有好几处错误。
调试后的程序均按照楼主要求输出了!
第一个程序修正如下:
#include<iostream>
#include<cmath>
using namespace std;

class Point{

public:
double x,y; //最好放在public或者private里面来
Point(){}//必须要有默认的构造函数,否则会在Line构造函数报错
Point(double x, double y)
// ERROR **********found**********
{ this->x=x; this->y=y;}
double getX()const{ return x; }
double getY()const { return y; }
// ERROR **********found**********
void show()const{ cout<<'('<<x<<','<<y<<')' ;}
};

class Line{

public:
Point p1,p2; //道理同上
Line(Point pt1, Point pt2)
// ERROR **********found**********
{ this->p1=pt1; this->p2=pt2; }
Point getP1()const{ return p1; }
Point getP2()const{ return p2; }
};

int main(){
Line line(Point(8,4), Point(3,5));
cout<<"p1=";
line.getP1().show();
cout<<"p2=";
line.getP2().show();
cout<<endl;
return 0;
}
第二个程序修正如下:
#include <iostream>
using namespace std;
class MyClass
{
public:
MyClass():count(0) { cout<<"This object is "; }
// ERROR ********found********
void Inc()
{ cout<<"no. "<<++count<<endl; }
private:
// ERROR ********found********
int count;
};

int main()
{
MyClass *obj=new MyClass;
// ERROR ********found********
obj->Inc(); //指针必须采用指向操作符访问。
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式