/* *copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved * File name: 123.cpp * Author: Wang Lui * Completion Date: May 6, 2016 * version number: v1.0 * * Problem Description: Point to The base class, which derives a circle class, increases the data member R, and the area of the member function, implements the other required member functions, and designs the main function to complete the test. * Input Description: None. * Program output: Circle Center coordinate, radius and area. */#include <iostream>using namespace Std;class point{public:point (double x=0,double y=0); Constructor point void SetPoint (double,double); Set x and Y coordinate values double GetX () {return x; }//x coordinates double GetY () {return y; }//y coordinates void show ();p rotected://protected member Double X, y;}; void Point::setpoint (double m,double n)//set X and Y coordinate values {x=m; Y=n;} Point: The constructor {x=m:P oint (double m,double n)//point; Y=n;} void Point::show () {cout<< "(" <<x<< "," <<y<< ")" <<ENDL;} Class Circle:public Point//circle is the common derived class of the point class {public:circle (double x=0,double y=0,double r=0); Constructor circle void Setr (double); Sets the value of the radius double getr (); The value of the read RADIUS double area (); Calculates the area of the Circle Void Show ();p rotected:double radius;}; Circle::circle (double m,double n,double R):P oint (m,n), radius (r) {}//define constructor void Circle::setr (Double R)//set radius value {Radi Us=r;} Double Circle::getr ()//Read RADIUS value {return radius;} Double Circle::area ()//Calculate the area of the circle {return radius*radius*3.14159;} void Circle::show ()//output point and Circle area {cout<< "point= (" <<x<< "," <<y<< "), r=" <<radius << ", area=" <<area () <<endl;} int main () {Circle C (all-in-all); cout<< "Circle Center, Radius, area:" <<endl; C.show (); C.setpoint (2,1); C.SETR (5); cout<< "changed Circle Center, radius, area:" <<endl; C.show (); return 0;}
Operation Result:
Tenth to tenth week Project one-point-circle-cylinder Group Design (2)