Question: C++ - Reverse Digit Problem : Certain mathematical problems involve manipulation of the digits within a decimal number. One such problem requires that the digits
C++ - Reverse Digit
Problem: Certain mathematical problems involve manipulation of the digits within a decimal number. One such problem requires that the digits be reversed.
Your assignment: Write and test an Object-Oriented C++ program that removes leading and trailing zeroes from an integer and then reverses the remaining digits. For example, the reversed value of 123450 is 54321, the reversed value of 005600 is 65; and the reversed value of -532 is -235. Develop a user-defined Number class to perform all the digit manipulations
Discussion: Extracting the digits from a decimal number involves repeated modulus and divide by 10 operations or conversion of the number to a printable string. Either method will work. How your Number class functions internally should be transparent to the user, e.g. there should be no cases in which the inner workings of the Number class produce unique results. Consider the following
The Number class should have a single instance variable of type integer and a method named reverse() that reverses the digits in the instance variable. Reversing the digits should not modify the value of the instance variable, but should create a new value and return that new value to the user as an integer.
Your program must read an indefinite series of integers from the console (as integers, no string input allowed). Use a single instance of the Number class to convert each input value to its reversed value. Stop when the user enters a value of zero.
For each input value, display the input value and the value returned from the reverse() method.
Coding
Each class must be defined within its own set of .h and .cpp files.
The program must accept any valid signed integer as input.
Validate all inputs and do not proceed until valid values are entered. Format your source code according to the style guide presented in class.
Bonus
Extend the Number class to include a method that will sort the digits from the input value after the leading and trailing zeroes are removed, returning a new integer with all its digits in ascending order. For instance, if the input value is -0315863, the sorted value would be 133568. The sign of the input value should be discarded for this output.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
