Answer to Question #265311 in C++ for Usama

Question #265311

Write a program in C++ that creates an enumerator Fruit. Presents the list of fruits to the user and 

displays the fruit name according to the number provided by the user.


1
Expert's answer
2021-11-13T01:18:03-0500
#include <bits/stdc++.h>
using namespace std;


// Defining enumerator Fruit
enum Fruit{
    Mango,Banana,Grapes,WaterMelon,Guavas,Avocado,Strawberry,Tomato,
};
Fruit EnumOfIndex(int i)
{
    return static_cast<Fruit>(i);
}
// Driver Code
int main()
{
    int x;
    cout<<"Mango Banana Grapes WaterMelon Guavas Avocado Strawberry Tomato"<<endl;
    cout<<"Enter a number: "<<endl;
    cin>>x;
    switch(x)
    {
    case 1:
        cout<<"Mango"<<endl;
        break;
    case 2:
        cout<<"Banana"<<endl;
        break;
    case 3:
        cout<<"Grapes"<<endl;
        break;
    case 4:
        cout<<"WaterMelon"<<endl;
        break;
    case 5:
        cout<<"Guavas"<<endl;
        break;
    case 6:
        cout<<"Avocado"<<endl;
        break;
    case 7:
        cout<<"Strawberry"<<endl;
        break;
    case 8:
        cout<<"Tomato"<<endl;
        break;
    }


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS