CJCoding With Joseph
15free / daySign inCreate account

Ticket Factory Returns a Heap Ticket

Write 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 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
Topics:
Pointers
📥 Auto-Input:
41 80 1\n
This input is automatically fed to your program's stdin
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.