1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <iostream>
#include <string>
using namespace std;
class Ingredient {
void ingre()
{
cout << "Ingredient : ";
}
protected:
string a, b;
string name[6] = { "apple", "eggs", "ham", "potato", "cheese", "tuna" };
virtual string ing(string a, string b) = 0;
public:
void run()
{
ingre();
for (int i = 0; i < 6; i++)
cout << name[i] << " ";
cout << endl;
}
void Set()
{
cout << "Please enter your favorite ingredients (two) : ";
cin >> a >> b;
}
void paint()
{
ing(a, b);
}
};
class com :public Ingredient {
string names[15] = { "pizza", "burger", "chopstick", "fried rice", "tuna soup", "egg with rice", "Gratin", "Cheese ball", "Tuna mayo rice bowl", "Potato croquette", "sandwitch", "rice with burger", "French fries", "potato soup", tuna Sashimi" };
protected:
string ing(string a, string b)
{
if (a == name[0] && b == name[1])
cout << names[0] << endl;
else if (a == name[0] && b == name[2])
cout << names[1] << endl;
else if (a == name[0] && b == name[3])
cout << names[2] << endl;
else if (a == name[0] && b == name[4])
cout << names[3] << endl;
else if (a == name[0] && b == name[5])
cout << names[4] << endl;
else if (a == name[1] && b == name[2])
cout << names[5] << endl;
else if (a == name[1] && b == name[3])
cout << names[6] << endl;
else if (a == name[1] && b == name[4])
cout << names[7] << endl;
else if (a == name[1] && b == name[5])
cout << names[8] << endl;
else if (a == name[2] && b == name[3])
cout << names[9] << endl;
else if (a == name[2] && b == name[4])
cout << names[10] << endl;
else if (a == name[2] && b == name[5])
cout << names[11] << endl;
else if (a == name[3] && b == name[4])
cout << names[12] << endl;
else if (a == name[3] && b == name[5])
cout << names[13] << endl;
else if (a == name[4] && b == name[5])
cout << names[14] << endl;
else
return 0;
}
};
int main()
{
Ingredient *d;
d = new com;
Ingredient *i = d; // Tried to Up-Casting
d->run();
d->Set();
d->paint();
i = d;
delete i;
}
| |