← Back to Pointers
Question 698
Ticket Factory Returns a Heap Ticket
Ticket Factory Returns a Heap Ticket
Write a classTicketplus a free (non-member) factory function that builds one on the heap.Ticketprivate 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 NEWTicketevery time it is called. A student ticket costsbasePrice / 2using integer division; anyone else paysbasePrice. The driver readsid basePrice isStudent(isStudent is 1 or 0), asks the factory for two tickets, prints them, anddeletes both. For the input:`41 80 1`` the 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 — 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.