Question

Assume the definition of Exercise 4, which defines the struct fruitType. Write a program that declares...

Assume the definition of Exercise 4, which defines the struct fruitType. Write a program that declares a variable of type fruitType, prompts the user to input data about a fruit, and outputs the fruit data.

Homework Answers

Answer #1
#include <iostream>
#include <string>
using namespace std;

struct fruitType {
    string type;
    string color;
};

int main() {
    fruitType fruit;
    cout << "Enter type of fruit: ";
    cin >> fruit.type;
    cout << "Enter color of fruit: ";
    cin >> fruit.color;
    cout << "Type of the fruit is " << fruit.type << " and the color of the fruit is " << fruit.color << endl;
    return 0;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that declares a variable named inches, which holds a length in inches, and...
Write a program that declares a variable named inches, which holds a length in inches, and assign a value. Display the value in feet and inches; for example: 86 inches is 7 feet and 2 inches. Be sure to use a named constant where appropriate. When submitting the program for testing/grading, assign the value 86 to inches.
Which one of the following situations does NOT have a retain cycle? Object 1 of struct...
Which one of the following situations does NOT have a retain cycle? Object 1 of struct A is assigned to a member of Object 2 of struct B, while Object 2 of struct B is assigned to a member of Object 1 of struct A. Object 1 of class A is assigned to a member of Object 2 of class A, while Object 2 of class A is assigned to a member of Object 1 of class A. Object 1...
Write a short MARIE program. Answer ASAP. Will upvote. This program will let the user input...
Write a short MARIE program. Answer ASAP. Will upvote. This program will let the user input two decimal values a and b. Then this program will calculate c = a + b and output the result. Q1) Write down the code which let the user input two valuesa and b. The code need to store the input values. Q2) Write down the code which calculates c = a + b. The code need to store the result into variable c....
Write the function definition for a function which asks the user for their name and then...
Write the function definition for a function which asks the user for their name and then prints a personalized greeting. DO NOT WRITE AN ENTIRE PROGRAM. DO NOT WRITE THE STATEMENT THAT CALLS THE FUNCTION JUST WRITE THE FUNCTION DEFINITION
Write a C++ program reads the grades. Declare a variable of type ifstream which is used...
Write a C++ program reads the grades. Declare a variable of type ifstream which is used to input a stream from a file: ifstream input; // input is the name of the variable Use the input operator (>>) to read data from the above file: input >> score1 >> score2 << score3; //
(Python Programming) Write a program that prompts a user for a positive integer and then uses...
(Python Programming) Write a program that prompts a user for a positive integer and then uses a loop to calculate and display the sum of specific fractions as follows: Let's say the user enters 5, then your program will compute: 1/5 + 2/4 + 3/3 + 4/2 + 5/1 which is 8.7.
Write the function definition for a function which accepts 2 values from the main program and...
Write the function definition for a function which accepts 2 values from the main program and returns the average of the two numbers. DO NOT WRITE AN ENTIRE PROGRAM. DO NOT WRITE THE STATEMENT THAT CALLS THE FUNCTION! JUST WRITE THE FUNCTION DEFINITION python program
Create a program which uses each struct declared in problem 1 and accesses each member of...
Create a program which uses each struct declared in problem 1 and accesses each member of each struct. (a) Create a variable using each struct and initialize it with some mock data of your choosing. (b) Print the members of each struct separated by a newline. (c) Modify each member of each struct to something different. (d) Print all members again. Save your code as prob2.c. This is Problem 1: struct ProductData {     int ID;     char Name[50];     float Price;     int...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
Write a function definition for a function which accepts three values from the main program and...
Write a function definition for a function which accepts three values from the main program and prints the largest of the three values. DO NOT WRITE AN ENTIRE PROGRAM. DO NOT WRITE THE STATEMENT THAT CALLS THE FUNCTION! JUST WRITE THE LINES OF CODE FOUND IN THE FUNCTION DEFINITION