Write a C++ program called
that behaves as the program from from HW1, except that it:
Now, instead of simply producing vnums, the program will produce tagged output. Each vnum will be preceded by an identifying character:
s: short (fits in a signed 16-bit integer)
i: int (fits in a signed 32-bit integer)
l: long (fits in a signed 64-bit integer)
c: char (a single eight-bit character)
S: string (a string of characters)
The program must figure out which category (short/int/long) a number should go into.
For example, the number three, since it fits into a short,
would be tagged with an
The number one billion, which fits into an int, would be
tagged with an
69 40 3b 9a ca 00
The serialized output for a character is simply a
c followed by the
character. For example,
'x' would be serialized as:
A string is serialized as follows:
"Jack" would be serialized as:
53 04 4a 61 63 6b
Don’t be fooled by
04. That is not a simple byte containing
the value 4. That is a vnum that happens to be a single byte,
because 4 (the length of “Jack”) fits into the bottom four bits of a vnum.
A longer string might have a multibyte vnum representing its length.
Here is a sample run. “%” is my prompt:
% cat sample-input 5 300 -1 1 2 -3 40 500 -6000 70000 1000000000 'a' 'b' ' ' "Jack Applin" % ./hw2 sample-input 73 05 73 11 2c 73 0f 73 01 73 02 73 0d 73 10 28 73 11 f4 73 2f e8 90 69 21 11 70 69 40 3b 9a ca 00 63 61 63 62 63 20 53 10 0b 4a 61 63 6b 20 41 70 70 6c 69 6e %
// Here’s how to convert a char to an int: int n = 'S'; // It’s just that easy. cout << hex << n;
or via the shell:
% echo -n silcS | xxd 0000000: 7369 6c63 53 silcS
or going from hex to characters:
% echo -e '\u4a\u61\u63\u6b' Jack
The requirements are the same as those for HW1, plus:
", emit an error message and terminate the program.
If you have any questions about the requirements, ask. In the real world, your programming tasks will almost always be vague and incompletely specified. Same here.
*.h) (if any)
Makefile, with a capital
Makefile’s default target must create the executable file
Makefilemust use at least
~cs253/bin/checkin HW2 hw2.tar
Turn in someone else’s work.