I currently have a method, that accepts 2 ints as parameters,and returns their a
ID: 3617563 • Letter: I
Question
I currently have a method, that accepts 2 ints as parameters,and returns their average. I need to overload the method to accept3, or 4 integers as parameters and return their average. How do Igo about this? My textbook describes how overloading works, butdoesn't give much guidance as to how to get it to work. Thanks. I currently have a method, that accepts 2 ints as parameters,and returns their average. I need to overload the method to accept3, or 4 integers as parameters and return their average. How do Igo about this? My textbook describes how overloading works, butdoesn't give much guidance as to how to get it to work. Thanks.Explanation / Answer
#include <iostream>
int num(intu, int i, int y);
int num(intu, int i, int y, into);
using namespace std;
int main()
{
int h,u,i,o, num3,num4;
cout << "Please enter your numbers andI'll tell the average of those numbers: ";
cin >> h >> u >> i >>o;
num3 = num(h,u,o);
num4 = num(h,u,o,i);
cout << "Average for 3numbers " << num3<<endl;
cout << "Average for 4numbers " <<num4;
return 0;
}
int num(intu, int i, int y)
{
int average, sum;
sum = u + i + y;
return sum / 3;
}
int num(intu, int i, int y, into)
{
int sum;
sum = u + i + y + 0;
return sum / 4;
}
Related 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.