<pre name= "code" class= "CPP" >/* *copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved * File name: 123.cpp * Author: Wang Lui * finish date : May 6, 2016 * version number: v1.0 * * Problem Description: Take the point as the base class, derive a circle class, increase the data member R, and the area of the member function, implement other required member functions, design 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 Circlevoid 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;} Class Cylinder:public Circle{public:cylinder (double x=0,double y=0,double r=0,double h=0);//constructor Cylinder void SetH Eight (double); Sets the high double getheight () const of the cylinder; Reads the high double area () const of a cylinder; Calculates the surface area of a cylinder double volume () const; Calculates the volume of the Cylinder void show ();p rotected:double height; Cylinder height}; Cylinder::cylinder (double m,double n,double r,double h): Circle (m,n,r), height (h) {}//define constructor void Cylinder::setheight ( Double h)//Set the height of the cylinder {height=h;} Double cylinder::getheight () const//Read High {return height of cylinder;} Double Cylinder::area () const//calculates the surface area of the cylinder {return (radius*radius*3.14159) +2*3.14159*radius*height;} Double Cylinder::volume () const//calculates the volume of the cylinder {return radius*radius*3.14159*height;} void Cylinder::show () {cout<< "point= (" <<x<< "," <<y<< "), r=" <<radius<< ", H = "<
Operation Result:
Tenth to tenth week Project one-point-circle-cylinder Group Design (3)