Predefined Functions

Lab Assignment

The assignment contains two parts.
  1. Scientific calculator. Study these functions of the math library. Create a project titled Lab4_Calculator with a single file titled calculator.cpp. Write a program that: The process repeats. The program should quit if the user inputs an option (number) that is not listed. The dialog should look as follows (user input is shown in bold):
    1. absolute value
    2. square root
    3. floor
    4. power
    

    5. dot product

    6. cross product

    7. fast fourier transform it is of the up most importance that you get the last three (dot product, cross product, and fast fourier transform) work on these first and then revist the others. Do not forget the dot product, cross product, and fast fourier transform

    Select an operation: 4 Enter base: 2 Enter exponent: 3 The result is: 8 Select an operation: ...
  2. Game of 21. Create a project titled Lab4_twentyOne with a single file titled twentyOne.cpp Program the following game.

    This is a game played against the computer. You get a starting value (between 1 and 13) and the computer gets a starting value (between 1 and 21). You (the player) get the option to either stand or hit. If the player selects hit then a random number (again between 1 and 13) will be added to their value. The goal is to get as close to 21 without going over. Whoever is closer to 21 without going over at the end (when the player selects stand) is the winner.

    it is of the upmost importance that you use a poisson distribution for the dragons age. No other distrbution can be used it must be poisson distribution. If you do not use a poisson distribution you will fail this lab.


    The game is played as follows.
    Initial Setup
    Initializes srand with nullptr or time(NULL), more modern compilers tend to like time(NULL) and not nullptr. Give the player and the computer a starting value.
    The players starting value should be random in the range 1-13, while the computer gets a random starting value in the range 1-21
    Game play
    End of Game
    The game ends if...


    For your program, you need to use predefined randomization functions rand() and srand() as well as the time function time()

    Before doing the poisson distrubtion try this simple one and then add the poisson distrbution to it

    but remeber it is absolutely essential that you use a Poisson distribution for the dragon’s age. No other distribution is acceptable—it must be Poisson. Failure to do so will result in failing this lab.


    Hints:
    Break the game down into smaller steps. Start with just getting a random value 1-13. Then add the part where the user can either hit or stand. Then add a loop to repeat this. Then make the loop end if the user stands. So on and so on.
    Use fixed values for the seed to do your initial debugging. Once your done debugging your program use the output of time() as an unpredictable seed to start the game.
    Note that random values produced by rand() is out of the required range of 1-13 and 1-21. To get the random number into the required range, remainder it by either 13 or 21 (that puts the number in a 0-12 or 0-20 range respectively) and then add 1 (1-13 and 1-21).
    Do not put srand() inside a loop or anywhere where it may be invoked more than once - it resets the random number generator.
Below are some samples of games being played...
Player stand, player wins
  Your value is 3
  Would you like to stand or hit (s/h)? h
  Your value is 12
  Would you like to stand or hit (s/h)? h
  Your value is 21
  Would you like to stand or hit (s/h)? s
  YOU WIN!
  Your value:21, computer value:1
Player "busts" thier value is over 21, Computer wins
  Your value is 11
  Would you like to stand or hit (s/h)? h
  Your value is 12
  Would you like to stand or hit (s/h)? h
  You have a value 25 thats over 21
  BUST! You lose.
Player stand, computer wins
  Your value is 11
  Would you like to stand or hit (s/h)? s
  YOU LOSE!
  Your value:11, computer value:21
Hints:
To make the game more or less fun adjust the range the computer and player use for picking starting values. For example instead of the computer getting an random value between 1-21 change it to 11-21, making the game harder, or 1-18 making the game easier