c++编程。(1)定义父类point,包含x和y两个坐标属性
急,在线等。(1)定义父类point,包含x和y两个坐标属性,并定义带两参数的构造函数和输出x和y的show函数;(20分)(2)定义point的公有继承派生类circl...
急,在线等。
(1)定义父类point,包含x和y两个坐标属性,并定义带两参数的构造函数和输出x和y的show函数;(20分)
(2)定义point的公有继承派生类circle,包含半径r一个属性,并定义带三参数的构造函数(其中两参传递给父类)和输出三个属性x,y,r的show函数(要求调用父类的show输出x和 y)。(25分)
(3)主函数测试circle类的构造和输出。(5分) 展开
(1)定义父类point,包含x和y两个坐标属性,并定义带两参数的构造函数和输出x和y的show函数;(20分)
(2)定义point的公有继承派生类circle,包含半径r一个属性,并定义带三参数的构造函数(其中两参传递给父类)和输出三个属性x,y,r的show函数(要求调用父类的show输出x和 y)。(25分)
(3)主函数测试circle类的构造和输出。(5分) 展开
3个回答
展开全部
#include <iostream>
using namespace std;
class point{
public:
point( double x = 0.0, double y = 0.0 ){
m_x = x;
m_y = y;
}
void show(){
cout << "x = " << m_x << "," << "y = " << m_y << endl;
}
private:
double m_x;
double m_y;
};
class circle : public point{
public:
circle( double r, double x = 0.0, double y = 0.0)
: point( x, y){
m_r = r;
}
void show(){
point::show();
cout << "r = " << m_r << endl;
}
private:
double m_r;
};
int main()
{
circle dc(100,20,30);
dc.show();
return 0;
}
2017-06-06
展开全部
Point类public class Point{private float x;private float y;public Point(float x,float y){this.x = x;this.y = y;}public float getX() {return x;}public void setX(float x) {this.x = x;}public float getY() {return y;}public void setY(float y) {this.y = y;}public float distanceToOrigin(){return (float) Math.sqrt(Math.pow(this.x, 2)+Math.pow(this.y, 2));}public float distanceToOther(int x, int y){return (float) Math.sqrt(Math.pow(this.x-x, 2)+Math.pow(this.y-y, 2));}public float distanceToOther(Point point){return (float) Math.sqrt(Math.pow(this.x-point.x, 2)+Math.pow(this.y-point.y, 2));}}测试类public class TestPoint{public static void main(String[] args) {Point p1 = new Point(3, 5);Point p2 = new Point(7, 8);System.out.println(p1.distanceToOrigin());System.out.println(p2.distanceToOrigin());System.out.println(p1.distanceToOther(20,30));System.out.println(p2.distanceToOther(20,30));System.out.println(p1.distanceToOther(p2));}}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Point<T> {
private T x;
private T y;
public Point(T x, T y) {
this.x = x;
this.y = y;
}
public T getX() {
return x;
}
public void setX(T x) {
this.x = x;
}
public T getY() {
return y;
}
public void setY(T y) {
this.y = y;
}
public void outPut(Point<T> p){
System.out.println("点的x坐标为:"+p.getX());
System.out.println("点的y坐标为:"+p.getY());
}
public static void main(String[] args) {
Point<Integer> p=new Point<Integer>(1,2);
p.outPut(p);
Point<Double> d=new Point<Double>(1.0,2.0);
d.outPut(d);
Point<Float> f=new Point<Float>(1.0f,2.0f);
f.outPut(f);
}
}
private T x;
private T y;
public Point(T x, T y) {
this.x = x;
this.y = y;
}
public T getX() {
return x;
}
public void setX(T x) {
this.x = x;
}
public T getY() {
return y;
}
public void setY(T y) {
this.y = y;
}
public void outPut(Point<T> p){
System.out.println("点的x坐标为:"+p.getX());
System.out.println("点的y坐标为:"+p.getY());
}
public static void main(String[] args) {
Point<Integer> p=new Point<Integer>(1,2);
p.outPut(p);
Point<Double> d=new Point<Double>(1.0,2.0);
d.outPut(d);
Point<Float> f=new Point<Float>(1.0f,2.0f);
f.outPut(f);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询