Answer to Question #300526 in C++ for Tony

Question #300526

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.

1
Expert's answer
2022-02-21T05:17:37-0500
#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);
}

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