Question: Reverse an integer: You will write a class CIS14 and implement its public member function, int reverseInt(int), to reverse an integer. Your program MUST include
Reverse an integer:
You will write a class CIS14 and implement its public member function, int reverseInt(int), to reverse an integer. Your program MUST include this CIS14 class declaration with its public member function BEFORE the placement of your main() function. Remember, no header file is necessary:
class CIS14 { public: int reverseInt(int input); }; Member function to implement:
int reverseInt(int input)
Example #1:
input: 14
returns: 41
Example #2:
input: -14
returns: -41
Example #3:
input: 10
returns: 1
Example #4:
input: 1000
returns: 1
Constraints/Assumptions:
int is equivalent to signed int and there's a range of values; on most of your machines it's a 32-bit integer which means your sizeof(int) should return 4
Your input to reverseInt is always assumed to be in-range. It is the responsibility of the user of your reverseInt() function to make sure that the input doesn't overflow. This responsibility is out of scope for this problem. So, input is assumed to be in-range.
Your function returns 0 when the reversed integer overflows.
Your function input is an int, so inputs such as 01, 001, 002, etc., are not possible
Your function output is also an int, so outputs such as 001, 01, 021, are not possible. You have to convert those into 1, 1, 21, etc respectively. See Hints below.
Grading for this problem is as follows:
Logic: 8 points (-1 point for each test case failure)
Styling/Documentation: 2 points (-1 for wrong function signature, -1 for wrong class declaration, and/or -1 for lack of documentation)
Hints:
Did you notice that the reversed integer might overflow, namely go outside of the 32-bit integer range? For example if your input is 1000000119 its reverse will not be acceptable
Overflow is NOT the same as overload. See http://www.cplusplus.com/reference/climits/ (Links to an external site.)Links to an external site. on INT_MAX
If the integer's last digit is 0, what should the output be? For example cases such as 10, 100, etc. For this problem, 01 is equivalent to 1, 001 is 1, and so on.
Submission:
You should have a total of ONE (1) cpp file for this problem
Follow the EXACT, SAME class/function signature; failure to abide by the exact class/function gets 1 point deduction from your logic.
Your CPP should have your main() and the named function above; no need for header files
You can either leave your main() empty or have your own test cases similar to the following in your submission file. Bottomline is, your CPP file should compile and run!
/* * EXAMPLE (you may choose to have your own implementation style in main()) */ int main() { // instantiate an instance of CIS14 class CIS14 cis14; // invoke this instance's member function one by one cout << cis14.reverseInt(1) << endl; cout << cis14.reverseInt(123) << endl; ... return 0; } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
