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

ooo AT&T; LTE 16:26 texsu.blackboard.com ELET 422-01 Homework 5 Due at 11:30 am,

ID: 3597243 • Letter: O

Question

ooo AT&T; LTE 16:26 texsu.blackboard.com ELET 422-01 Homework 5 Due at 11:30 am, Tuesday October 24, 2017 No credit after 5:00 pm, Monday, March 30, 2017 Name: Use Word to process your homework and submit to Blackboard is mandatory Directly copy the source code and paste into the Word file. Screenshot of running result must be presented. 1. (30 points) Grading system 90 and above, display "A" -80 to 89, display "B" 70 to 79, display "C" -60 to 69, display "D” -59 and below, display "P" ile(cins x) to 2. (30 points) Write a program using vw get several integer numbers, calculate the average and display the result on the screen. 3. (40 points) Write a program using while (cin>>x) to get several float numbers, calculate the average and display the result on the screen. Use setprecision to display two digits after decimal point. (Hint: std::cout std::fixed;)

Explanation / Answer

1st...

#include<iostream>
using namespace std;
int main(){
   int sum=0,average,n=0,x;
   while(cin >> x){
       sum += x;
       n++;
   }  
   average = sum/n;
   cout << average;
}

output:

65

D

99

A

82

B

32

F

---------------------------------------------------------------------------------

2.....

#include<iostream>
using namespace std;
int main(){
   int sum=0,average,n=0,x;
   while(cin >> x){
       sum += x;
       n++;
   }  
   average = sum/n;
   cout << average;
}

output:

5
6
4
h //other than integer to break the loop
5

--------------------------------------------------------------------------------

3.......

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
   float sum=0,average,n=0,x;
   while(cin >> x){
       sum += x;
       n++;
   }  
   average = sum/n;
   std::cout << std::fixed;
   std::cout << std::setprecision(2);
   std::cout << average;
}

output:

4.3
2.3
2.3
2.3
2.3
2.3
s //other than float to break the loop
2.63