Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

University of Central Florida COP 3223 Into to Programming in C 4 Assignment 5 Due, Wednesday, November 11, 2020 for maximum 100 Thursday, November 12, 2020 for maximum 90 Friday, November 13, 2020...

1 answer below »
University of Central Florida
COP 3223 Into to Programming in C
4
Assignment 5
Due, Wednesday, November 11, 2020 for maximum 100
Thursday, November 12, 2020 for maximum 90
Friday, November 13, 2020 for maximum 80
Saturday, November 14, 2020 for maximum 70
Deliverables 
To complete this assignment you must submit your casino.c to Webcourses.
Project description
This project will require students to simulate a casino where players can select from a list of games they wish to play. Students will have to work through a series of programming implementations in order to complete the project. The project will include the use of primitive data type variables, a
ays, user defined functions, and functions from the C li
ary.
Assignment Naming Convention
It is highly recommended that for each iteration of the project students copy the previous assignment and rename it for additional functionality. The purpose of this implementation is two-fold. First, if there is a grading discrepancy, students have evidence that your source code worked as designed respective to what the grading ru
ic required. Second, the cu
ent implementation of Webcourses automatically renames a student’s assignment submission. The first submission would be “casino.c”, the second submission automatically gets renamed to “casino-1.c”, the third submission automatically gets renamed to “casino-2.c”, etc… and causes concern for students.
Assignment Scope
1. Create a C source code file
2. Add functions to existing project
3. Use random function
4. Use decision making control flow
5. Use looping control flow
6. Use one dimensional a
ay
7. Use two dimensional a
ay
8. Use structs
9. Use formatted printing
10. Compile and run a file
11. Submit to Webcourses
References
Source code examples in Webcourses
1. dataTypes.c
2. functions.c
3. inputOutput.c
4. a
ays.c
5. decisionMaking.c
6. looping.c
7. random.c
8. structures.c
9. typecasting.c
Tasks
    Activity
    casino.c
    1. Copy casino4.c to casion5.c
    
    1. Add constants for game Scratch Offs as follows:
a. BONUS as value of 20
2. Write the function declarations or prototypes for the follow functions
a. cashOneDolla
. cashTwoDolla
c. cashFiveDolla
d. getBonus
    function playScratchOffs
    3. Update function playScratchOffs to do the following
a. Update the switch statement to do the following
i. case ONE: set variable cash equal to function call cashOneDollar passing the struct OneDollar variable as an argument
ii. case TWO: set variable cash equal to function call cashTwoDollar passing the struct TwoDollar variable as an argument
iii. case FIVE: set variable cash equal to function call cashFiveDollar passing the struct FiveDollar variable as an argument
    function cashOneDolla
    4. Write function cashOneDollar to do the following
a. Return type int
. Parameter list struct OneDolla
c. Declare the following constants
i. SYMS with value 2 for number of bonus symbols
ii. NUMS with value 5 for number of player numbers and prizes
d. Declare the following variables
i. cash, data type float for the player’s cash
ii. n, data type integer for a looping variable
iii. bonus, data type character set equal to function call getBonus passing constant ONE as an argument
e. Write a printf statement to display the bonus symbol
f. Write a for loop to loop five times
i. Compare each of the player’s numbers to the winning number in the struct OneDollar parameter to determine if they are equal
1. If true, update the cash variable to add the associated prize in the struct OneDollar parameter to the cu
ent value of variable cash
g. Write a for loop to loop two times
i. Compare each of the player’s symbols to the bonus symbol (i.e. bonus) to determine if they are equal
1. If true, update the cash variable to add the bonus cash (i.e. BONUS) to the cu
ent value of variable cash
h. Write a printf statement to inform the player their winnings for the scratch off ticket
i. return cash explicitly type casted to data type int
    function cashTwoDolla
    5. Write function cashTwoDollar to do the following
a. Return type int
. Parameter list struct TwoDolla
c. Declare the following constants
i. WINS with value 2 for the number of winning numbers
ii. SYMS with value 2 for number of bonus symbols
iii. NUMS with value 10 for number of player numbers and prizes
d. Declare the following variables
i. cash, data type float for the player’s cash
ii. w, data type integer for a looping variable
iii. n, data type integer for a looping variable
iv. bonus, data type character set equal to function call getBonus passing constant TWO as an argument
e. Write a printf statement to display the bonus symbol
f. Write a for loop to loop two times (i.e. number of winning numbers)
i. Write a for loop to loop 10 times
1. Compare each of the player’s numbers to the winning numbers in the struct TwoDollar parameter to determine if they are equal
a. If true, update the cash variable to add the associated prize in the struct TwoDollar parameter to the cu
ent value of variable cash
g. Write a for loop to loop two times
i. Compare each of the player’s symbols to the bonus symbol (i.e. bonus) to determine if they are equal
1. If true, update the cash variable to add the bonus cash (i.e. BONUS) to the cu
ent value of variable cash
h. Write a printf statement to inform the player their winnings for the scratch off ticket
i. return cash explicitly type casted to data type int
    function cashFiveDolla
    6. Write function cashFiveDollar to do the following
a. Return type int
. Parameter list struct FiveDolla
c. Declare the following constants
i. WINS with value 4 for the number of winning numbers
ii. SYMS with value 4 for number of bonus symbols
iii. NUMS with value 12 for number of player numbers and prizes
d. Declare the following variables
i. cash, data type float for the player’s cash
ii. w, data type integer for a looping variable
iii. n, data type integer for a looping variable
iv. bonus, data type character set equal to function call getBonus passing constant FIVE as an argument
e. Write a printf statement to display the bonus symbol
f. Write a for loop to loop four times (i.e. number of winning numbers)
i. Write a for loop to loop 12 times
1. Compare each of the player’s numbers to the winning numbers in the struct FiveDollar parameter to determine if they are equal
a. If true, update the cash variable to add the associated prize in the struct FiveDollar parameter to the cu
ent value of variable cash
g. Write a for loop to loop four times
i. Compare each of the player’s symbols to the bonus symbol (i.e. bonus) to determine if they are equal
1. If true, update the cash variable to add the bonus cash (i.e. BONUS) to the cu
ent value of variable cash
h. Write a printf statement to inform the player their winnings for the scratch off ticket
i. return cash explicitly type casted to data type int
    function getBonus
    7. Write function getBonus to do the following
a. Return type characte
. Parameter list data type integer (i.e. type)
c. Declare the following constants
i. Constant for the number of random symbols for OneDollar and TwoDollar scratch offs, data type integer set equal to the value 6 (i.e. ONE_TWO)
ii. Constant for the number of random symbols for FiveDollar scratch off, data type integer set equal to the value 8 (i.e. FIVE_RAND)
iii. Character a
ay set equal to data set '$', '%', '&', '#', '@', '!', '^', '*' (i.e. SYMBOLS)
d. Declare the following variables
i. Data type character to store the bonus symbol (i.e. bonus)
ii. Data type integer to store the random number selection (i.e. sym)
e. Write an if statement to evaluate the parameter received (i.e. type) to determine if the scratch off type is ONE or TWO; if true
i. Set variable sym equal to random number generation based six symbols
ii. Write a switch statement to evaluate variable sym to select the bonus symbol from the SYMBOLS a
ay and store the symbol in variable bonus
f. else if statement to evaluate the parameter received (i.e. type) to determine if the scratch off type is FIVE; If true
i. Set variable sym equal to random number generation based eight symbols
ii. Write a switch statement to evaluate variable sym to select the bonus symbol from the SYMBOLS a
ay and store the symbol in variable bonus
g. return the bonus symbol (i.e. bonus)
    Casino executable
    
    Test Case 1
    Test Case 1 passes
    Test Case 2
    Test Case 2 passes
    Test Case 3
    Test Case 3 passes
    Test Case 4
    Test Case 4 passes
    
    Source compiles with no e
ors
    
    Source runs with no e
ors
    
    Source includes comments    
Perform the following test cases
    Test Cases
    
    Action
    Expected outcome
    Test Case 1
    Run executable
User clicks the key
User enters value 2 and clicks the key to select Scratch Offs
    When the executable runs and the user clicks at the Welcome screen
The user enters the value 2 and clicks The output in the command prompt should look like Figure 1 Scratch Off function output
    Test Case 2
    User enters value 1 to select a One Dollar scratch off ticket and clicks User enters a value for the number of tickets and clicks     The player should be informed what their winnings are for the scratch off ticket.
The screen displays similar output to Figure 3 OneDollar ticket
    Test Case 3
    User enters value 2 to select a Two Dollar scratch off ticket and clicks User enters a value for the number of tickets and clicks     The player should be informed what their winnings are for the scratch off ticket.
The screen displays similar output to Figure 4 TwoDollar ticket
    Test Case 4
    User enters value 5 to select a Five Dollar scratch off ticket and clicks User enters a value for the number of tickets and clicks     The player should be informed what their winnings are for the scratch off ticket.
The screen displays similar output to Figure 5 FiveDollar ticket
    Test Case 5
    
    Player’s winnings should calculate co
ectly to reflect the prizes associated with player’s numbers matching the winning number(s) and the bonus symbol
Figure 1 Scratch Off function output
Figure 2 User prompts
Figure 3 OneDollar ticket

Figure 4 TwoDollar ticket
Figure 5 FiveDollar ticket
Answered Same Day Nov 08, 2021

Solution

Arun Shankar answered on Nov 11 2021
160 Votes
#include #include #include global constants
#define SLOTS 1
#define SCRATCH 2
#define BLACKJACK 3
#define FACES 13
#define SUITS 4
#define CLUBS 0
#define DIAMONDS 1
#define HEARTS 2
#define SPADES 3
#define BUST 21
#define ONE 1
#define TWO 2
#define FIVE 5
#define BONUS 20
struct OneDollar{
int winNumber;
int numbers[5];
float prizes[5];
char bonus[2];
};
struct TwoDollar{
int winNumbers[2];
int numbers[10];
float prizes[10];
char bonus[2];
};
struct FiveDollar{
int winNumbers[4];
int numbers[12];
float prizes[12];
char bonus[4];
};
function prototypes
void welcomeScreen();
void clearScreen();
int playSlots();
int playScratchOffs();
int playBlackJack();
int displayMenu();
char randomSymbol();
void initializeDeck(char deck [SUITS][FACES] );
void printDeck(char deck[SUITS][FACES]);
void initializeUsed (int used[SUITS][FACES]);
int deal(char deck [SUITS][FACES], int dealt [SUITS][FACES]);
int results (int playerScore, int dealerScore);
int playBlackJack( int cash);
struct OneDollar createScratchOffOne(struct OneDollar oneSo);
struct TwoDollar createScratchOffTwo(struct TwoDollar twoSo);
struct FiveDollar createScratchOffFive(struct FiveDollar fiveSo);
void displayScratchOffOne(struct OneDollar oneSo);
void displayScratchOffTwo(struct TwoDollar twoSo);
void displayScratchOffFive(struct FiveDollar fiveSo);
int main()
{
int game;
int cash = 1000;
srand(time(0));
welcomeScreen();
clearScreen();
game = displayMenu();
clearScreen();
switch(game)
{
case 1:
cash = playSlots(cash);

eak;
case 2:
cash = playScratchOffs(cash);

eak;
case 3:
cash = playBlackJack(cash);

eak;
}
game = displayMenu();
return 0;
}
opening text statement
void welcomeScreen()
{
printf(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n X !!!HIGH STAKES GAMES!!! X\n XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");
}
clears the screen
void clearScreen()
{
char enter;
printf(" Press the enter to continue!\n");
scanf("%c", &enter);

windows clea
system("cls");

linux clea

system("clear");
}
displays the menu options, player selects numeral 1-3
int displayMenu()
{
int select;
do
{
printf("Select your game:\n 1. SLOTS\n 2. SCRATCH\n 3. BLACKJACK\n");
scanf("%d", &select);
} while(select < SLOTS || select > BLACKJACK );
return select;
}
int playSlots(int cash)
{
const int bet = 5;
const int match_two = 5;
const int match_three = 50;
int play = 1;
char symOne;
char symTwo;
char symThree;
printf("Bet costs %d. If you match two you win %d. If you match three you win %d.\n", bet, match_two, match_three);
if (cash >= bet)
{
while (play == 1)
{
cash = cash - bet;
printf("Slots are spinning\n");
symOne = randomSymbol();
symTwo = randomSymbol();
symThree = randomSymbol();
printf("%c %c %c\n", symOne, symTwo, symThree);
if (symOne == symTwo && symOne == symThree)
{
printf("All three symbols match! You win $%d!\n", match_three);
cash = cash + match_three;
}
else if (symOne == symTwo || symOne == symThree || symTwo == symThree)
{
printf("Two symbols match. You win $%d.\n", match_two);
cash = cash + match_two;
}
else
{
printf("No symbols match.\n");
}
printf("Your cu
ent cash is now %d.\n", cash);
if (cash >= bet)
{
printf("Would you like to spin again? Press 1 to play again or 0 to return to main menu.\n");
scanf("%d", &play);
}
else
{
printf("Not enough cash to continue, returning to main menu.\n");

eak;
}
}
printf("Thanks for playing. Cu
ent cash amount is %d\n",cash);
return cash;
}
else
{
play = 0;
}
return 0;
}
char randomSymbol()
{
const char symbols [] = "$" "%" "&" "#" "@" "!";
char randomSymbol;
int randomNumber;
randomNumber = rand() % 5 + 0;
switch(randomNumber)
{
case 0:
randomSymbol = symbols[0];

eak;
case 1:
randomSymbol = symbols[1];

eak;
case 2:
randomSymbol = symbols[2];

eak;
case 3:
randomSymbol = symbols[3];

eak;
case 4:
randomSymbol = symbols[4];

eak;
case 5:
randomSymbol = symbols[5];

eak;
}
return randomSymbol;
}
Functions coded by me
char getBonus(int type)
{
const int ONE_TWO = 6;
const int FIVE_RAND = 8;
char SYMBOLS[] = {'$', '%', '&', '#', '@', '!', '^', '*'};
char bonus;
int sym;
if((type == ONE) || (type == TWO))
{
sym = rand() % ONE_TWO;
switch(sym)
{
case 0: bonus = SYMBOLS[0];
eak;
case 1: bonus = SYMBOLS[1];
eak;
case 2: bonus = SYMBOLS[2];
eak;
case 3: bonus = SYMBOLS[3];
eak;
case 4: bonus = SYMBOLS[4];
eak;
case 5: bonus = SYMBOLS[5];
eak;
}
end of switch case
}
else if(type == FIVE)
{
sym = rand() % FIVE_RAND;
switch(sym)
{
case 0: bonus = SYMBOLS[0];
eak;
case 1: bonus = SYMBOLS[1];
eak;
case 2: bonus = SYMBOLS[2];
eak;
case 3: bonus = SYMBOLS[3];
eak;
case 4: bonus = SYMBOLS[4];
eak;
case 5: bonus = SYMBOLS[5];
eak;
case 6: bonus = SYMBOLS[6];
eak;
case 7: bonus = SYMBOLS[7];
eak;
}
end of switch case
}
return bonus;
}
int cashOneDollar(struct OneDollar oneSo)
{
const int SYMS = 2;
const int NUMS = 5;
float cash;
int n;
char bonus = getBonus(ONE);
printf("bonus = %c\n", bonus);
for(n = 0; n < NUMS; ++n)
{
if(oneSo.winNumber == oneSo.numbers[n])
cash += oneSo.prizes[n];
}
End of...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here