Answer to Question #250362 in C++ for basit

Question #250362
Define a structure that represents Fruit with properties fruit name, fruit type, fruit color.
Write a program that accepts data of four fruits and displays the results.
1
Expert's answer
2021-10-13T00:30:04-0400

/*Define a structure that represents Fruit with properties of fruit name, fruit type, fruit color.


Write a program that accepts data of four fruits and displays the results. */

#include <iostream>

using namespace std;


//Defining a struct

struct Fruit

{

  char name[50], type[50], color[50];

  int roll;

} f[4];


int main()

{

  cout << "Enter Fruit and fruit properties: " << endl;


  // accepts data of four fruits

  for(int i = 0; i < 4; ++i)

  {

    f[i].roll = i+1;

    cout << "For roll number" << f[i].roll << "," << endl;


    cout << "Enter fruit name: ";

    cin >> f[i].name;


    cout << "Enter fruit type: ";

    cin >> f[i].type;


    cout << "Enter fruit color: ";

    cin >> f[i].color;


    cout << endl;

  }


  cout << "Displays the results: " << endl;


  //Displays the results

  for(int i = 0; i < 4; ++i)

  {

    cout << "\nRoll number: " << i+1 << endl;

    cout << "Fruit Name: " << f[i].name << endl;

    cout << "Fruit type: " << f[i].type << endl;

    cout << "Fruit color: " << f[i].color << endl;

  }


  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