Design of point-circle-cylinder class family

Source: Internet
Author: User
Tags getv

/* Copyright (c) 2016* All rights reserved College of Computer and Control engineering, Yantai University * file name: 3.cpp* Liu Li * completion date: April 28, 2016 * version number: v1.0* * "Project-point-circle-cylinder class design" as follows, starting from the design and testing of the base class, gradually complete the design of each class, find out the surface area, volume and output of the cylindrical cylinder and complete the required calculation tasks: (1) first set up a point (dot) class, including data member X, y (coordinate point), Implement the required member functions, and design the main function to complete the test; (2) a Circle (circle) class is derived from the point base, the data member R (RADIUS) is added, and the member function area is implemented to implement the other required member functions, and the main function is designed to complete the test ; (3) with the Circle class as the direct base class, a cylinder (cylinder) class is derived, and then the data member H (high) is added, and the member function area of the cylinder surface and the member function of the cylinder volume are volume, the member function is implemented, and the main function is designed to complete the test. A program is required to design a variety of "required member functions", including constructors, destructors, modify data members and get data members of the public interface, for the output of the overloaded operator "<<" function. (Tip: This task can be divided into three sub-tasks into several steps.) First, declare the base class, then declare the derived class, step through, and Debug. --this method is suitable for any project) */#include <iostream> #include <cstring>const double pi=3.14;using namespace Std;class    Point{protected:int x; int y;public:point (int x,int y): x (x), Y (y) {};};    Point::P oint (const point &a) {x=a.x; Y=A.Y;}    Class Circle:public Point{protected:int r;public:circle (int x,int y,int R):P oint (x, y), R (r) {}; Double Getarea ();}; Double Circle::getarea () {return pi*r*r;} Class CyliNder:public circle{protected:int h;public:cylinder (int x,int y,int r,int h): Circle (X,y,r), H (h) {};    Double Getcarea (); Double Getv ();}; Double Cylinder::getcarea () {return pi*r*r*2+2*pi*r*h;} Double Cylinder::getv () {return pi*r*r*h;}    int main () {Cylinder C1 (0,0,2,5);    cout << "Bottom area:" <<c1.getarea () <<endl;    cout << "surface area:" <<c1.getcarea () <<endl;    cout << "Volume:" <<c1.getv () <<endl; return 0;}



Design of point-circle-cylinder class family

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.