This is C++ question, not public class Create two overloaded functions called su
ID: 3873409 • Letter: T
Question
This is C++ question, not public class
Create two overloaded functions called sumLast. The first function will take as parameters two int variables. The second function will take as parameters three int variables. The functions will return the sum of the last digits in the integer.
Example:
Given two variables
int x = 143, y = 3901;
The last two digits of the variables are 3 and 1. Given these values then your two argument function will return 4.
NOTE:
You are not allowed to convert any of the parameters to a string. Do your best to eliminate as much duplicate code as you can.
Explanation / Answer
Hey, Here's the solution to your question in C++, kindly let me know if you have any doubts.
Overloading.cpp:
#include <iostream>
using namespace std;
class Overloading {
public:
//Overloaded functions
//number%10 returns the last digit of number
int sumLast(int x, int y, int z) {
return x%10 + y%10 + z%10;
}
int sumLast(int x, int y) {
return x%10 + y%10;
}
};
int main(void) {
Overloading overloadingObj;
// Call to return sum of the last digits
cout << overloadingObj.sumLast(143,3901) <<" ";
cout << overloadingObj.sumLast(5,52,1) <<" ";
return 0;
}
Output:
4
8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.