c++的编程题,求解,急!!!
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
1个回答
展开全部
1、最低限度符合要求。
2、通过VS2012测试编译无误,显示无误。
3、代码如下:
#include<iostream>
#include<math.h>//ex2
#include<string>//ex3
using namespace std;
//ex2
class Point
{
int x;
int y;
public:
Point(){x=0;y=0;}
Point(int vecX, int vecY):x(vecX),y(vecY){}
int getX(){return x;}
int getY(){return y;}
};
class Line:public Point
{
Point point1;
Point point2;
public:
Line(Point p1,Point p2):point1(p1),point2(p2){}
double getLength()
{
return sqrt(pow((point1.getX()-point2.getX()),2)+pow((point1.getY()-point2.getY()),2));
}
};
//ex3
class Dog
{
protected:
string breed;
double height;
double weight;
string color;
public:
Dog(string br, double h, double w,string clr)
{
breed = br;
height = h;
weight = w;
color = clr;
}
void show_breed()
{
cout << breed << endl;
}
};
class spotted_dog:public Dog
{
string spotClr;
public:
spotted_dog(string br, double h, double w,string clr,string spot):Dog(br,h,w,clr),spotClr(spot){}
void spot_info()
{
cout << spotClr << endl;
}
};
class unspotted_dog:public Dog
{
public:
unspotted_dog(string br,double h, double w,string clr):Dog(br,h,w,clr){}
};
int main()
{
//ex2 simple
Line line1(Point(3,2),Point(2,6));
cout << "Line1's length is:" << line1.getLength() << "." << endl;
//ex3 simple
spotted_dog redSpot("Dalmatian",24,60,"white","red");
unspotted_dog rover("Labrador Retriever",30,40,"yellow");
redSpot.show_breed();
redSpot.spot_info();
rover.show_breed();
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |