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 C program that declares an integer variable called "favorite_number". The program should then prompt...
write a C program that declares an integer variable called "favorite_number". The program should then prompt the user to enter their favorite number, and use scanf to read the user's input into favorite_number. Finally, the program should print a message that includes the user's input.
Write a program that prompts the user to input a decimal number and outputs the number...
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
Write a complete Java program which prompts the user of the program to input his/her first...
Write a complete Java program which prompts the user of the program to input his/her first name, then prompts the user for the middle initial and finally prompts the user for the last name. As indicated, there are three prompts to the user. The program should output the user’s name with the first name first, followed by the middle initial, and the last name last, all on one line (with appropriate spacing). If you could also pinpoint exactly where to...
C++ program 1. Write a structure (struct) for a course information that contains: subject(string), course number(int),...
C++ program 1. Write a structure (struct) for a course information that contains: subject(string), course number(int), section number (int), and department name (string). Then in a application program, ask a user to input the necessary information and populate a structure.
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare...
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare a variable of type ofstream which is used to output a stream into a file: ofstream output; // output is the name of the variable Prompt the user to input values for the grades of 3 students. Use the output operator (<<) to write the grades into grades.txt: output << grade1 << " " << grade2 << " " << grade3 << endl; You...
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.
Write a java program that declares a variable in inches, which holds a length in inches,...
Write a java program that declares a variable in inches, which holds a length in inches, and assign a value 100 inches. Display the value in feet and inches; for example, 86 inches becomes 7 feet and 2 inches. Print the results of conversion of 100 inches into feet and inches. Java 11 please
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 program (just console application, no GUI) in C# which prompts the user for an...
Write a program (just console application, no GUI) in C# which prompts the user for an integer, increments the integer by 1 and displays the result in the following format: "The given number n has been incremented to n+1" Make sure your application fails to a secure mode. That is, no matter what is the user input, the application does not terminate with an error
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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT