In: Mechanical Engineering
Write a program that calculates the average of a four lab marks. It should use the following functions:
• void getMarks() should ask the user for a lab marks, store it in a reference parameter variable, and validate it so that lab marks lower than 0 or higher than 100 is not accepted. This function should be called by main once for each of the four lab marks to be entered.
• void avgGradeDisp() should calculate and display the average of the four lab marks rounded to the nearest whole number. It should also display the grade of the average lab marks obtained by the student as per the table given below.
Lab Marks Grade GPA 75 - 100 A 3 65-74 B 2 50-64 C 1 0-49 F 0
#include <iostream>
#include <cmath>
using namespace std;
float L1;
float L2;
float L3;
float L4;
float av;
void getMarks(){
float &ref1 {L1};
float &ref2 {L2};
float &ref3 {L3};
float &ref4 {L4};
cout<<"lab 1 marks here ";
cin >> ref1;
while (0>ref1 || ref1>100){
cout<<"please between 0 and 100 for lab 1 marks ";
cin >> ref1;
}
cout<<"lab 2 marks here ";
cin >> ref2;
while (0>ref2 || ref2>100){
cout<<"please between 0 and 100 for lab 2 marks ";
cin >> ref2;
}
cout<<"lab 3 marks here ";
cin >> ref3;
while (0>ref3 || ref3>100){
cout<<"please between 0 and 100 for lab 3 marks ";
cin >> ref3;
}
cout<<"lab 4 marks here ";
cin >> ref4;
while (0>ref4 || ref4>100){
cout<<"please between 0 and 100 for lab 4 marks ";
cin >> ref4;
}
}
void avgGradeDisp(){
float &ref {av};
ref= (L1+L2+L3+L4)/4;
cout << "ROUNDED AVERAGE::----> " <<
round(av);
if (0<=ref && ref<=49){
cout << "\n GRADE::----> F";
}
else if (50<=ref && ref<=64){
cout << "\n GRADE::----> C";
}
else if (65<=ref && ref<=74){
cout << "\n GRADE::----> B";
}
else if (75<=ref && ref<=100){
cout << "\n GRADE::----> A";
}
}
int main()
{
getMarks();
avgGradeDisp();
return 0;
}