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

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 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 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...
Write a program that calculates the balance of a savings account at the end of a...
Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following: Ask the user for the total amount deposited into the account during that month. Do not accept negative numbers. This amount should be added to the balance. Ask the user for the...
Write a program that calculates the balance of a savings account at the end of a...
Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number of months that have passed since the account was established. A loop should then iterate once for every month, performing the following: Ask the user for the amount deposited into the account during the month. (Do not accept negative numbers.) This amount should be added...
Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has.
Use JAVAProgram #1: Hotel Occupancy: Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration of the for loop, the program should ask the user for the number of rooms of the floor and how many of them are occupied. After all of the iterations are complete the program should display how...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT