Assignment: Modify your Program #3 three times using the while, do while and for
ID: 3888542 • Letter: A
Question
Assignment: Modify your Program #3 three times using the while, do while and for loops. You will have 3 programs for this assignment Programda (uses a while loop), Programdb (uses a do while) and Program 4c (uses a for loop). to process the letter grade (of Program #2 and Program #3 Each program will process 10 grades (int) and produce the letter grade using the switch statement from Program #3 Additionally, each program sums the grades and calculates the average. Note: Do not use any structures that we haven't covered in class or that have not been required in the programming assignment. de Input and Output: In each iteration of each loop, prompt the user for the (int) grade and print the grade just read and its associated letter grade. Compute the average of these 10 grades. When the program is done reading in the ten grade values and printing the associated letter grades then print the average. Make sure you print meaningful and helpful text for both the program input and output. the average lil le surew t0 grades Wnen ther i Test Document: None required for this program. Programs Directory: Make sure that each program - Program4a, Program4b and Program4c- are all in your PROGRAMS directory in your csci2 account.Explanation / Answer
Given below modified versions of the program as specified by the question. Hope it helps. If it does, please do rate the answer. Thank you very much.
Program4a.cpp
#include <iostream>
using namespace std;
int main()
{
int grade;
char letterGrade;
int i = 1;
int n = 10;
int total = 0;
while( i <= n)
{
cout << " Enter your grade(score) " << i << " :";
cin >> grade;
while(grade > 100)
{
cout << " Grade cannot be greater than 100 ";
cout << " Enter a valid grade(score):";
cin >> grade;
}
if(grade < 60)
{
letterGrade = 'F';
}
else if(grade >= 60 && grade <=69)
{
letterGrade = 'D';
}
else if(grade >= 70 && grade <=79)
{
letterGrade = 'C';
}
else if(grade >= 80 && grade <=89)
{
letterGrade = 'B';
}
else if(grade >= 90 && grade <=100)
{
letterGrade = 'A';
}
switch(letterGrade)
{
case 'F':
cout << "You received a 'F'? Oh no! Time to put in deep effort!";
break;
case 'D':
cout << "You received a 'D'? Oh no! Hit those books!";
break;
case 'C':
cout << "You received a 'C'..You can do better!";
break;
case 'B':
cout << "You received a 'B'..That is a good job!";
break;
case 'A':
cout << "You received a 'A'..Great! That is nice!";
break;
}
total += grade; // add the grade to total
i++; //increment i
}
double avg = ((double) total) / n;
cout << " Average = " << avg << endl;
return 0;
}
Program4b.cpp
#include <iostream>
using namespace std;
int main()
{
int grade;
char letterGrade;
int i = 1;
int n = 10;
int total = 0;
do
{
cout << " Enter your grade(score) " << i << " :";
cin >> grade;
while(grade > 100)
{
cout << " Grade cannot be greater than 100 ";
cout << " Enter a valid grade(score):";
cin >> grade;
}
if(grade < 60)
{
letterGrade = 'F';
}
else if(grade >= 60 && grade <=69)
{
letterGrade = 'D';
}
else if(grade >= 70 && grade <=79)
{
letterGrade = 'C';
}
else if(grade >= 80 && grade <=89)
{
letterGrade = 'B';
}
else if(grade >= 90 && grade <=100)
{
letterGrade = 'A';
}
switch(letterGrade)
{
case 'F':
cout << "You received a 'F'? Oh no! Time to put in deep effort!";
break;
case 'D':
cout << "You received a 'D'? Oh no! Hit those books!";
break;
case 'C':
cout << "You received a 'C'..You can do better!";
break;
case 'B':
cout << "You received a 'B'..That is a good job!";
break;
case 'A':
cout << "You received a 'A'..Great! That is nice!";
break;
}
total += grade; // add the grade to total
i++; //increment i
}while(i <= n);
double avg = ((double) total) / n;
cout << " Average = " << avg << endl;
return 0;
}
Program4c.cpp
#include <iostream>
using namespace std;
int main()
{
int grade;
char letterGrade;
int n = 10;
int total = 0;
for(int i = 1; i <= n; i++)
{
cout << " Enter your grade(score) " << i << " :";
cin >> grade;
while(grade > 100)
{
cout << " Grade cannot be greater than 100 ";
cout << " Enter a valid grade(score):";
cin >> grade;
}
if(grade < 60)
{
letterGrade = 'F';
}
else if(grade >= 60 && grade <=69)
{
letterGrade = 'D';
}
else if(grade >= 70 && grade <=79)
{
letterGrade = 'C';
}
else if(grade >= 80 && grade <=89)
{
letterGrade = 'B';
}
else if(grade >= 90 && grade <=100)
{
letterGrade = 'A';
}
switch(letterGrade)
{
case 'F':
cout << "You received a 'F'? Oh no! Time to put in deep effort!";
break;
case 'D':
cout << "You received a 'D'? Oh no! Hit those books!";
break;
case 'C':
cout << "You received a 'C'..You can do better!";
break;
case 'B':
cout << "You received a 'B'..That is a good job!";
break;
case 'A':
cout << "You received a 'A'..Great! That is nice!";
break;
}
total += grade; // add the grade to total
}
double avg = ((double) total) / n;
cout << " Average = " << avg << endl;
return 0;
}
output
Enter your grade(score) 1 :78
You received a 'C'..You can do better!
Enter your grade(score) 2 :67
You received a 'D'? Oh no! Hit those books!
Enter your grade(score) 3 :90
You received a 'A'..Great! That is nice!
Enter your grade(score) 4 :87
You received a 'B'..That is a good job!
Enter your grade(score) 5 :54
You received a 'F'? Oh no! Time to put in deep effort!
Enter your grade(score) 6 :45
You received a 'F'? Oh no! Time to put in deep effort!
Enter your grade(score) 7 :79
You received a 'C'..You can do better!
Enter your grade(score) 8 :60
You received a 'D'? Oh no! Hit those books!
Enter your grade(score) 9 :99
You received a 'A'..Great! That is nice!
Enter your grade(score) 10 :95
You received a 'A'..Great! That is nice!
Average = 75.4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.