哪位C++高手帮忙做一下,感谢了可以发到我的邮箱:liujun4503@163.com改的地方最好用不同颜色区别,再次感谢

1以下程序有什么错误?如有请予以修改.(1)使用静态成员函数.#include<iostream.h>#include<string.h>classperson{publ... 1以下程序有什么错误?如有请予以修改.
(1)使用静态成员函数.
#include<iostream.h>
#include<string.h>
class person{
public:
char m_strName[20];
long m_ID;
public:
person (char * strName,long ID){strcpy(m_strName,strName);m_ID=ID;}
};
void main()
{
person personl(”liujun”,1101640524);
cout<<”ID=”<<person::getID()<<'\n';
}
(2).派生类的构造函数调用基类的构造函数.
#include<iostream.h>
class point
{
protected:
int x,y;
public:
point(int a,int b){x=a,y=b;}
int getX(){ return x;}
int getY(){ return y;}
};
class circle:public point
{
protected:
int radius;
public:
Circle(int a=0,int b=0,int r=0){radius=r;}
int getRadius(){radius;}
};
void main()
{
Circle c(100,150,200);
cout<<"X="<<c.getX()<<",y="<<c.getY()<<",radius="<<c.getRadius()<<endl;}
(3),关于常对象和常对象成员.
#include<iostream.h>
class Sample
{
private:
int n;
public:
sample(int x){n=x;}
void setValue(int x){n=x;}
void Display(){cout<<"n="<<n<<endl;}
};
void main()
{
const Sample a(100);
a.SetValue(0);
a.Display();
}
2.指出以下程序中的错误,并加以修改
#include<iostream.h>
class A

protected:
int a;
public:
void setData(int x){a=x;}
int GetData() {return a;}
};
class B
{
protected:
int b;
public:
void SetData(int y){b=y;}
int GetData(){return b;}
};
class C: public A,public B
{
public:
void SetData(int x,int y){a=x;b=y}
};
void main()
{
C c;
c.SetData(30,70);
cout<<"a="<<c.GetData()<<",b="<<c.GetData()<<endl;
}
展开
 我来答
hbjzzt
推荐于2016-07-22 · TA获得超过476个赞
知道小有建树答主
回答量:245
采纳率:0%
帮助的人:269万
展开全部
(1)
#include<iostream.h>
#include<string.h>
class person{
public:
char m_strName[20];
long m_ID;
public:
person (char * strName,long ID)
{
strcpy(m_strName,strName);
m_ID=ID;
}
};
void main()
{
//修改的两条
//---------------------------------------------
person personl("liujun",1101640524);
cout<<"ID="<<personl.m_ID<<'\n';
//---------------------------------------------
}

(2)
//---------------------------------------------
//#号修改
#include<iostream.h>
//---------------------------------------------
class point
{
protected:
int x,y;
public:
point(int a,int b)
{
x=a,y=b;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
};
//---------------------------------------------
//Circle的c大写
class Circle:public point
//---------------------------------------------
{
protected:
int radius;
public:
//---------------------------------------------
//加: point(a,b)
Circle(int a=0,int b=0,int r=0) : point(a,b)
//---------------------------------------------
{
point(a,b);
radius=r;
}
int getRadius()
{
//---------------------------------------------
//加return
return radius;
//---------------------------------------------
}
};
void main()
{
Circle c(100,150,200);
cout<<"X="<<c.getX()<<",y="<<c.getY()<<",radius="<<c.getRadius()<<endl;
}

(3)
//---------------------------------------------
//修改#
#include<iostream.h>
//---------------------------------------------
class Sample
{
private:
int n;
public:
//---------------------------------------------
//以下两条s大写
Sample(int x){n=x;}
void SetValue(int x){n=x;}
//---------------------------------------------
void Display(){cout<<"n="<<n<<endl;}
};
void main()
{
const Sample a(100);
//---------------------------------------------
//修改
Sample *pa=const_cast<Sample*>(&a);
pa->SetValue(10);
pa->Display();
//---------------------------------------------
}

(4)
//---------------------------------------------
//修改#
#include<iostream.h>
class A
//修改{
{
//---------------------------------------------
protected:
int a;
public:
void setData(int x){a=x;}
int GetData() {return a;}
};
class B
{
protected:
int b;
public:
//---------------------------------------------
//修改;
void SetData(int y){b=y;}
//---------------------------------------------
int GetData(){return b;}
};
class C: public A,public B
{
public:
//---------------------------------------------
//y后加;
void SetData(int x,int y){a=x;b=y;}
//---------------------------------------------
};
void main()
{
C c;
c.SetData(30,70);
//---------------------------------------------
//修改
cout<<"a="<<c.A::GetData()<<",b="<<c.B::GetData()<<endl;
//---------------------------------------------
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式