10th Week Project One-point-round-cylinder design (2)

Source: Internet
Author: User

Code:

/**copyright (c) 2016, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: main.cpp;* Author: Ye Chengyan; * Completion Date: May 6, 2015; * Version number: vc++6.0;** problem description As a base class of point, a circle class is derived, the radius r of the data member is increased, and the area of the member function is calculated.                    * Program input: slightly; * Program output: slightly; */#include <iostream>using namespace Std;class point{public:point (double x=0,double y=0);                  constructor void SetPoint (double,double);   Sets the coordinate value double GetX () const {return x;   Read x-coordinate} double GetY () const {return y; Read y-coordinate} void Show ();p rotected://protected Member double x,y;};/    The/point constructor 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//circle is the common derived class of the point class {public:circle (double x=0,double y=0,double r=0);                  constructor void Setradius (double);       Set the RADIUS value double Getradius () const;        Read RADIUS value double area () const; Calculate Circle area Void Show ();p rotected:double radius;};/ /definition constructor, circle::circle (double a,double b,double R) for the center coordinate and radius initialization, radius (r) {}//set radius value void Circle::setradius:P oint (b) ( Double r) {radius=r;} Read RADIUS value double Circle::getradius () const{return radius; Calculate Circle Area Double Circle::area () const{return 3.14159*radius*radius;} Output Circle information void Circle::show () {cout<< "center=[" <<x<< "," <<y<< "], r=" <<radius< < ", area=" <<area () <<endl;}    int main () {Circle C (3.5,6.4,5.2);    cout<< "Original circle:\n";    C.show ();    C.setpoint (5,5);    cout<< "New circle:\n";    C.show (); return 0;}
Run the test;



10th Week Project One-point-round-cylinder design (2)

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.