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 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 program that calculates the occupancy rate for each floor of a hotel. (Use a...
Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations, the program...
Create a program that calculates the average of 3 test scores. Make use of an array...
Create a program that calculates the average of 3 test scores. Make use of an array to store the integer scores. const int size = 3; int testScores[size]; Send this array to a function that actually calculates and returns the average. 1. Tell the user what the program does. 2. Prompt the user to enter the integer scores. ( Use a for loop to do this. ) 3. Create and implement a function with prototype: double average( int a[], int...
Write a program that calculates mean and standard deviation for four user entered values. The most...
Write a program that calculates mean and standard deviation for four user entered values. The most common measures of a sample are the mean and the standard deviation. the mean is the sum of the values divided by the number of elements in the data set. The dispersion - or spread in the values - is measured by the standard deviation The equation for the mean is x¯ = x1 + x2 + · · · + xn The equation...
Question 2: Write a java program that calculates the weighted average of three grades using the...
Question 2: Write a java program that calculates the weighted average of three grades using the method with header public static double CalculateWeightedAverage (double grade1, double grade2, double grade3), such that: [4 Marks] Weighted average = grade1 * 0.5 + grade2 * 0.25 + grade3 * 0.25 The program in the main method will: o ask the user to enter the three grades o and then call the method that will calculate the weighted average o and finally display the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT