COMP 322 Assignment 2: Exploring Classes. solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

Question 1 (5 pts)
Complete the implementation for the class SuperDraw by implementing the constructor
and the destructor bodies if needed. Constructor should be initializing the object to
whatever initial suitable state.
2
Question 2 (15 pts)
Add a public method called newTicket(int verbose = 0) that generates random 6 numbers.
The newly created ticket should be added to the linked list and the randomly generated
numbers should be printed out to the screen if verbose argument is set to 1. By default the
verbose argument is set to 0 which means that no messages will be printed out to the
screen.
The numbers should be sorted in ascending order.
Remember that the pointers ticketListHead and ticketListTail should be updated
accordingly after the generation of each new ticket
The test main() function should look like the following:
int main()
{
SuperDraw sd;
sd.newTicket(1);
}
The output should be something like:
A new ticket was successfully generated. The numbers are: 12, 14, 23, 39, 40, 44
Question 3 (10 pts)
Add a constructor that takes an int argument which corresponds to the number of tickets
to be generated.
The test main() function should look like the following:
int main()
{
SuperDraw sd(2);
}
The output should be something like:
3
2 new ticket were successfully generated.
The numbers are: 12, 14, 23, 39, 40, 44 and 1, 2, 9, 12, 28, 41
Question 4 (15 pts)
Add a public method called printAllTicketNumbers() that print to the screen a list of all
generated numbers for all the tickets.
The test main() function should look like the following:
int main()
{
SuperDraw sd;
sd.newTicket();
sd.newTicket();
sd.newTicket();
sd.newTicket();
sd.printAllTicketNumbers();
}
The output should be something like:
We found 4 generated tickets:
12, 14, 23, 39, 40, 44
1, 5, 12, 14, 32, 33
2,24, 27, 29, 45, 46
8, 12, 19, 29, 32, 34
4
Question 5 (15 pts)
Add a method called verifySequence() that verifies if a certain sequence of numbers is
already generated.
The test main() function should look like the following:
int main()
{
SuperDraw sd;
sd.newTicket();
// as many sd.newTicket() as you like
Int myNumbers[6] = {2, 4, 17, 29, 31, 34}
sd.verifySequence(myNumbers)
}
The output should be something like:
The provided sequence of numbers was never generated before
Or:
The provided sequence of numbers was already generated.
Question 6 (15 pts)
Add a method called deleteSequence() that deletes a ticket. Note that in order to delete a
ticket, you have to verify first whether a ticket existed, if so you need to delete it by freeing
its allocated memory and then you need to update the next pointer of the previous element
in the list that was initially pointing to it.
The test main() function should look like the following:
int main()
{
SuperDraw sd;
sd.newTicket();
// as many sd.newTicket() as you like
Int myNumbers[6] = {2, 4, 17, 29, 31, 34}
5
sd.deleteSequence(myNumbers)
}
The output should be something like:
The provided sequence of numbers was never generated before
Or:
The provided sequence of numbers was successfully deleted.
Question 7 (10 pts)
Provide an implementation for the destructor method that ensures that all previously
allocated tickets are freed when the object is destroyed so that we don’t risk having
memory leaks after running the program.
Question 8 (15 pts)
Provide a copy constructor that copies the content of a SuperDraw object into another
object.
The test main() function should look like the following:
int main()
{
SuperDraw sd;
sd.newTicket();
// as many sd.newTicket() as you like
SuperDraw sd2(sd);
sd2.printAllTicketNumbers();
}
6