14-week Task 3 (area calculation)

Source: Internet
Author: User
/** Copyright and version declaration section of the Program * Copyright (c) 2013, student * All rightsreserved from computer College of Yantai University. * file name: score. cpp * Author: Liu Yuanlong * Completion Date: July 15, May 31, 2013 * version: v1.0 * input Description: * Problem description: * output: */# include <iostream> using namespace std; // empty base class csolid {public: virtual void area () {cout <"did not tell me how to find the information:";} virtual void v () {cout <"did not tell me how to find the information! ";}}; // Cube class cball: public csolid {public: cball (double); void area (); void v (); protected: double d ;}; cball: cball (double R) {d = R;} void cball: area () {double s; s = d * d; cout <"area: "<s <" ";}void cball: v () {double v; v = d * d; cout <" volume: "<v; cout <endl;} // ball class ccylinder: public csolid {public: ccylinder (double); void area (); void v (); protected: double r ;}; ccylinder: ccylinder (double X) {r = X;} void ccylinder: area () {double s; s = 4*3.14 * r; cout <"Area:" <s <";} void ccylinder: v () {double v; v = (4/3) * r; cout <"volume:" <v <endl ;}// cylinder class ccube: public csolid {public: ccube (double, double); void area (); void v (); protected: double a, B ;}; ccube: ccube (double X, double Y) {a = X; // The ground radius of the cylinder B = Y; // cylinder height} void ccube: area () {double s; s = (3.14*2 * a * B) + (2*3.14 * ); cout <"Area:" <s <";} void ccube: v () {double v; v = 3.14 * a * B; cout <"volume:" <v <endl ;}int main () {ccube c1 (4.5); cball r1 (4); ccylinder t1 ); csolid * p = & c1; p-> area (); p-> v (); p = & r1; p-> area (); p-> v (); p = & t1; p-> area (); p-> v (); return 0 ;}

Running result:

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.