Question: Write the code in C++ for the following algorithm. Begin converter function Declare int variables deciOrig, deciSave, quotient, Initialize the string sRemainder to empty string
Write the code in C++ for the following algorithm.
Begin converter function
Declare int variables deciOrig, deciSave, quotient,
Initialize the string sRemainder to empty string ""
Define the base array for the 3 divisors: 16, 8, and 2
Create a local stack of strings
priming read decimal (refers to a base 10 number, not floating point)
While not at end of the file2
save deciOrig to deciSave
Print deciOrig to console and fout
Loop through each base array value: 16, 8, 2
Assign base array value to divisor
DO while quotient is not equal to zero
Quotient is saved decimal/divisor
Remainder is decimal mod base divisor
Convert remainder to sRemainder: a string
Push remainder on the stack of strings
Assign quotient to deciSave
End of do While
Assign decimal to deciSaved for the enxt base conversion
Print the entire stack (horizontally) and set width correctly formatted
Re-assign the sRemainder to the empty string ""
End of loop through each base value 16, 8, 2
Make a new line
Read next decimal from file 2
End of loop while not at end of file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
