1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rudiy27
3 years ago
6

You’re going to write a program that models the Littleton City Lotto (not a real Lotto game). The program is going to allow to u

ser to first select their lotto numbers. The program will then randomly generate the winning lotto numbers for the week and then check the winning numbers against the random ticket the user played in the Lotto to see how many numbers the user guessed correctly.
Engineering
1 answer:
sveta [45]3 years ago
8 0

Answer:

Explanation:

// Include the required

// header files.

#include <iostream>

#include <cstdlib>

#include <iomanip>

#include <ctime>

#include <string>

// Use the

// standard namespace.

using namespace std;

// Define the function NoDuplicates(),

// to check whether a value is already

// present in an array or not.

int NoDuplicates(int arr[], int size, int val)

{

// Run the loop to

// traverse the array.

for(int i=0; i<size; i++)

{

// If the value is already present

// in the array, return 0.

if(arr[i] == val)

{

return 0;

}

}

// Otherwise, return 1.

return 1;

}

// Define the function getLottoPicks().

void getLottoPicks(int UserTicket[])

{

int currNum;

//

// Run the oop to get 7

// numbers from the user.

for(int i=0; i<7; i++)

{

// Prompt the user

// to enter the number.

cout << "Please enter number "<<i+1<<":";

// Read and store

// the number.

cin >> currNum;

// Run the loop till the

// entered number is valid.

while(true)

{

// If the number is out of range,

// display an error message.

if(currNum>40 || currNum<1)

{

cout << "The number must between 1 and 40. ";

}

// Otherwise, if the number is

// already present in the array,

// display an error message.

else if(NoDuplicates(UserTicket, i, currNum) == 0)

{

cout << "No duplicate numbers are accepted. ";

}

//Otherwise if the number is valid,

// break out of the loop.

else

{

break;

}

// If the number was invalid,

// prompt the user to enter the number again.

cout << "Please enter another number:"<<endl;

cin >> currNum;

}

// Store the number in the array.

UserTicket[i] = currNum;

}

}

// Define the function GenWinNums().

void GenWinNums(int WinningNums[7])

{

int currNum;

// Run the loop to

// generate 7 numbers.

for(int i=0; i<7; i++)

{

// Generate a random number

// in the range 1-40.

currNum = (rand()%40) + 1;

//Run the loop till the

// generated number is valid.

while(NoDuplicates(WinningNums, i, currNum) == 0)

{

// If the generated number was

// a duplicate, generate another number.

currNum = (rand()%40) + 1;

}

// Store the number in the array.

WinningNums[i] = currNum;

}

}

// Define the function getWinnings().

string getWinnings(int numMatches)

{

// Return the winnings as

// per the number of matches.

switch(numMatches)

{

case 0:

case 1:

case 2:

return "SORRY NOTHING";

case 3:

return "FREE TICKET";

case 4:

return "NOT BAD - $100";

case 5:

return "LUCKY YOU! - $5,000";

case 6:

return "GREAT! - $100,000";

case 7:

return "JACKPOT - 1 MILLION";

}

return "Invalid Matches";

}

// Define the function displayResults().

void displayResults(string name, int UserTicket[], int WinningNums[])

{

int numMatches = 0;

string winnings;

// Run the loop to convert

// the name to uppercase.

for(int i=0; i<name.size(); i++)

{

name[i] = toupper(name[i]);

}

// Run the loop to find

// the number of matches.

for(int i=0; i<7; i++)

{

for(int j=0; j<7; j++)

{

if(UserTicket[i] == WinningNums[j])

{

numMatches++;

break;

}

}

}

// Get the winnings as per

// the number of matches.

winnings = getWinnings(numMatches);

// Display the results.

cout << endl

<< name << "'s LOTTO RESULTS" << endl;

cout << "------------------------"<<endl;

cout << "WINNING TICKET NUMBERS:";

// Run the loop to display

// the winning numbers.

for(int i=0; i<7; i++)

{

cout << setw(3) << WinningNums[i];

}

cout << endl;

cout << setw(13) << name << "'s TICKET:";

// Run the loop to display

// the user ticket.

for(int i=0; i<7; i++)

{

cout << setw(3) << UserTicket[i];

}

cout << endl;

cout << "RESULTS:"<<endl;

cout << "--------"<<endl;

cout << "Number Matches: " << numMatches << endl;

cout << "Winnings : " << winnings << endl

<< endl;

}

// Define the

// function menu().

void menu()

{

cout << "LITTLETON CITY LOTTO MODEL:"<<endl

<<"---------------------------"<<endl

<<"1) Play Lotto"<<endl

<<"q) Quit Program"<<endl

<<"Please make a selection:"<<endl;

}

// Define the

// main() function.

int main() {

// Set the random seed.

srand(time(NULL));

// Define an array to store

// the user ticket.

int UserTicket[7];

// Define an array to

// store the winning numbers.

int WinningNums[7];

char userChoice = '0';

string name;

// Run the loop till

// the user wants to quit.

while(userChoice != 'q')

{

// Display the menu.

menu();

// Read and store

// the user choice.

cin >> userChoice;

// Perform the required action

// as per the user choice.

switch(userChoice)

{

case '1':

cout << "Please enter your name:"

<< endl;

cin >> name;

getLottoPicks(UserTicket);

GenWinNums(WinningNums);

displayResults(name, UserTicket, WinningNums);

break;

// If the user chooses to quit,

// display a message.

case 'q':

cout << "Thank you for"

<<" using the program."<<endl;

break;

// Display an error message

// for invalid selection.

default:

cout << "Invalid selection."

<< endl;

}

}

// Return from

// the main() function.

return 0;

}

You might be interested in
An air compressor of mass 120 kg is mounted on an elastic foundation. It has been observed that, when a harmonic force of amplit
kupik [55]

Answer:

equivalent stiffness is 136906.78 N/m

damping constant is 718.96 N.s/m

Explanation:

given data

mass = 120 kg

amplitude = 120 N

frequency = 320 r/min

displacement = 5 mm

to find out

equivalent stiffness and damping

solution

we will apply here frequency formula that is

frequency ω = ω(n) √(1-∈ ²)      ......................1

here  ω(n) is natural frequency i.e = √(k/m)

so from equation 1

320×2π/60 = √(k/120) × √(1-2∈²)

k × ( 1 - 2∈²) = 33.51² ×120

k × ( 1 - 2∈²) = 134752.99    .....................2

and here amplitude ( max ) of displacement is express as

displacement = force / k  ×  (  \frac{1}{2\varepsilon \sqrt{1-\varepsilon ^2}})

put here value

0.005 = 120/k   ×  (  \frac{1}{2\varepsilon \sqrt{1-\varepsilon ^2}})  

k ×∈ × √(1-2∈²) = 1200       ......................3

so by equation 3 and 2

\frac{k\varepsilon \sqrt{1-\varepsilon^2})}{k(1-2\varepsilon^2)} = \frac{12000}{134752.99}

\varepsilon^{2} - \varepsilon^{4}  = 7.929 * 10^{-3} - 0.01585 * \varepsilon^{2}

solve it and we get

∈ = 1.00396

and

∈ = 0.08869

here small value we will consider so

by equation 2 we get

k × ( 1 - 2(0.08869)²) = 134752.99

k  = 136906.78 N/m

so equivalent stiffness is 136906.78 N/m

and

damping is express as

damping = 2∈ √(mk)

put here all value

damping = 2(0.08869) √(120×136906.78)

so damping constant is 718.96 N.s/m

7 0
3 years ago
Question 9 of 25
mafiozo [28]

Answer:

D

Explanation:

took test failed question D is the right answer

3 0
3 years ago
We have a tube with a diameter of 5 inches that is 1 foot long. The tube then reduces the diameter to 3 inches. According to the
Ksju [112]
Can I get a picture? Of the question so I can understand it more?
6 0
2 years ago
Read 2 more answers
A house that was heated by electric resistance heaters consumed 1500 kWh of electric
gladu [14]

Answer:

2.5=1500/Whp=> Whp=600 kWh

delWgain=1500-600=900 kWh

Money saved= 900* 6tk*=5400 tk

5 0
3 years ago
A continuous random variable, X, whose probability density function is given by f(x) = ( λe−λx , if x ≥ 0 0, otherwise is said t
Ganezh [65]

Answer:

a) F(x) = \lambda \int_0^{\infty} e^{-\lambda x} dx= -e^{-\lambda x} \Big|_0^{\infty} = 1- e^{-\lambda x} \

b) P(10 < X

Explanation:

Previous concepts

The cumulative distribution function (CDF) F(x),"describes the probability that a random variableX with a given probability distribution will be found at a value less than or equal to x".

The exponential distribution is "the probability distribution of the time between events in a Poisson process (a process in which events occur continuously and independently at a constant average rate). It is a particular case of the gamma distribution".

Part a

Let X the random variable of interest. We know on this case that X\sim Exp(\lambda)

And we know the probability denisty function for x given by:

f(x) = \lambda e^{-\lambda x} , x\geq 0

In order to find the cdf we need to do the following integral:

F(x) = \lambda \int_0^{\infty} e^{-\lambda x} dx= -e^{-\lambda x} \Big|_0^{\infty} = 1- e^{-\lambda x} \

Part b

Assuming that X \sim Exp(\lambda =0.1), then the density function is given by:

f(x) = 0.1 e^{-0.1 x} dx , x\geq 0

And for this case we want this probability:

P(10 < X

And evaluating the integral we got:

P(10 < X

4 0
4 years ago
Other questions:
  • A pitfall cited in Section 1.10 is expecting to improve the overall performance of a computer by improving only one aspect of th
    6·1 answer
  • Why do electricians require critical thinking skills? In order to logically identify alternative solutions to problems in order
    8·1 answer
  • Write down the equation for the stoichiometric combustion of propane (C3H8).
    6·1 answer
  • You are given that kc = 10-1 kg eq-1 min-1, ku = 10-3 kg2 eq-2 min-1 and [A]0 = 10 eq kg-1, where kc is the rate constant for a
    15·1 answer
  • Can someone Please help me..? If I'm your Onii-San then answer. And get brainliest. Make sure to explain why..
    15·1 answer
  • A hot plate with a temperature of 60 C, 50 triangular profile needle wings of length (54 mm), diameter 10 mm (k = 204W / mK) wil
    6·1 answer
  • 4. Which of the following is the first thing you should do when attempting
    13·2 answers
  • The specific gravity of a fluid with a weight density of 31.2 lb/ft is a. 2.00 b. 0.969 c. 0.500 d. 1.03
    10·1 answer
  • I need to solve for d
    11·2 answers
  • Planetary gears require the armature to be offset via a gear housing that holds the starter drive.
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!