/** 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 ;}