IN C++ PLEASE CODE THE FOLLOWING Given int std1, std2, std3, std4, std5, avegrad
ID: 3733592 • Letter: I
Question
IN C++ PLEASE CODE THE FOLLOWING
Given
int std1, std2, std3, std4, std5, avegrade;// avegrade is the average of the 5 grades
std1 = 87;
std2 = 90;
std3 = 67;
std4 = 72;
std5 = 78; // as grades of five students
avegrade = 0;
Write a program to perform the following tasks.
I. declare and initialize std1, std2, std3, std4, std5, and avegrade as above.
II. compute the average grade of the five students and assign it to avegrade, and then display the
average grade on the screen.
III. Using if – else statement:
If the avegrade is >= 80, display message “A level” on the screen.
If the avegrade is >= 60 and < 80, display message “B level” on the screen.
If the avegrade is < 60, display message “C level“ on the screen.
Explanation / Answer
C++ code according to the given requirements:
#include<iostream>
using namespace std;
//functin definition
string Day(char);
//main function
int main()
{
//declare and initialize std1, std2, std3, std4, std5, and avegrade
int std1, std2, std3, std4, std5;
//in order to get decimal values in average, avegrade variable should be double
double avegrade; // avegrade is the average of the 5 grades
std1 = 87;
std2 = 90;
std3 = 67;
std4 = 72;
std5 = 78;
avegrade = 0; // as grades of five students
//compute the average grade of the five students and assign it to avegrade,
avegrade=double(std1+std2+std3+std4+std5)/5;
//displaying average grade on the screen
cout<<"Average Grade: "<<avegrade<<endl;
//Using if – else statement:
if(avegrade >= 80)
cout<<"A level"<<endl;
else if(avegrade >= 60 && avegrade < 80)
cout<<"B level"<<endl;
if(avegrade <60)
cout<<"C level"<<endl;
}
Output:
Average Grade: 78.8
B level