1. (30 points) Grading system 90 and above, display \"A\" 80 to 89, display \"B\
ID: 3599566 • Letter: 1
Question
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 , 2. (30 points) Write a program using while(cin>x to 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:coutExplanation / Answer
#include <iostream>
using namespace std;
int main()
{
int grade;
cout<<"Enter the grade: "<<endl;
cin >> grade;
if(grade >= 90) {
cout<<"A"<<endl;
} else if(grade >=80 && grade < 90) {
cout<<"B"<<endl;
} else if(grade >=70 && grade < 80) {
cout<<"C"<<endl;
} else if(grade >=60 && grade < 70) {
cout<<"D"<<endl;
} else {
cout<<"F"<<endl;
}
return 0;
}
Output:
#include <iostream>
using namespace std;
int main()
{
int x, sum = 0, count = 0;
cout<<"Enter the numbers (- 1 to quit): "<<endl;
cin >> x;
while(x!= -1) {
count++;
sum+=x;
cin >> x;
}
cout<<"Sum: "<<sum<<endl;
cout<<"Average: "<<(sum/(double)count)<<endl;
return 0;
}
Output:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float x, sum = 0;
int count = 0;
cout<<"Enter the numbers (- 1 to quit): "<<endl;
cin >> x;
while(x!= -1) {
count++;
sum+=x;
cin >> x;
}
cout<<fixed<<setprecision(2)<<"Sum: "<<sum<<endl;
cout<<fixed<<setprecision(2)<<"Average: "<<(sum/count)<<endl;
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.