Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. A class called Lotto has as its private variables a vector of ints called numbers and a vector of ints called winning_numbers. It has

1. A class called Lotto has as its private variables a vector of ints called numbers and a vector of ints called winning_numbers. It has a default constructor and it has a regular constructor that takes as an argument a vector of ints. It has accessor called get_numbers() that returns the numbers vector. It has a member function called number_of_matches() that returns the number of elements in the numbers vector that match the numbers in the winning_numbers vector. It has an operator < that takes as an argument a Lotto object. a) Write the class declaration for the Lotto class. b)Write the definition for the regular constructor for the Lotto class. This function should set the numbers vector to have 7 random numbers in the range 1-50. Make sure that there are no repeated numbers. The winning_numbers vector should be set equal to the argument vector. Hint: To make sure that you do not repeat numbers, first create a vector of ints called temp and fill it with numbers 1-50. Then randomly select numbers from this vector and add them to the numbers vector. Each time you select a number from the temp vector, erase it from the temp vector. Note: To simplify this problem you may assume that the erase function we constructed in class has been programmed for you. That is, to erase an element of the temp vector at index i all you need to write is: erase(temp[i]); c) Write the definition for the number_of_matches member function. This function returns the number of elements in the numbers vector that match the elements in the winning_numbers vector. d) Write the definition for the < operator. Implement it in such a way that the description below is satisfied: Given two Lotto objects A and B, the expression A < B should make sense and should evaluate to true if number_of_matches for A is less than number_of_matches for B. (Refer to part c) for the description of the number_of_matches member function.)

2. Using Classes a) Declare a vector of Lotto objects called tickets. b) Assume that you are given a vector of ints called winning_numbers. Write a for loop that adds 100 Lotto objects to the tickets vector. Use the regular constructor and use the winning_numbers vector as an input to the regular constructor. c) Using the overloaded < operator, find the Lotto object in the tickets vector with the most matches to the winning_numbers. Output the numbers in this Lotto object.

3. On the average, how many lotto tickets does one need before all 7 numbers are matched? Write a program that simulates the answer to this question.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

understand the meaning of the terms discipline and grievance

Answered: 1 week ago

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago