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
53. The plan of a building is in the form of a rectangle with
schepotkina [342]

Answer: 150m

Explanation:

The following can be depicted from the question:

Dimensions of outer walls = 9.7m × 14.7m.

Thickness of the wall = 0.30 m

Therefore, the plinth area of the building will be:

= (9.7 + 0.30/2 + 0.30/2) × (14.7 × 0.30/2 + 0.30/2)

= 10 × 15

= 150m

7 0
3 years ago
A hypothetical A-B alloy of composition 57 wt% B-43 wt% A at some temperature is found to consist of mass fractions of 0.5 for b
Dennis_Churaev [7]

Answer:

composition of alpha phase is 27% B

Explanation:

given data

mass fractions  = 0.5 for both

composition = 57 wt% B-43 wt% A

composition = 87 wt% B-13 wt% A

solution

as by total composition Co = 57 and by beta phase composition  Cβ = 87  

we use here lever rule that is

Wα = Wβ   ...............1

Wα = Wβ = 0.5

now we take here left side of equation

we will get

\frac{C_\beta - Co}{C_\beta - Ca}   = 0.5

\frac{87 - 57}{87 - Ca} = 0.5  

solve it we get

Ca = 27

so composition of alpha phase is 27% B

8 0
3 years ago
An FPC 4 m2 in area is tested during the night to measure the overall heat loss coefficient. Water at 60 C circulates through th
sp2606 [1]

Answer:

<em> - 14.943 W/m^2K  ( negative sign indicates cooling ) </em>

Explanation:

Given data:

Area of FPC = 4 m^2

temp of water = 60°C

flow rate = 0.06 l/s

ambient temperature = 8°C

exit temperature = 49°C

<u>Calculate the overall heat loss coefficient </u>

Note : heat lost by water = heat loss through convection

m*Cp*dT  = h*A * ( T - To )

∴ dT / T - To = h*A / m*Cp  ( integrate the relation )

In ( \frac{49-8}{60-8} ) =  h* 4 / ( 0.06 * 10^-3 * 1000 * 4180 )

In ( 41 / 52 ) = 0.0159*h

hence h = - 0.2376 / 0.0159

              = - 14.943  W/m^2K  ( heat loss coefficient )

7 0
2 years ago
A cylindrical metal specimen having an original diameter of 12.8 mm and gauge length of 50.80 mm is pulled in tension until frac
Sedaia [141]

Answer:

%Reduction in area = 73.41%

%Reduction in elongation = 42.20%

Explanation:

Given

Original diameter = 12.8 mm

Gauge length = 50.80mm

Diameter at the point of fracture = 6.60 mm (0.260 in.)

Fractured gauge length = 72.14 mm.

%Reduction in Area is given as:

((do/2)² - (d1/2)²)/(do/2)²

Calculating percent reduction in area

do = 12.8mm, d1 = 6.6mm

So,

%RA = ((12.8/2)² - 6.6/2)²)/(12.8/2)²

%RA = 0.734130859375

%RA = 73.41%

Calculating percent reduction in elongation

%Reduction in elongation is given as:

((do) - (d1))/(d1)

do = 72.14mm, d1 = 50.80mm

So,

%RA = ((72.24) - (50.80))/(50.80)

%RA = 0.422047244094488

%RA = 42.20%

3 0
3 years ago
Compressed Air In a piston-cylinder device, 10 gr of air is compressed isentropically. The air is initially at 27 °C and 110 kPa
Helen [10]

Answer:

(a) 2.39 MPa (b) 3.03 kJ (c) 3.035 kJ

Explanation:

Solution

Recall that:

A 10 gr of air is compressed isentropically

The initial air is at = 27 °C, 110 kPa

After compression air is at = a450 °C

For air,  R=287 J/kg.K

cv = 716.5 J/kg.K

y = 1.4

Now,

(a) W efind the pressure on [MPa]

Thus,

T₂/T₁ = (p₂/p₁)^r-1/r

=(450 + 273)/27 + 273) =

=(p₂/110) ^0.4/1.4

p₂ becomes  2390.3 kPa

So, p₂ = 2.39 MPa

(b) For the increase in total internal energy, is given below:

ΔU = mCv (T₂ - T₁)

=(10/100) (716.5) (450 -27)

ΔU =3030 J

ΔU =3.03 kJ

(c) The next step is to find the total work needed in kJ

ΔW = mR ( (T₂ - T₁) / k- 1

(10/100) (287) (450 -27)/1.4 -1

ΔW = 3035 J

Hence, the total work required is = 3.035 kJ

4 0
3 years ago
Other questions:
  • What entrepreneurial activities do you know?are you capable of doing entrepreneurial activities
    15·1 answer
  • For a p-n-p BJT with NE 7 NB 7 NC, show the dominant current components, with proper arrows, for directions in the normal active
    14·1 answer
  • A solid steel shaft has to transmit 100 kW at 160 RPM. Taking allowable shear stress at 70 Mpa, find the suitable diameter of th
    15·1 answer
  • Technician A says that latent heat is hidden heat and cannot be measured on a thermometer. Technician B says that latent heat is
    12·1 answer
  • Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
    10·1 answer
  • A partnership between a gaming company and moviemakers might happen in what two ways?
    6·1 answer
  • Name the four ways in which heat is transferred from a diesel engine
    7·1 answer
  • Select the correct answer <br><br> What is the simplest definition of a manufacturing process?
    5·2 answers
  • 7. If you can't ignore a distraction, what should you do?
    15·1 answer
  • which of the following processes would be appropriate for cutting a narrow slot, less than 0.015 inch wide, in a 3/8- inch thick
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!