← Back to Streams
Question 724
Ticket Line That Leaves the Stream Untouched
Ticket Line That Leaves the Stream Untouched
Ticketis written for you, with a friend declaration foroperator<<. Define the free functionostream& operator<<(ostream& os, const Ticket& t)below the class so that one ticket prints as a single line: -Ticketthen the id right-aligned in 6 columns padded with0-:then the event name right-aligned in 16 columns padded with.- a space, the seat count right-aligned in 2 columns padded with spaces, thenseats @- the price per seat with two decimals in 6 columns,=, then the subtotal (seats times price) with two decimals in 7 columns -fee:then 5% of the subtotal (FEE_RATE) with two decimals in 6 columns,due:then subtotal plus fee with two decimals in 7 columns, and a newline After your function returns,osmust have exactly the fill character, flags and precision it had before the call: the driver prints a width-6 integer and the plain double3.14159through the same stream afterwards. Write toos, never tocout, and returnos. For the input17,Jazz Night,3 45the driver prints the output shown in Expected Output. Do NOT write a main function.
Expected Output:
Ticket 000017: ......Jazz Night 3 seats @ 45.00 = 135.00 fee: 6.75 due: 141.75 42|3.14159
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsostream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.