Question

In: Computer Science

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 the reference parameters

b) void calcAverage (4 double parameters) should do the following:

- call findLowest passing the test scores as parameters

- total the 4 scores and subtract the result returned by findLowest

- this will leave you with the total of 3 test scores, so divide the total by 3

- print the average with a label

c) double findLowest (so it has 4 double parameters) should find and return the lowest of the 4 scores passed to it.

​​​​​​​​​​​​​​d) In the main function

- call getScores sending 4 double variables as parameters

- call calcAverage sending those 4 double variables

Note about reference parameters: remember that with reference parameters, you will use the & in the top line of the function itself, but you will not use the & in the call to the function in main.

Solutions

Expert Solution

Main Code :

#include<iostream>
#include<fstream>
using namespace std;
void getScores(double &a,double &b,double &c,double &d)
{
ifstream f;
f.open("Lab11C.txt");
if(!f)
cout<<"Unable to open the file";
else
{
f>>a;
f>>b;
f>>c;
f>>d;
}
f.close();
}
double findLowest(double a,double b,double c,double d)
{
if((a<b)&&(a<c)&&(a<d))
return a;
else if((b<c)&&(b<d))
return b;
else if(c<d)
return c;
else
return d;
}
void calcAverage(double a,double b,double c,double d)
{
double low=findLowest(a,b,c,d);
double tot=a+b+c+d;
tot=(tot-low)/3;
cout<<"Average = "<<tot;
}
int main()
{
double a,b,c,d;
getScores(a,b,c,d);
calcAverage(a,b,c,d);
}

File : Lab11C.txt

Output :


Related Solutions

Write a C++ program named, myGrade.cpp, that calculates a letter grade for a student of this...
Write a C++ program named, myGrade.cpp, that calculates a letter grade for a student of this course (CSC100 online) based on three user inputs. This program should begin by printing the title of the application (program) and a brief description of what it does. (Note: this is NOT the same as the program prolog: a prolog is much more detailed, has required elements, and is intended for other programmers reading the cpp file. The title and description displayed by the...
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 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 program named MakeChange that calculates and displays the conversion of an entered number of...
Write a program named MakeChange that calculates and displays the conversion of an entered number of dollars into currency denominations—twenties, tens, fives, and ones. For example, if 113 dollars is entered, the output would be twenties: 5 tens: 1 fives: 0 ones: 3. Answer in C# (P.S i'm posting the incomplete code that i have so far below.) using System; using static System.Console; class MakeChange { static void Main() { int twenties, tens, fives, ones; WriteLine("Enter the number of dollars:");...
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...
using C# Write a program named RectangleArea tocalculate the area of a rectangle with a...
using C# Write a program named RectangleArea to calculate the area of a rectangle with a length of 15.8 and a width of 7.9. The program should have two classes, one is theRectangleArea holding the Main(), and the other one is Rectangle. The Rectangleclass has three members: a property of length, a property of width, and a method with a name of CalArea() to calculate the area. You can invoke the auto-provided constructor or write a self-defined constructor to initialize...
using C++ 23. Savings Account Balance Write a program that calculates the balance of a savings...
using C++ 23. Savings Account Balance 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 steps: A) Ask the user for the total amount deposited into the account during that month and add it to the balance. Do not accept negative...
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...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT