Ticket Factory Returns a Heap Ticket
mediumQuestion 698Write a class Ticket plus a free (non-member) factory function that builds one on the heap.
Ticket private members:
- int id;
- int price;
Public interface used by the hidden driver:
Ticket(int id, int price);
int getId() const;
int getPrice() const;Then write the factory, OUTSIDE the class:
Ticket* makeTicket(int id, int basePrice, bool isStudent);It must return a pointer to a NEW Ticket every time it is called. A student ticket costs basePrice / 2 using integer division; anyone else pays basePrice.
The driver reads id basePrice isStudent (isStudent is 1 or 0), asks the factory for two tickets, prints them, and deletes both.
For the input:
41 80 1the exact output is what is shown in Expected Output.
Free the memory you allocate — this question checks for memory leaks.
Do NOT write a main function.
Expected output
Ticket 41 costs 40 Ticket 42 costs 80 separate=1
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
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.