|
CP107 LAB 5
LAB OBJECTIVES:
LAB PROCEDURE: Read the problem description carefully and create pseudo code from the information that is provided below. Submit pseudo code as part of the assignment. Using the pseudo that you just created, develop a computer program. Test the program and submit it.
LAB ASSIGNMENT 1) LAB 5A Write a complete C++ program with two alternate functions
specified below, of which each simply triples the variable count defined
in main. Then compare and contrast the two approaches.
Submit the program as lab5a.cpp
2) Lab5B Modify
the craps program to allow wagering. Package as function the
portion of the program that runs on game of craps. Initialize variable bankBalance
to 1000 dollars.
Prompt the player to enter a wager. Use a
while loop to check that wager is less than or equal to bankBalance and, if not, prompt the user to reenter wager
until a valid wager is
entered. After a correct wager
is entered, run on game of craps. If the player wins, increase bankBalance
by wager and
print the new bankBalance.
If the player loses, decrease bankBalance by wager, print the new bankBalance, check whether the bankBalance
has become zero and, if so, print the message “Sorry, you busted!”, As
the game progress, print various message to create some “chatter”. The exact
messages are listed below. Submit the program as craps5b.cpp Function “void chatter( void )”Use switch statement with argument ( 1 + rand() % 9 ) and print the following messages. case 1, "Oh, you're going for broke, huh?" case 2, "Aw cmon, take a chance!" case 3, "Hey, I think this guy is going to break the bank!!" case 4, “You're up big. Now's the time to cash in your chips!" case 5, "Way too lucky! Those dice have to be loaded!" case 6, "Bet it all! Bet it all!" case 7, "Can I borrow a chip?" case 8, "Let's try our luck at another table." case 9, "You're a cheat! It is just a matter of time before I catch you!!!"
int rollDice( void );Simulates roll of two dice, prints the following message and returns the sum of the two dice rolls. Use mod operator to get a random number in range 1 to 6. Dice will be rolled twice. Prints out "Player rolled " << die1 << " + " << die2 << " = " << workSum << '\n';
Status craps( void );call rollDice and then determines if the game is WON,
LOSS or CONTINUE. Use a switch statement.
Main Programint
result, wager = 0, bankBalance = 1000; use srand to randomize time. Use a do-while loop
as the main control structure of the program
|
Copyright (c) Yusuf Family Website 2001 |