Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HOMEWORK # 1 . PROGRAM #2 Instructions: For this program t is REQUIRED that you

ID: 3751976 • Letter: H

Question

HOMEWORK # 1 . PROGRAM #2 Instructions: For this program t is REQUIRED that you match the spacing, the reason is this exercise is about formatting. This means you must have 'green complete in Hypergrade for this program Write a C++program that dsplays the results of the expressions 30·5.0. 7.1·83-22, and 32 , 1 . 5 Display the results of each calculation right aligned rounded to two decimal places Your output should look like this (you will need to use setw, fixed and setprecision to get this to workj: 3.0 -5.0 15.00 7.1 8.3 -2.2 56.73 3.2 16.1 0.10 Pseudocode is NOT required for this program. This program IS auto-graded. Test Case 1 - Failed

Explanation / Answer

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
double num = 3.0;
double num1 = 5.0;
double num2 = num*num1;
double num3 = 7.1;
double num4 = 8.3;
double num5 = 2.2;
double num6 = num3*num4-num5;
double num7 = 3.2;
double num8 = 6.1;
int num9 = 5;
double num10 = num7/(num8*num9);
  
cout << setw(7) << fixed << right << setprecision(1) << num
<< endl;
  
cout << "*"
<< setw(5) << fixed << right << setprecision(1) << num1
<< endl;

cout << "------"
<< setw(5) << fixed << right << endl;

cout << setw(6) << fixed << right << setprecision(2) << num2
<< endl;

cout << endl << endl; //end of part1 3.0*5.0

cout << setw(5) << fixed << right << setprecision(1) << num3
<< endl;

cout << "*"
<< setw(4) << fixed << right << setprecision(1) << num4
<< endl;
  
cout << "-"
<< setw(4) << fixed << right << setprecision(1) << num5
<< endl;

cout << "------"
<< setw(5) << fixed << right << endl;

cout << setw(6) << fixed << right << setprecision(2) << num6
<< endl;

cout << endl << endl; //end of part2 7.1*8.3-2.2
  
cout << setw(5) << fixed << right << setprecision(1) << num7
<< endl;

cout << "/"
<< "("
<< setw(3) << fixed << right << setprecision(1) << num8
<< endl;

cout <<"*"
<< setw(3) << fixed << right << num9 << ")"
<< endl;

cout << "------"
<< setw(5) << fixed << right << endl;
  
cout << setw(6) << fixed << right << setprecision(2) << num10
<< endl; //end of part3 3.2/(6.1*5)

return 0;
}

Output of the program:-

3.0
* 5.0
------
15.00


7.1
* 8.3
- 2.2
------
56.73


3.2
/(6.1
* 5)
------
0.10