Question
Define a class RESTRA in C++ with following description: Private Members:
- FoodCode of type int
- Food of type string
- FType of type string
- Sticker of type string
A member function GetSticker() to assign the following values for Sticker as per the given Ftype:
FType |
Sticker |
Vegetarian |
GREEN |
Contains Egg |
YELLOW |
Non-Vegetarian |
RED |
Public Members :
- A function GetFood() to allow user to enter values for FoodCode, Food,Ftype and call function GetSticker() to assign
- A function ShowFood() to allow user to view the concept of all the data members.
Solution
class RESTRA
{
int FoodCode;
char Food[20];
char FType[20];
char Sticker[20];
void GetSticker();
public:
void GetFood();
void ShowFood();
};
void RESTRA::GetFood()
{
cin>>FoodCode;
cin>>Food;
cin>>FType;
GetSticker ();
}
void RESTRA:: GetSticker ()
{
if (strcmp(FType,'Vegetarian'))
strcpy(Sticker,'GREEN');
else if (strcmp(FType,'Contains Egg'))
strcpy(Sticker,'YELLOW');
else if(strcmp(FType,'Non-Vegetarian'))
strcpy(Sticker,'RED');
}
void RESTRA:: ShowFood ()
{
cout<< FoodCode <<'\t'<<Food<<'\t'<<FType<<'\t'<<Sticker<<endl;
}