Virtual base exercise animal 1

Source: Internet
Author: User
/* The long-term evolution of species enables amphibious animals to live on land and swim in water. The virtual base class is used to establish multiple inheritance of a class, including animals (animal, attributes include body length, weight, and gender), and terrestrial animals (ter_animal, attributes increase the running speed ), aquatic Animals (aqu_animal, attributes increase the swimming speed) and amphibious animals (amp_animal ). Amphibious animals retain the attributes of terrestrial and aquatic animals. Input length, weight, gender, swimming speed, running speed (running_speed) Output initialized length, weight, gender, swimming speed, running speed (running_speed) and the length, weight, gender, swimming speed, and running speed of the input amphibious animals (running_speed) */# include <iostream> using namespace STD; class animal {protected: int height; int weight; char sex; public: Animal () {} animal (int h, int W, char S): height (H), weight (W), sex (s) {}}; class aqu_animal: virtual public animal {protected: int extends ming_speed; public: aqu_animal () {} aqu_animal (int h, int W, char S, int s_p ): animal (H, W, S), swimming_speed (s_p) {}}; class ter_animal: virtual public animal {protected: int running_speed; public: ter_animal () {} ter_animal (int h, int W, char S, int R_p): Animal (H, W, S), running_speed (R_p) {}}; class amp_animal: Public aqu_animal, public ter_animal {public: amp_animal () {} amp_animal (int h, int W, char S, int s_p, int R_p): Animal (H, W, S ), aqu_animal (H, W, S, s_p), ter_animal (H, W, S, R_p) {} void input () cin> height> weight> sex> extends ming_speed> running_speed; void show () {cout <"height:" 

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.