Duck duck;
duck.Run(); // Running!!! (duck)
duck.Fly(); // Flying!!! (duck)
duck.Sing(); // The duck sings like "GUA-GUA-GUAAA"
duck.Swim(); // Swimming~~~
duck.Feed("worms"); // You just feed the duck some worms
// Nothing happened...
duck.Feed("bookworms"); // You just feed the duck some worms
// "BURP!" the duck just laid an egg
duck.Sleep(); // Sleeping~~~ (duck)
#include <iostream>
#include <string>
using namespace std;
/* Todo */
// 1. Should invoke Run(), Sleep()
class Animal
{
public:
Animal() : type("UNKNOWN") {}
protected:
string type;
};
/* Todo */
// 1. Implement Inheritance
// 2. Should invoke Woof()
class Dog
{
public:
Dog()
{
type = "dog";
}
};
/* Todo */
// 1. Implement Inheritance
// 2. Should invoke Fly(), Sing()
// 3. Should complete Feed(string food)
class Bird
{
public:
Bird() : sound("UNKNOWN"), secretFood("UNKNOWN")
{
type = "BIRD";
}
void Feed(string food)
{
cout << "You just feed the " << type << " some " << food << endl;
/* Todo */
cout << "Nothing happened..." << endl;
}
protected:
string sound;
string secretFood;
private:
void LayAnEgg()
{
cout << "\"BURP!\" the " << type << " just laid an egg" << endl;
}
};
/* Todo */
// 1. Implement Inheritance
// 2. Should handle parameters sound, secretfood in constructor
class Chicken
{
public:
Chicken()
{
type = "chicken";
/* Todo */
}
};
/* Todo */
// 1. Implement Inheritance
// 2. Should handle parameters sound, secretfood in constructor
// 3. Should invoke Swim()
class Duck
{
public:
Duck()
{
type = "Duck";
/* Todo */
}
};
int main()
{
int testcase = 0;
/* Todo */
// 1. Handle input
// 2. Create Dog, Chicken, Duck Object
// 3. No need to change anything in switchcase
switch (testcase)
{
case 1:
dog.Run();
dog.Woof();
dog.Sleep();
break;
case 2:
chicken.Run();
chicken.Fly();
chicken.Sing();
chicken.Feed("rice");
chicken.Sleep();
break;
case 3:
chicken.Run();
chicken.Fly();
chicken.Sing();
chicken.Feed("uncooked rice");
chicken.Sleep();
break;
case 4:
duck.Run();
duck.Fly();
duck.Sing();
duck.Swim();
duck.Feed("worms");
duck.Sleep();
break;
case 5:
duck.Run();
duck.Fly();
duck.Sing();
duck.Swim();
duck.Feed("bookworms");
duck.Sleep();
break;
default:
cout << "Remember to handle input!" << endl;
break;
}
return 0;
}
No need to handle input. (Input would be number 1~5 to represent the index of test-case)