Here are my directions:
Construct a C++ class named “Cruncher” that implements a “factorial” method. The “factorial” method shall take an integer parameter, validate the parameter’s value as being a positive integer, and then calculate the factorial value associated with the parameter’s value. For example, a call such as “cruncher.factorial(5);” will yield a return value of 120, since 5! = 5 * 4 * 3 * 2 * 1. Use a “while” loop to make your calculation.
You will also implement two accessor methods, getMaxFactorial() and getMinFactorial(). These methods will merely return the values of the maxFactorial and minFactorial instance variables, respectively. In other words, they are just simple “get” methods.
You will need to ensure that the values of maxFactorial and minFactorial retain the largest and smallest factorials that have been calculated by the Cruncher object since it was instantiated. This implies that your “factorial” method will check to see if the currently calculated factorial is less than the minFactorial value or greater than the maxFactorial value, and, if so, update the instance variables accordingly.
[Hint: To deal with the initialization of these variables, you can set them to zero. Then, make use of the fact that factorials are necessarily non-zero. The first time your factorial method is called your algorithm will check to see if either instance variable is zero, in which case you will set both instance variables to your calculated factorial value.]
I am supposed to not use cin and also to end up with three files: Main.cpp, crunher.h and cruncher.cpp.
here is what i have to use for main.cpp:
Code:#include “stdafx.h” #include <string.h> #include “Cruncher.h” using std::cout; using std::endl; int main() { Cruncher cruncher; int number = 5; cout << “The factorial of “ << number << “ is” << cruncher.factorial(number) << endl; number = 8; cout << “The factorial of “ << number << “ is” << cruncher.factorial(number) << endl; number = 3; cout << “The factorial of “ << number << “ is” << cruncher.factorial(number) << endl; cout << “The maximum factorial calculated was “ << cruncher.getMaxFactorial() << endl; cout << “The minimum factorial calculated was “ << cruncher.getMinFactorial() << endl; }
Can anyone tell me where to begin with the cruncher.h and cruncher.cpp files?