Question
home / study / engineering / computer science / questions and answers / in c++ you must use the io manipulators hex, oct, ... Your
home / study / engineering / computer science / questions and answers / in c++ you must use the io manipulators hex, oct, ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: IN C++ You MUST use the IO manipulators hex, oct, ... Bookmark IN C++ You MUST use the IO manipulators hex, oct, dec, showbase, right, and internal, in this program Output a formatted table with four columns, one each for Decimal, Octal, Hexadecimal and Binary in that order. Each column must have a right justified heading, and a separator line below the headings. Columns should be separated by blank space. Do not use tabs in this assignment. Do not hard-format the headings use setw() for each column's heading, just like for its data. Data in the table must be justified as shown below. Each column must be formatted with one or more uses of setw() and fillchar(), as required. Set the width of each column as shown in the following table: Column Width Notes Decimal 8 No prefix, right justified, leading blanks. Hexadecimal 12 0x prefix, right justified, internally zero padding, minimum 4 digits (i.e., 0x0001) This column requires special handling to ensure the leading 0's are between the 0x and the number, NOT to the left of the prefix. This is one of the rare cases internal justification is required, but it really screws up right justifying the actual numeric output! The trick is to compute the number of leading blanks needed to ensure the number, with prefix and internal zeros, is output to the right, and output an EMPTY string formatted to that computed width. Octal 15 0 prefix, no minimum/max digits, right justified. Binary 22 C++ doesn't have binary literals, but C++15 will introduce the "0b" prefix which you will our for your program's output. Minimum 8 digits, maximum of 16 digits. Your binary output must pad the binary output to the minimum with leading zeros, and ideally group digits by fours. Thus, decimal 17 is 0b0001_0001 For Base 10, 16, and 8 output decimal, hexadecimal, and octal you will use C++'s builtin numeric formatting manipulators, dec, hex, and oct. However, there is no builtin manipulator for binary. You will need to write your own function for conversion to binary. You function must have the following prototype: string convertToBase ( unsigned num, unsigned base = 2); // convert num to string of digits in given base, default to base 2. // You *must* support base 2, and it is easier to write it to handle // conversion to all bases 2-16. Bases >16 are not required. // Just for grins see the Number System Refresher document in Canvas OR... // Note that the algorithm is the same as in your Written Number program. // Here we just want digit characters, not words, and there is no // repetition on every n-digits (though the repetition would make separation // easy to do). Use this array: static char digits[] = "0123456789ABCDEF"; For Base 10, 16, and 8 output, the prefix must be printed using the showbase manipulator. Since this is sticky, I suggest you turn on showbase formatting before any other output. The actual numeric content in the table is trivial and essentially meaningless except you should see some patterns non-decimal bases! Use a loop to produce the first 33 rows of the table, counting from 0 to 32, inclusive. If you ask me what kind of loop my head will literally explode. Seriously. After exiting the loop, print three rows for each the following numbers N in {64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536} There should be one row for each value (N-1), (N), and (N+1). For example, for the first number 64 you need to output rows the values 63, 64, and 65. Ignore this text box You must write a function to convert an unsigned integer input to a string of characters for each base. Your function is responsible for leading padding, and for appropriate numeric prefixes. The prototype for this function must be as shown below: string convertToBase ( unsigned num, unsigned base ); Examples: convertToBase ( 13, 2 ) "0b1101" -- no padding, but "0b" prefix convertToBase( 13, 10 ) "13" convertToBase( 13, 16 ) "0xD" convertToBase( 13, 5 ) "23" -- Check it, "23" in base 5 2*5 + 3 = 13 Between each group of output, print a separating line of periods (formatted to the width of the table!)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started