Question

In: Computer Science

In the following questions you will be designing a class called SuperDraw to generate lotto numbers...

In the following questions you will be designing a class called SuperDraw to

generate lotto numbers and manage the process of verifying whether a ticket

is a winner. Every lotto ticket has 6 numbers generated randomly between 1

and 49. A number cannot be repeated in the same ticket.

The main SuperDraw class structure should look like the following:

struct ticket

{

unsigned int numbers[6];

ticket* next;

};

class SuperDraw

{

private:

ticket* ticketListHead;

ticket* ticketListTail;

public:

SuperDraw(/* args */);

~SuperDraw();

};

ticket

is a linked list structure that holds the 6 lotto numbers in an array and a pointer to

the next element in the list. Notice that the class SuperDraw has 2 private data members,

ticketListHead and ticketListTail. They are 2 pointers pointing to the head (first element)

and the tail (last element) of the linked list.

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.

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

Add a constructor that takes an int argument which corresponds to the number of tickets

to be generated.

Question 3 (10 pts)

The test main() function should look like the following:

int main()

{

SuperDraw sd(2);

}

The output should be something like:

2 new ticket were successfully generated.

The numbers are: 12, 14, 23, 39, 40, 44 and 1, 2, 9, 12, 28, 41

Solutions

Expert Solution

Screenshot

-------------------------------------------------------------------

Program

//Header file
#include<iostream>
#include<string>
using namespace std;
//Ticket node
struct ticket
{
   unsigned int numbers[6];
   ticket* next;
};
//sorting method
void sort(ticket* val) {
   for (int i = 0; i < 6; i++) {
       for (int j = i+1; j < 6; j++) {
           if (val->numbers[i] > val->numbers[j]) {
               int temp=val->numbers[i];
               val->numbers[i] = val->numbers[j];
               val->numbers[j] = temp;
           }
       }
   }
}
//Create a class draw
class SuperDraw
{
   //Instance variables
private:
   ticket* ticketListHead;
   ticket* ticketListTail;
public:
   //Default constructor
   SuperDraw() {
       ticketListHead = NULL;
       ticketListTail = NULL;
   }
   //Parameterized constructor
   SuperDraw(int val) {
       //Loop unti number of parameter ticket generate
       for (int j = 0; j < val; j++) {
           //Create a ticket
           ticket *temp = new ticket;
           //Add values
           for (int i = 0; i < 6; i++) {
                   temp->numbers[i] = rand() % 49 + 1;
           }
           temp->next = NULL;
           //Sort
           sort(temp);
           //Then add into list
           if (ticketListHead== NULL)
           {
               ticketListHead= temp;
               ticketListTail = temp;
               temp = NULL;
           }
           else
           {
               ticketListTail->next = temp;
               ticketListTail = temp;
           }
       }
       ticket *temp = new ticket;
       temp = ticketListHead;
       while (temp != NULL)
       {
           for (int i = 0; i < 6; i++) {
               if (i < 5) {
                   cout << temp->numbers[i] << ",";
               }
               else {
                   cout << temp->numbers[i];
               }
           }
           if (temp != ticketListTail) {
               cout << " and ";
           }
          
           temp = temp->next;
       }
       cout << endl;
   }
   //Method to add new ticket
   void newTicket(int verbose=0) {
           ticket *temp = new ticket;
           for (int i = 0; i < 6; i++) {
               temp->numbers[i] = rand() % 49 + 1;
           }
           temp->next = NULL;
           sort(temp);
           if (ticketListHead == NULL)
           {
               ticketListHead = temp;
               ticketListTail = temp;
               temp = NULL;
           }
           else
           {
               ticketListTail->next = temp;
               ticketListTail = temp;
           }
           //If passed verbose is 1 then print
       if (verbose == 1) {
           for (int i = 0; i < 6; i++) {
               if (i < 5) {
                   cout << temp->numbers[i] << ",";
               }
               else {
                   cout << temp->numbers[i];
               }
           }
           cout << endl;
       }
   }
   //Destructor
   ~SuperDraw() {
   }

};
//Main method
int main()

{
   srand(0);
   //Create an object
   SuperDraw sd(2);
   //Add new ticket
   sd.newTicket(1);
   return 0;
}

----------------------------------------------------------

Output

22,27,36,37,38,39 and 14,23,24,36,37,44
7,16,22,28,37,46


Related Solutions

Develop a C++ class called PrimeNumberGenerator. An object of this class will generate successive prime numbers...
Develop a C++ class called PrimeNumberGenerator. An object of this class will generate successive prime numbers on request. Think of the object as being similar to the digital tasbeeh counter. It has a reset button which makes the counter return to 0. There is also a button to get the next prime number. On the tasbeeh, pressing this button increments the current value of the counter. In your object, pressing this button would generate the next prime number for display....
n Java, Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have...
n Java, Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form realPart + imaginaryPart * i where i is square root of -1 Use floating-point variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. Provide a no-argument constructor with default values in case no initializers are provided. Provide public methods that perform the following operations: a)...
  In games of the KENO or LOTTO style, the bettor selects numbers from a fixed set....
  In games of the KENO or LOTTO style, the bettor selects numbers from a fixed set. Then the game operator selects another set of numbers, and the bettor wins according to the number of matches.    a.​Suppose that the game uses the numbers 1 through 50, and suppose that the operator selects eight of these. If the bettor selects five numbers, find the probability that there are exactly five matches. HINT: Think Hypergeometric b.​Suppose that the game uses the numbers...
Create an Excel spreadsheet that will generate random numbers based on the following probability distributions. You...
Create an Excel spreadsheet that will generate random numbers based on the following probability distributions. You can keep the answers to (a) (b) and (c) on the same spreadsheet. If I click on F9 key, the random numbers must be refreshed. a. Use Excel generic function to generate randomly 50 observations following a general discrete distribution described in the table below. To keep things compact, you don’t need to put the 50 random numbers down one column, instead put them...
Create a class called RandomGuess. In this game, generate and store a random number between 1...
Create a class called RandomGuess. In this game, generate and store a random number between 1 and 100. Then, continuously (in a loop): Ask the user to enter a number between 1 and 100 Let the user know if the guess is high or low, until the user enters the correct value If the user enters the correct value, then display a count of the number of attempts it took and exit
Define a class called Rational for rational numbers. Arational number is a number that can...
Define a class called Rational for rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, /2, 3/4, 64/2, and so forth are all rational numbers.Represent rational numbers as two private values of type int, numfor the numerator and den for the denominator. The class has a default constructor with default values (num = 0,den = 1), a copy constructor, an assignment operator and three friend functions for operator overloading...
Create a class called triangle_area. The initializing inputs are numbers b and h. In addition to...
Create a class called triangle_area. The initializing inputs are numbers b and h. In addition to the initialization method, the class must have the area method, which calculates the area of ​​a triangle (A = b x h / 2) and creates an attribute called Area with that value. Use python sintaxis
(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence,...
(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 114, … etc. By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. We define Fib(0)=0,...
Create a class called RandomWhen. The program must continuously generate a random number between 1 and...
Create a class called RandomWhen. The program must continuously generate a random number between 1 and 100 inclusive. The program must stop when the number 1 is generated, and the loop iteration will be printed. Run the program 3 different times. Sample output: It took ## iterations to generate a 1. It took ## iterations to generate a 1. It took # iterations to generate a 1.
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100...
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100 and 300. Pick a number at random out of these 50 random variables. a. Determine the probability of the chosen number being greater than 200. This may be achieved by counting the numbers that are greater than 200 and dividing the count by 50. Make sure you, i.Formulate the appropriate if-conditions to check for a number being greater than 200 ii. Use a for-loop...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT