Tenth Week-design project of Circle Group

Source: Internet
Author: User

Questions and codes:

/*copyright School of Computer and control engineering completion Date: May 6, 2016 Ma Yanyan problem Description: Based on point, derive a circle (circle) class, increase the data member R (RADIUS), and the area of the member function areas to implement other required member functions, Design main function to complete the test; Input Description: No output description: coordinate value; */#include <iostream>using namespace std;const float Pi=3.1415926;class point{                    Public:point (double x=0,double y=0);                  constructor void SetPoint (double,double);              Sets the coordinate value double GetX () const {return x;}              X-coordinate double GetY () const {return y;}                                       Y-coordinate void show (); Protected member Double x, y;};    Point::P oint (double a,double b) {x=a; Y=b;}    Set x and Y coordinate values void Point::setpoint (double a,double b) {x=a; Y=b;} void Point::show () {cout<< "(" <<x<< "," <<y<< ")" &LT;&LT;ENDL;}    Class Circle:public point{private:double R;        Public:circle (double x=0,double y=0,double r=0);        void Setr (double);        Double area () const; void Show ();}; Circle:: Circle (Double a,double b,double R):P Oint (A, B), R (r) {}//Set circleThe constructor of void Circle::setr (double R) {this->r=r;}    Double Circle::area () const{return pi*r*r;//the area of the Circle}void Circle:: Show () {cout<< "center coordinates are:" <<endl;    cout<< "(" <<x<< "," <<y<< ")" <<endl;    cout<< "Radius:" <<endl; Cout<<r<<endl;}    int main () {Circle C (3.1,4.5,2.1);    C.show ();    C.setpoint (5,8);    C.show (); return 0;}

Operation Result:


Summary of Knowledge points:

When point is the base class for circle, if Circle is accessing the private member of the base class is not possible, then the original private member is defined as a protected class or public class

Tenth Week-design project of Circle Group

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.