Tenth to tenth week Project one-point-circle-cylinder Group Design (3)

Source: Internet
Author: User

<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<< ")" &LT;&LT;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)

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.