Question

In: Mechanical Engineering

Write a program that calculates the average of a four lab marks. It should use the...

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

Solutions

Expert Solution

#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;
}


Related Solutions

Write a program that calculates the salary of employees. The program should prompt the user to...
Write a program that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
Please use Phyton to write a program: Write a program that calculates and displays the total...
Please use Phyton to write a program: Write a program that calculates and displays the total bill at a restaurant for a couple that is dining. The program should collect from the couple, cost of each meal, and the percentage of the final cost that they would like to tip. The sales tax in the state where the restaurant exists is 7.5%. Display to the user, line by line: Total Cost of Both Meals Sales Tax in dollars Tip in...
Write a program that calculates the area and circumference of a circle. It should ask the...
Write a program that calculates the area and circumference of a circle. It should ask the user first to enter the number of circles n, then reads the radius of each circle and stores it in an array. The program then finds the area and the circumference, as in the following equations, and prints them in a tabular format as shown in the sample output. Area = πr2 , Circumference = 2πr, π = 3.14159 Sample Output: Enter the number...
Write a program in C++ that calculates the sum of two fractions. The program should ask...
Write a program in C++ that calculates the sum of two fractions. The program should ask for the numerators and denominators of two fractions and then output the sum of the two fractions. You will need to write four functions for this program, one to read the inputted data, one to calculate the sum of the two fractions, one to find the Greatest Common Divider (GCD) between the numerator and denominator and a function that will display the end result....
Write a program that calculates the average of a group of test scores, where the lowest...
Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions: void getScore() should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered. void calcAverage() should calculate and display the average of the four highest scores. This function...
Write a program that calculates the average of upto 100 English distances input by the user....
Write a program that calculates the average of upto 100 English distances input by the user. Create an array of objects of the Distance class, as in the ENGLARAY example in this chapter. To calculate the average, you can borrow the add_dist() member function from the ENGLCON example in Chapter 6. You’ll also need a member function that divides a Distance value by an integer. Here’s one possibility: void Distance::div_dist(Distance d2, int divisor) { float fltfeet = d2.feet + d2.inches/12.0;...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of test scores where the lowest score is dropped. It should use the following functions a) void getScores should have 4 double reference parameters (one for each test score) getScores should do the following: - read 4 test scores from the text file Lab11C.txt (Important: declare your ifstream infile and open the file inside this function, not in the main function) - store them in...
Write a C program that calculates the average grade for a specified number of students from...
Write a C program that calculates the average grade for a specified number of students from each student's test1 and test2 grades. The program must first ask the user how many students there are. Then, for each student, the program will ask the user for the test1 grade (grade #1) and test2 grade (grade #2). The program should be able to handle up to 100 students, each with 2 grades (test1 and test2). Use a two-dimensional float array to store...
Write a C program that calculates the average grade for a specified number of students from...
Write a C program that calculates the average grade for a specified number of students from each student's termtest and final grade. The program must first ask the user how many students there are. Then, for each student, the program will ask the user for the termtest grade (grade #1) and final grade (grade #2). The program should be able to handle up to 100 students, each with 2 grades (termtest and final). Use a two dimensional float array to...
Write a python program that calculates the average number of words per sentence in the input...
Write a python program that calculates the average number of words per sentence in the input text file. every sentence ends with a period (when, in reality, sentences can end with !, ", ?, etc.) and the average number of sentences per paragraph, where a paragraph is any number of sentences followed by a blank line or by the end of the text.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT