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 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...
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.
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 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 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 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; //
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Binary Search Tree Code in Java Write a program that prompts user to enter however many...
Binary Search Tree Code in Java Write a program that prompts user to enter however many numbers they want to add to the binary search tree. Then have the user input numbers until the tree contains that many elements. If the user enters a number that already exists in the tree, then a message should be displayed "Number is already in the tree". Once all elements are added to the tree print its contents in sorted order. Assume all user...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT