Define a struct , FruitType, to store the following data about a fruit: Fruit name (string), color (string), fat (int), sugar ( int ), and carbohydrate (int). Now write a program that implements the struct FruitType, then include two functions. One function must ask the user to input the data about the fruit. The other function must output the data bout the fruit.
#include<iostream>
#include<string>
using namespace std;
struct FruitType
{
string FruitName;
string color;
int fat;
int sugar;
int carbohydrate;
};
void SetData(FruitType* ft)
{
cout<<"Please, enter a Fruit name: ";
cin>>ft->FruitName;
cout<<"Please, enter a color of Fruit: ";
cin>>ft->color;
cout<<"Please, enter fat of Fruit: ";
cin>>ft->fat;
cout<<"Please, enter sugar of Fruit: ";
cin>>ft->sugar;
cout<<"Please, enter carbohydrate of Fruit: ";
cin>>ft->carbohydrate;
}
void Display(FruitType* ft)
{
cout<<"\nFruit name is "<<ft->FruitName
<<"\nColor is "<<ft->color
<<"\nFat is "<<ft->fat
<<"\nSugar is "<<ft->sugar
<<"\nCarbohydrate is "<<ft->carbohydrate;
}
int main()
{
FruitType a;
SetData(&a);
Display(&a);
}
Comments
Leave a comment