Use the
String
class
that we developed in lecture to solve the following assignment.
Having added
translation for C-strings and overflow
protection thereof
and
insertion for all 6 built-in types, Cstring,
and even String,
what abilities can our String
class now claim to have?
Why it can now set width on inserted items, of course!
Unfortunately, it isn't automatic...you'll have to show it how.
Adjust your code to allow your insertion operators to account for the width a user set. (You can even have it work on char data -- unlike the stream's inane version.)
Don't forget to create a test app for your new modifications
(perhaps by adding them to the String
test application)
to show your code works properly.
This assignment is (Level 2).
Add (Level 0.5) to allow the user of your class to specify the fill character.
Add (Level 1.5) to allow the user to set the policy on how to handle data too long for the specified width. (I'd recommend stars, ignore_width, or truncate as good possible policies.) (Hint: This is best done through flags. See how the String class already handles the case_on flag in both its use and management.)
Add (Level 0.5) to allow the user of your class to specify the precision of decimal values (still in fixed notation with a showpoint-like effect in place).
Add (Level 1) to allow the user of your class to specify the justification within the field: left, right, internal, or center. Here's a 'clip' from the ios class to give you some ideas:
enum { left = 1, right = 2, internal = 4, adjustfield = 7 };
(Also see our code for ostream &operator<< for width handling...)