knrt.net
当前位置:首页 >> 用C++定义一个点类Point,由此派生出一个圆类 >>

用C++定义一个点类Point,由此派生出一个圆类

#include using std::cout;using std::endl;#define pi 3.14159struct point { int x, y; point(int _x, int _y) : x(_x), y(_y) {} virtual void show() const { cout 评论0 0 0

#includeusing namespace std;class point{public: point(int ix,int iy){set(ix,iy);} void set(int ix,int iy){x = ix;y = iy;} void disp(){cout 评论0 0 0

朋友这个是C++的吧! class Point { private: int m_nX; int m_nY; public: // } class Circle : public Point { private: int m_nR; public: // }

class Point {public: Point(int x, int y) {_x=x; _y=y;} ~Point() {} int _x, _y;};class Circle : public Point {public: Circle(int x, int y, int radius) : Point(x, y) {_radius=radius;} ~Circle() {} double area() {//面积函数,根据_x,_y和_radius来自己计算出来} int _

//用定义个点类派生一个圆类再画一个圆 #includeclass point{protected: double x; double y;public: point():x(0),y(0) {} point(double xx,double yy):x(xx),y(yy) {} void print() { cout 追问: 是在DOS 窗口下画出来的 评论0 0 0

徒手也一下 试一试class Point{};class Circle:Point{protected: float r;public: Circle(); Circle(float r); float getArea();};Circle::Circle(float r){ this -> r = r;}Circle::Circle(){ this -> r = 0;}floatCircle::getArea(){ returnPI*r*r;}class Ball :Circle{public: Ball(float r);

/***************************************************************\* Copyright (c) 2009 eryar All rights reserved. ** ** File : Main.CPP ** Date : 2009-01-19 19:00 ** Author : eryar@163.com ** ** Description: ** 编写一个程序,设计一个点类Point,求两个点

#include <stdio.h>#include <stdlib.h>class Point{private: int _x; int _y;public: Point(int x,int y) { this->_x=x; this->_y=y; } int getX() { return this->_x; } int getY() { return this->_y; }};class Rectangle:public Point{private: int _width; int _height;public:

class Point { public: virtual int GetArea(){} public: int x; int y; } class Rectangel:public Point { public: int GetArea(){return x*y;} } class Circle:public Point { public: int GetArea(){return 3.14*x*y;} } 直接手打的,基本是这样,你可以参考一下

修改好了,问题都已经在程序里响应位置标出了:#include<iostream>#include<cmath> using namespace std; class point { public: //根据你程序,这儿需要用public,protected和private再类外都是无法访问的 int x,y; public: point(){}; //加上默认

网站首页 | 网站地图
All rights reserved Powered by www.knrt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com