For this problem you will write two functions and place them in someFunctions.cp
ID: 3544446 • Letter: F
Question
For this problem you will write two functions and place them in someFunctions.cpp. someFunctions.cpp should only contain the two functions described below and should not contain a main() function.
In C++, two functions can have the same name as long as if their parameter types or number are different. This concept is called overloading. (See http://www.cplusplus.com/doc/tutorial/functions2/#function_overload.) The compiler chooses which function to call based upon the parameters. In someFunctions.cpp , place two functions, both named add, one of which returns the sum of its two double parameters, and one of which returns the sum of its three double parameters. Here are the function prototypes:
double add(double num1, double num2);
double add(double num1, double num2, double num3);
Provided on the assignment page is a separate test program called testSomeFunctions.cpp. To compile both source files at the same time, use
g++ someFunctions.cpp testSomeFunctions.cpp
If you use Eclipse, put both source files in the same project.
As discussed in class, each function should be preceded by a comment that describes what the function does, along with a description of each input parameter and a description of the function's return value. See the Coding Standard on the class website for a detailed description of function comments. Here is an example of comments you could use for one of the functions:
Explanation / Answer
please rate - thanks
double add(double num1, double num2)
{return num1+num2;
}
double add(double num1, double num2, double num3)
{return num1+num2+num3;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.