Write a program named final Exam Program 2 that defines a struct named mint Type
ID: 3573889 • Letter: W
Question
Write a program named final Exam Program 2 that defines a struct named mint Type to store the following data about mint plants: species (string), height (double). The main() function in your program should do the following: Create two variables of type mint Type named mint1 and mint2. Prompt the user to enter values for the members of mint 1, and store these values in mint 1. Call a function named display, passing mint 1 as a parameter. This function takes a parameter of type mint Type and displays the values stored in the parameter, as shown below. Call a function named double Mint. passing mint1 as a parameter and assigning the return value to mint2. This function takes a parameter of type mintType and returns an object of type mintType whose name is the input parameters name repeated twice and whose height is twice the input parameters height. The function also displays a message that says "Doubling your mint...." Call the function named print again, this time passing mint2 as a parameter. Two sample runs are shown below. Your prompts and outputs should look exactly like this (spelling, punctuation, number format, and so on). Sample Run #1 Enter the mints species: spearmint Enter the mints height: 0.79 Mint information: Species = spearmint, height = 0.79 inches. Doubling your mint... Mint information: Species height = 0.79 inches Doubling your mint... Mint information: Species height = 1.58 inches spearmint spearmint, height = 1.58 inches. Sample Run #2 Enter the mints species: peppermint Enter the mints height: 0.86 inches Doubling your mint... Mint information: Species = peppermintpeppermint, height = 1.72 inches.Explanation / Answer
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
struct mintType //structure definition
{
string species;
double height;
};
void display(mintType m) //display mint
{
cout<<" Mint information :";
cout<<" Species = "<<m.species<<", height = "<<m.height<<" inches.";
}
mintType doubleMint(mintType m) //double mint
{
mintType doubleM;
doubleM.species = m.species;
doubleM.species = m.species.append(m.species); //append method is used to concatenate strings
doubleM.height = 2*(m.height); //double the height of mint
cout<<" Doubling your mint...";
return doubleM;
}
int main()
{
mintType mint1,mint2;
string species;
double height;
cout<<" Enter the mint's species: ";
cin>>species;
cout<<" Enter the mint's height: ";
cin>>height;
mint1.species = species;
mint1.height = height;
display(mint1);
mint2 = doubleMint(mint1);
display(mint2);
return 0;
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.