I would really appreciate if someone helps me out with this C++ assignment; PART
ID: 3906993 • Letter: I
Question
I would really appreciate if someone helps me out with this C++ assignment;
PART1 A. REQUIREMENT Open a blank Word document then answer the following questions and save with the name SP2018LAB3_PART1_YourLastName You should study the chapter3 before doing.
Question1:
double x, y; int z; char ch; cin >> x >> ch >> y >> z;
What are values, if any, stored in x, y, z and ch if the input one of the following case, each case separately:
case a: 35 62.3 78
case b: 86.2 32.4A 92.6
case c: 12.7 .45 32A
Question2:
int num1, num2; char symbol;
case a: cin >> num1 >> symbol >> num2;
case b: cin >> symbol >> num1 >> num2;
case c: cin >> num1; cin.get(symbol); cin >> num2;
case d: cin >> num1 >> num2; cin.get(symbol);
case e: cin.get(symbol); cin >> num1 >> num2;
What are values (if any) assigned to num1, num2 and symbol on each case if using the same input for each case:
34 8.43A
Question3:
int age;
char ch;
string name;
cin >> age;
cin.get(ch);
getline(cin, name);
What are the values of age and name if the input is one of the following case:
case a: input is: 45 Russel Goel
case b: input is: 45 - Russel Goel
Question4:
During each summer, John and Jessica grow vegetables in their backyard and buy seeds and fertilizer in various bag sizes. When buying a particular fertilizer, they want to know the price of the fertilizer per pound and the cost of fertilizing per square foot. The following program prompts the users to enter the size of the fertilizer bag, in pounds, the cost of the bag and the area, in square feet, that can be covered by the bag. The program should output the desired results, the price per pound and the cost of each square foot fertilizer However, the program contains logic errors. Find and correct the logic errors so that the program works properly.
#include <iostream>
using namespace std;
int main()
{
int bagSize;
cout << fixed << showpoint << setprecision(2);
cout << "The cost of the fertilizer per pound is: $" << bagCost / bagSize << endl;
cout << "The cost of the fertilizer per square foot is: $"
<< bagCost / bagAreaCovered << endl;
cout << "Enter the amount of fertilizer, in pounds, in the bag: " << endl;
cin >> bagSize;
cout << "Enter the cost of the " << bagSize << " pound fertilizer bag: " << endl;
cin >> bagCost;
cout << "Enter the area, in square feet, that you want to fertilizer? " << endl;
cin >> bagAreaCovered;
double bagCost;
double bagAreaCovered;
system("pause");
#include <iomanip>
return 0;
}
Explanation / Answer
If you have any doubts, please give me comment...
1)
case 1:
x = 35
ch = 6
y = 2.3
z = 78
case 2:
x = 86.2
ch = 3
y = 2.4
z = 0
case 3:
x = 12.7
ch = .
y = 45
z = 32
2)
case d: cin >> num1 >> num2; cin.get(symbol);
3)
case a: input is: 45 Russel Goel
4)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int bagSize;
double bagCost;
double bagAreaCovered;
cout << "Enter the amount of fertilizer, in pounds, in the bag: " << endl;
cin >> bagSize;
cout << "Enter the cost of the " << bagSize << " pound fertilizer bag: " << endl;
cin >> bagCost;
cout << "Enter the area, in square feet, that you want to fertilizer? " << endl;
cin >> bagAreaCovered;
cout << fixed << showpoint << setprecision(2);
cout << "The cost of the fertilizer per pound is: $" << bagCost / bagSize << endl;
cout << "The cost of the fertilizer per square foot is: $"
<< bagCost / bagAreaCovered << endl;
system("pause");
return 0;
}