Project 1 of week 1: What is animal name? (Abstract class)

Source: Internet
Author: User
/** Program Copyright and version description Section * copyright (c) 2012, Yantai University Computer college student * All rightsreserved. * Author: Li Yang * Completion Date: July 15, June 2, 2013 * version: V1.0 * input Description: none * Problem description: none * program output: none */# include <iostream> # include <string> using namespace STD; class animal {public: Virtual void cry () {cout <"which animal does not know, how can I learn it? "<Endl ;}}; class mouse: Public animal {public: mouse (string, char); Virtual void cry (); protected: string name; char sex ;}; mouse: mouse (string Nam, char SE) {name = Nam; Sex = Se;} // call void mouse: cry () {cout <"my name is" <name <", is a" <(sex = 'M ')? "Male": "female") <"Mouse, my cry is: cheep! "<Endl;} class Cat: Public animal {public: CAT (string); Virtual void cry (); protected: string name ;}; // constructor Cat :: CAT (string NAM) {name = Nam;} // call void Cat: cry () {cout <"my name is" <name <", it's a mouse. My cry is: Meow! "<Endl;} class Dog: Public animal {public: Dog (string); Virtual void cry (); protected: string name ;}; // constructor dog :: dog (string NAM) {name = Nam;} // void dog: cry () {cout <"my name is" <name <", a dog, my cry is: Wang! "<Endl;} class Giraffe: Public animal {public: giraffe (string, char); Virtual void cry (); protected: string name; char sex ;}; // constructor Giraffe: giraffe (string Nam, char SE) {name = Nam; Sex = Se;} // void Giraffe: cry () {cout <"my name is" <name <", is" <(sex = 'M ')? "Male": "female") <"giraffe, my neck is too long to sound! "<Endl ;}int main () {animal * P; P = new animal (); // open up space for the pointer p-> cry (); mouse M1 ("Jerry", 'M'); P = & M1; P-> cry (); mouse m2 ("Jemmy", 'F '); P = & m2; P-> cry (); CAT C1 ("Tom"); P = & C1; P-> cry (); dog D1 ("Droopy "); P = & D1; P-> cry (); giraffe G1 ("Gill", 'M'); P = & G1; P-> cry (); Return 0 ;}
/** Copyright and version declaration section of the Program * copyright (c) 2012, student * All rightsreserved from computer College of Yantai University. * Author: Li Yang * Completion Date: July 15, June 2, 2013 * version: V1.0 * input Description: none * Problem description: none * program output: none */# include <iostream> # include <string. h> using namespace STD; class animal {public: Virtual void cry () = 0 ;}; class mouse: Public animal {public: mouse (string, char ); virtual void cry (); protected: string name; char sex ;}; mouse: mouse (string Nam, char SE) {name = Nam; Sex = Se ;}// Void mouse: cry () {cout <"my name is" <name <", is it a" <(sex = 'M ')? "Male": "female") <"Mouse, my cry is: cheep! "<Endl;} class Cat: Public animal {public: CAT (string); Virtual void cry (); protected: string name ;}; // constructor Cat :: CAT (string NAM) {name = Nam;} // call void Cat: cry () {cout <"my name is" <name <", it's a mouse. My cry is: Meow! "<Endl;} class Dog: Public animal {public: Dog (string); Virtual void cry (); protected: string name ;}; // constructor dog :: dog (string NAM) {name = Nam;} // void dog: cry () {cout <"my name is" <name <", a dog, my cry is: Wang! "<Endl;} class Giraffe: Public animal {public: giraffe (string, char); Virtual void cry (); protected: string name; char sex ;}; // constructor Giraffe: giraffe (string Nam, char SE) {name = Nam; Sex = Se;} // void Giraffe: cry () {cout <"my name is" <name <", is" <(sex = 'M ')? "Male": "female") <"giraffe, my neck is too long to sound! "<Endl ;}int main () {animal * P; // P = new animal (); // P-> cry (); mouse M1 (" Jerry ", 'M'); P = & M1; P-> cry (); mouse m2 ("Jemmy", 'F'); P = & m2; p-> cry (); CAT C1 ("Tom"); P = & C1; P-> cry (); dog D1 ("Droopy"); P = & D1; p-> cry (); giraffe G1 ("Gill", 'M'); P = & G1; P-> cry (); Return 0 ;}

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.