Point, circle, and cylindrical

Source: Internet
Author: User
Tags gety

Print? /* Copyright (c) 2012, computer College, Yantai University
* All rights reserved.
* File name: text. cpp
* Author: Hu Ying
* Completion date: January 1, May 20, 2013
* Version No.: v1.0
*
* Input Description: None
* Problem description: (1) create a Point class, which includes data members x and y (coordinate Point); (2) base class with Point, A Circle class is derived, and the data member (RADIUS) is added. (3) A Cylinder class is derived from the Circle class as the direct base class, then add the data member h (high ). Requires programming, design various basic member functions (including constructor, destructor, public interfaces for modifying data members and getting data members, and heavy-duty operators for output, such as <function), it can be used to process the above objects, and finally obtain the surface area, volume, and output of the cylindrical cylinder.
* Program output: output point, circle information, and cylindrical Information
* Problem Analysis: None
* Algorithm Design: omitted
*/
# Include <iostream>
Using namespace std;
Class Point
{
Public:
Point (double x = 0, double y = 0); // The initialization coordinate is (0, 0)
Double getX () const
{
Return x;
}
Double getY () const
{
Return y;
}
Void setPoint (double, double );
Friend ostream & operator <(ostream &, const Point &);
Protected:
Double x, y;
};
Point: Point (double a, double B)
{
X =;
Y = B;
}
Void Point: setPoint (double a, double B)
{
X =;
Y = B;
}
Ostream & operator <(ostream & output, const Point & p)
{
Output <"point: [" <p. x <"," <p. y <"]" <endl;
Return output;
}
Class Circle: public Point
{
Public:
Circle (double x = 0, double y = 0, double r = 0 );
Void setRadius (double );
Double getRadius () const;
Double area () const;
Friend ostream & operator <(ostream &, const Circle &);
Protected:
Double radius;
};
Circle: Circle (double a, double B, double r): Point (a, B), radius (r ){}
Void Circle: setRadius (double r)
{
Radius = r;
}
Double Circle: getRadius () const
{
Return radius;
}
Double Circle: area () const
{
Return 3.14159 * radius;
}
Ostream & operator <(ostream & output, const Circle & c)
{
Output <"center = [" <c. x <"," <c. y <"], r =" <c. getRadius () <", area =" <c. area () <endl;
Return output;
}
Class Cylinder: public Circle
{
Public:
Cylinder (double x = 0, double y = 0, double r = 0, double h = 0 );
Void setHeight (double );
Double getHeight () const;
Double area () const;
Double volume () const;
Friend ostream & operator <(ostream &, const Cylinder &);
Protected:
Double height;
};
Cylinder: Cylinder (double a, double B, double r, double h): Circle (a, B, r), height (h ){}
Void Cylinder: setHeight (double h)
{
Height = h;
}
Double Cylinder: getHeight () const
{
Return height;
}
Double Cylinder: area () const
{
Return 2 * Circle: area () + 2*3.14159 * radius * height; // calculate the area by using the area function of the Circle member function. The method is Circle: area ()
}
Double Cylinder: volume () const
{
Return Circle: area () * height;
}
Ostream & operator <(ostream & output, const Cylinder & cy)
{
Output <"center = [" <cy. x <"," <cy. y <"], r =" <cy. radius <", h =" <cy. height <", area =" <cy. area () <", volume =" <cy. volume () <endl;
Return output;
}
Int main ()
{
Point p (3.5, 6.4 );
Cout <"x =" <p. getX () <", y =" <p. getY () <endl;
P. setPoint (8.5, 6.8 );
Cout <"p:" <p <endl;
Circle c (1.2, 2.2, 3.2 );
Cout <"original circle: x =" <c. getX () <", y =" <c. getY () <", r =" <c. getRadius () <", area =" <c. area () <endl;
C. setPoint (5, 5 );
Cout <"new circle:" <c;
Cylinder cy1 (1.2, 2.2, 3.2, 4.2 );
Cout <"original Cylinder: x =" <cy1.getX () <", y =" <cy1.getY () <", r =" <cy1.getRadius () <", h =" <cy1.getHeight () <", area =" <cy1.area () <", volume =" <cy1.volume () <endl;
Cy1.setPoint (5, 5 );
Cy1. setradius (2.1 );
Cy1.setHeight (3 );
Cout <"new Cylinder:" <cy1;
Return 0;
}

/* Copyright (c) 2012, computer College, Yantai University
* All rights reserved.
* File name: text. cpp
* Author: Hu Ying
* Completion date: January 1, May 20, 2013
* Version No.: v1.0
*
* Input Description: None
* Problem description: (1) create a Point class, which includes data members x and y (coordinate Point); (2) base class with Point, A Circle class is derived, and the data member (RADIUS) is added. (3) A Cylinder class is derived from the Circle class as the direct base class, then add the data member h (high ). Requires programming, design various basic member functions (including constructor, destructor, public interfaces for modifying data members and getting data members, and heavy-duty operators for output, such as <function), it can be used to process the above objects, and finally obtain the surface area, volume, and output of the cylindrical cylinder.
* Program output: output point, circle information, and cylindrical Information
* Problem Analysis: None
* Algorithm Design: omitted
*/
# Include <iostream>
Using namespace std;
Class Point
{
Public:
Point (double x = 0, double y = 0); // The initialization coordinate is (0, 0)
Double getX () const
{
Return x;
}
Double getY () const
{
Return y;
}
Void setPoint (double, double );
Friend ostream & operator <(ostream &, const Point &);
Protected:
Double x, y;
};
Point: Point (double a, double B)
{
X =;
Y = B;
}
Void Point: setPoint (double a, double B)
{
X =;
Y = B;
}
Ostream & operator <(ostream & output, const Point & p)
{
Output <"point: [" <p. x <"," <p. y <"]" <endl;
Return output;
}
Class Circle: public Point
{
Public:
Circle (double x = 0, double y = 0, double r = 0 );
Void setRadius (double );
Double getRadius () const;
Double area () const;
Friend ostream & operator <(ostream &, const Circle &);
Protected:
Double radius;
};
Circle: Circle (double a, double B, double r): Point (a, B), radius (r ){}
Void Circle: setRadius (double r)
{
Radius = r;
}
Double Circle: getRadius () const
{
Return radius;
}
Double Circle: area () const
{
Return 3.14159 * radius;
}
Ostream & operator <(ostream & output, const Circle & c)
{
Output <"center = [" <c. x <"," <c. y <"], r =" <c. getRadius () <", area =" <c. area () <endl;
Return output;
}
Class Cylinder: public Circle
{
Public:
Cylinder (double x = 0, double y = 0, double r = 0, double h = 0 );
Void setHeight (double );
Double getHeight () const;
Double area () const;
Double volume () const;
Friend ostream & operator <(ostream &, const Cylinder &);
Protected:
Double height;
};
Cylinder: Cylinder (double a, double B, double r, double h): Circle (a, B, r), height (h ){}
Void Cylinder: setHeight (double h)
{
Height = h;
}
Double Cylinder: getHeight () const
{
Return height;
}
Double Cylinder: area () const
{
Return 2 * Circle: area () + 2*3.14159 * radius * height; // calculate the area by using the area function of the Circle member function. The method is Circle: area ()
}
Double Cylinder: volume () const
{
Return Circle: area () * height;
}
Ostream & operator <(ostream & output, const Cylinder & cy)
{
Output <"center = [" <cy. x <"," <cy. y <"], r =" <cy. radius <", h =" <cy. height <", area =" <cy. area () <", volume =" <cy. volume () <endl;
Return output;
}
Int main ()
{
Point p (3.5, 6.4 );
Cout <"x =" <p. getX () <", y =" <p. getY () <endl;
P. setPoint (8.5, 6.8 );
Cout <"p:" <p <endl;
Circle c (1.2, 2.2, 3.2 );
Cout <"original circle: x =" <c. getX () <", y =" <c. getY () <", r =" <c. getRadius () <", area =" <c. area () <endl;
C. setPoint (5, 5 );
Cout <"new circle:" <c;
Cylinder cy1 (1.2, 2.2, 3.2, 4.2 );
Cout <"original Cylinder: x =" <cy1.getX () <", y =" <cy1.getY () <", r =" <cy1.getRadius () <", h =" <cy1.getHeight () <", area =" <cy1.area () <", volume =" <cy1.volume () <endl;
Cy1.setPoint (5, 5 );
Cy1. setradius (2.1 );
Cy1.setHeight (3 );
Cout <"new Cylinder:" <cy1;
Return 0;
}

Running result:

Related Article

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.