Lab 5

Store all of your files for this lab in a folder named "lab5".

Exercise 1

Create a slot machine game. Here is one way the program could work:

There are three reels each one numbered 0 to 9. The user starts off with 100 coins. Before each spin, the user chooses to pay 1, 2 or 3 coins. If all three reels land on the same number then the user wins coins equal to 300 multiplied by the number of coins they paid. The program should repeat this process until the user quits or runs out of coins.

Your program may optionally display an animation for the spin. If you'd like, you can make the reels have more symbols or make the pay out condition more complex.

Name your source file slots.cpp and your program slots.

Exercise 2

This is the source code for a program that makes you guess a random 3-letter, lowercase password:

#include <iostream> #include <random> using namespace std; int main() { default_random_engine prng(random_device{}()); uniform_int_distribution<char> dist('a','z'); string password; string guess; for (int i = 0; i < 3; ++i) password += dist(prng); while (true) { cout << "Guess 3-letter password: "; cin >> guess; cout << "You guessed: " << guess << endl; if (guess == password) { cout << "Access granted." << endl; break; } else { cout < "Access denied." < endl; } } return 0; }

Save this source code into password.cpp and compile it into a program named password.

Now create a program named guess so that when you run this command:

./guess | ./password

the password will be cracked. The above command will execute the guess program and send all of it's output to the input of the execution of the password program. The guess program should output all possible password combinations so that the correct password will eventually be guessed.