Question

In: Computer Science

"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to...

"Gambling Greg" Assignment

Outcomes:

  • Demonstrate the ability to create and use structs
  • Demonstrate the ability to create and use menus
  • Demonstrate the ability to create and use an array of structs
  • Demonstrate the ability to generate and use random numbers

Program Specifications:

Assume that gambling Greg often goes to the Dog Racing Track. Greg loves to bet on the puppies. In each race Greg will place a wager and pick a dog. The dog information will be stored in a structure name DOG as follows:

Name, amount to pay out if Greg wins, and the odds of this dog winning the race.

The program should have the following menu:

[G]amble

[R]esults of All Races

[L]eave the Dog Track

If Greg selects [G] the program will ask Greg for his wager and allow Greg to pick a dog from a list. The program will then run the race. The result will be shown to Greg. The results of the race will be stored for future use.

If Greg selects [R] the program will show Greg the results of all previous races entered during this run of the program.

If Greg selects [L] the program will end.

The dogs:

You will create 9 different dogs. See below:

Dog Name

Payout

Odds of Winning

You name the dogs

2 to 1

40%

5 to 1

10%

10 to 1

8%

15 to 1

6%

50 to 1

1%

20 to 1

4%

10 to 1

8%

5 to 1

10%

3 to 1

13%

Submission Requirements:

You must follow the rules from the first assignment. Don't forget your design tool!

DO NOT:

  • Use global variables
  • Use the goto command
  • Use the break command outside a case statement

Solutions

Expert Solution

Note: The provided solution is correct as per the question requirements. If you need further assistance feel free to comment in the comment section. I'm happy to help you. :)

Program code screenshot:

Sample output:

Program code to copy:

// Declare the required header file

#include<stdio.h>

#include<limits.h>

#include<stdlib.h>

#include<time.h>

#include<string.h>

//Demonstrate the ability to create and use structs

// the name of DOG

// to store the information of dog

struct DOG

{

// The dog information which structure have

// Dog name

char Name[32];

// amount of pay of if Greg Wins

int amounttopayout;

// Odds of the dog winning the race

int Oddsofthewinningdog;

};

// Demonstrate the ability to create

//and use an array of structs

// array of struct use to store all the given

// DOg information

void arrayofstruct(struct DOG* d)

{

// Char Dog Name store the information of dog name

char DogNames[9][32] = { "Prince", "Dayna", "Rockey", "Tommy","Beast","Buddy","Oscar","Lovely","Teddy"};

// Create an array of pay out to store the dog payout information

int Payout[9] = {2,5,10,15,50,20,10,5,3};

// Create an array of Odds winning dog % to store the dog percent

int Odds_of_Win_dog[9] = {40,10,8,6,1,4,8,10,13};

// loop to store the information

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

{

    strcpy(d[i].Name,DogNames[i]); d[i].amounttopayout=Payout[i]; d[i].Oddsofthewinningdog=Odds_of_Win_dog[i];

}

}

//Demonstrate the ability to generate

// and use random numbers

// Create a function of random number to choose the

// random dof for the race

void randomnumbers(struct DOG* d, int *randomnum)

{

// Initially random r is equal to zero

int r=0;

// Loop to compute the random

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

    {

    // for loop to access the random dog

    for(int j=0; j<d[i].Oddsofthewinningdog; j++)

    {

      // increment the random

      randomnum[r++] = i;

    }

}

}

// Demonstrate the ability to create and use menus

// to display the following menu:

char menu()

{

// Display for Gamble

printf("[G]amble.\n");

// Display for Result

printf("[R]esult of all Races\n");

// Display for Leave te dog track

printf("[L]eave the Dog Track\n");

// Ask from the Greg to choice the dog

printf("Please select the choice Greg:");

char ch;

scanf(" %c",&ch);

// retur the choice

return ch;

}

// Create a function to pickup the dog list

void pickupdoglist(struct DOG* d)

{

// Display the Dog Table with all the name of Dog and

// all the information

printf("S.No. Dog name      Payout     Odds of Winning \n");

// For loop to display all the stored dog information

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

{

    printf("%d.   %7s,    %4d to 1,    %7d%% \n",i+1, d[i].Name,d[i].amounttopayout,d[i].Oddsofthewinningdog);

}

}

// Create a dog running race function

// to running the choice dog with randomly dog

int dogrunnningrace(int* randomnum)

{

// timer start with zero random

srand(time(0));

// Declare an random variable to store random

// number

int random = rand()%100;

// Return the random number

return randomnum[random];

}

// Create a dog infromation function to ask from the

// Greg

void doginformation(struct DOG* d, int *randomnum, char* buffer)

{

// Ask from the Greg to input the wager for Dog

printf("Please Greg input a wager:");

int wager;

scanf("%d",&wager);

// Call the pickupdog list function

pickupdoglist(d);

// Greg to pick a dog from the list

printf("Please pick up a dog from the list by s.no.:");

int pick;

scanf("%d",&pick);

// Pickup dog index Initially with zero

pick = pick-1;

// Call the dogrunning race function

int raceresult = dogrunnningrace(randomnum);

// Check the pickup dog is equal to race result

if(pick == raceresult)

{

    // Display the result with the name of dog and wager

    printf("%s wins the race. you won %d\n",d[pick].Name,wager*(d[pick].amounttopayout));

    // Store the result for future use

    sprintf(buffer,"%s wins the race. you won %d\n",d[pick].Name,wager*(d[pick].amounttopayout));

}

// otherwise

else

{

    // Display the result greg lost the race with the dog names

    printf("%s loose the race. %s wins the race.\n", d[pick].Name, d[raceresult].Name);

    // Store the result for future use

   sprintf(buffer,"%s loose the race. %s wins the race.\n", d[pick].Name, d[raceresult].Name);

}

}

// Create a function to store the previous races information

void previousraces(char** futureuse, int counter)

{

futureuse = futureuse;

counter = counter +1;

}

// Create a main function of the program

int main(void)

{

// Create the structure dog d as like an object

struct DOG d[9];

int randomnum[100];

// Call the array of struct

arrayofstruct(d);

// call the random numbers function

randomnumbers(d, randomnum);

// Declare the required variable

// Which is not use globally

char selection;

char G,R,L;

char futureuse[1024][64];

int counter=0;

// Create a do while to select the Greg selction

do

   {

    // select the menu

    selection = menu();

    // Note: Here, I'm providing the solution by using

    // switch case or by using simple if-else

    // Please use the approach which you want

    // if you want to use switch case then go for continue

    // or if you want to use if else then comment the switch

    // case than comment from /*switch (selection) to ...

    // last break } */ and remove comment from if else approach

    switch (selection)

    {

      // If Greg selects [G] the program will

      //ask Greg for his wager and allow Greg

      // to pick a dog from a list

      // When User select G

    case 'G':

      // Call the doginformation

      doginformation(d, randomnum,futureuse[counter]);

      // break command use inside the case not outside

      break;

   

    // If Greg selects [R] the program

    //will show Greg the results of all

    //previous races entered during

    // this run of the program.

    // When user select R

    case 'R':

      // Loop to access the future use result

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

      {

        // display future use result

      printf("%s",futureuse[i]);

      }

      break;

    

     // If Greg selects [L] the program will end

    // When user selct L

    case 'L':

      // Display Thank you message and program will end

      printf("Thank you!!!. The program will end.\n");

      break;

   

    // Default case when Greg select wrong choice

    default:

      printf("Wrong selection!!\n");

      break;

    }

    /*

    if (selection == 'G')

    {

      doginformation(d, randomnum,futureuse[counter]);

    }

    else if(selection == 'R')

    {

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

      {

        printf("%s",futureuse[i]);

      }

    }

    else if (selection == 'L')

    {

      printf("Thank You!!!.\n");

    }

    else

    {

      printf("Wrong selection!!\n");

    }*/

    counter++;

}

while(selection != 'L');

}

Note: please give me positive response thank you:)


Related Solutions

Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate strings. Demonstrate the ability to write well written code. Program Specifications: DESIGN and IMPLEMENT a short program that will: Allow the user to enter a string with up to 100 letters. Display the user-entered string: Forward Backward Vertical As a triangle made from the letters of the string Display the number of letters in the string. Once everything above is displayed, the program will...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability to identify emerging ethical issues in business, interpret the multitude of perspectives inherent in your case study, and model appropriate behaviour by recommending specific solutions. How to Proceed Select a case. It can be one of the textbook cases that we have not discussed during the course. It can also come from the outside world, perhaps a case you have been following in the...
In this lab assignment, students will demonstrate the abilities to: - Use functions in math module...
In this lab assignment, students will demonstrate the abilities to: - Use functions in math module - Generate random floating numbers - Select a random element from a sequence of elements - Select a random sample from a sequence of elements (Python Programming) NO BREAK STATEMENTS AND IF TRUE STATEMENTS PLEASE Help with the (create) of a program to play Blackjack. In this program, the user plays against the dealer. Please do the following. (a) Give the user two cards....
Using ONE of the following themes to create a class and demonstrate the idea. Use this...
Using ONE of the following themes to create a class and demonstrate the idea. Use this to create a solution (two ADTs and a driver program) to demonstrate the following concepts. Create a one page summary to describe where you are using each of these concepts. Themes:(PICK ONE) a house has a door a semester has a holiday break a cell phone has a shatterproof case a chair has a cushion Concepts to include: composition separating interface from implementation an...
Demonstrate the use of CRUNCH tool to create a Wordlist file to generate a minimum and...
Demonstrate the use of CRUNCH tool to create a Wordlist file to generate a minimum and maximum word length (2-9) based on your MIT ID and the first seven numbers and two unique special characters, and store the result in file pass.txt. Give an exampleof two generated passwords with length of three characters, one number and one special character. After that, use the HYDRA attacking tool to attack ftp://192.168.1.3 server which has the username ‘tom’ and password length between 2...
Car Race Outcome: Student will demonstrate the ability to generate random numbers Student will demonstrate the...
Car Race Outcome: Student will demonstrate the ability to generate random numbers Student will demonstrate the ability to use a switch statement with cases Student will demonstrate the ability to use loop structures Student will demonstrate the ability to create program logic Student will demonstrate the ability to produce nicely formatted output Program Specifications: You will design a simulated car race. The race will consist of three cars: car A, car B, and car C. Your program will show the...
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT