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
Can high throttle torque tend to open the throttle plate
koban [17]

Answer:

no

Explanation:

7 0
3 years ago
3. In the text, we described a multithreaded file server, showing why it is better than a single-threaded server and a finite-st
NemiM [27]

Answer and Explanation:

• 1 thread awaits the incoming request

• 1 thread responds to the request

• 1 thread reads the hard disk

A multithreaded file server is better than a single-threaded server and a finite-state machine server because it provides better response compared to the rest and can make use of the shared Web data.

Yes, there are circumstances in which a single-threaded server might be better. If it is designed such that:

- the server is completely CPU bound, such that multiple threads isn't needed. But it would account for some complexity that aren't needed.

An example is, the assistance number of a telephone directory (e.g 7771414) for an community of say, one million people. Consider that each name and telephone number record is sixty-four characters, the whole database takes 64 MB, and can be easily stored in the server's memory in order to provide quick lookup.

NOTE:

Multiple threads lead to operation slow down and no support for Kernel threads.

4 0
3 years ago
Can someone pls give me the answer to this?
Zolol [24]
During World War ll, the United States and the Soviet Union fought together as the allies against the Axis power. However, the relationship between the two nations was a tense one. Americans had long been wary of Soviet communism and concerned about Russian leader Joseph Stalin’s tyrannical rule of his own country
7 0
3 years ago
(SI units) Molten metal is poured into the pouring cup of a sand mold at a steady rate of 400 cm3/s. The molten metal overflows
maxonik [38]

Answer:

diameter of the sprue at the bottom is 1.603 cm

Explanation:

Given data;

Flow rate, Q = 400 cm³/s

cross section of sprue: Round

Diameter of sprue at the top d_{top} = 3.4 cm

Height of sprue, h = 20 cm = 0.2 m

acceleration due to gravity g = 9.81 m/s²

Calculate the velocity at the sprue base

V_{base} = √2gh

we substitute

V_{base} = √(2 × 9.81 m/s² × 0.2 m )

V_{base} = 1.98091 m/s

V_{base} = 198.091 cm/s

diameter of the sprue at the bottom will be;

Q = AV = (πd_{bottom}^2/4) × V_{base}

d_{bottom} = √(4Q/πV_{base})

we substitute our values into the equation;

d_{bottom} = √(4(400 cm³/s) / (π×198.091 cm/s))

d_{bottom}  = 1.603 cm

Therefore, diameter of the sprue at the bottom is 1.603 cm

6 0
3 years ago
A heat pump is used to warm a building in the winter. This system implements an ideal vapor-compression cycle with R-134a as the
Marrrta [24]

Answer:

See attachment for detailed answer.

Explanation:

Download pdf
5 0
3 years ago
Other questions:
  • The y component of velocity in a steady, incompressible flow field in the xy plane is v = -Bxy3, where B = 0.4 m-3 · s-1, and x
    8·1 answer
  • How does a catapult incorporate technology?
    11·1 answer
  • python Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month an
    7·1 answer
  • Steel riverts in aluminium drain gutters leak after two years. is it galvanic corrosion? ​
    5·1 answer
  • A fan draws air from the atmosphere through a 0.30-mdiameter round duct that has a smoothly rounded entrance. A differential man
    14·1 answer
  • Which of the following describes a product concept?
    15·1 answer
  • How do i do this? if y’all don’t mind helping lol
    13·1 answer
  • 9. An elevator on a construction site is being operated at rated capacity of 6 tons, and is supported by two standard steel cabl
    7·1 answer
  • What is the condition for maximum efficiency in a DC motor?
    15·1 answer
  • Suppose a manager of a certain mining company wants to determine the weekly food expenditure of the company’s employees. if ther
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!