Write a program that overloads functions. The program will determine the average
ID: 3624976 • Letter: W
Question
Write a program that overloads functions. The programwill determine the average of 3 integers and the average
of 3 doubles.
You should call a function to get user input for 3 integers
and another function to get user input for 3 doubles. The
functions should have the same return type (void) and the
same name: getNumbers.
Then create 2 overloaded functions to return the average.
Those functions should return a double and be named getAverage.
Then back in main display the averages.
Explanation / Answer
#include using namespace std; void getNumbers(int &x, int &y, int &z) { cout > x; cout > y; cout > z; } void getNumbers(double &x, double &y, double &z) { cout > x; cout > y; cout > z; } int getAverage(int x, int y, int z) { return (x+y+z)/3; } double getAverage(double x, double y, double z) { return (x+y+z)/3.0; } int main() { int x,y,z; double xd,yd,zd; int intAverage; double doubleAverage; getNumbers(x,y,z); getNumbers(xd,yd,zd); intAverage = getAverage(x,y,z); doubleAverage = getAverage(xd,yd,zd); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.