Astro 503 Homework #3, Due Tuesday Jan 31 1. Convert your structure and subroutines for the complex number into a class. Make the real and imag parts as private data members, but provide methods that access them. All your subroutines should now be member functions. Provide a constructor that initializes the Complex with two double values. 2. Create a class called UniformDeviate that generates uniform deviates. The interface is as follows: class UniformDeviate { public: UniformDeviate(const long lseed); //Seed the RNG with chosen integer. UniformDeviate(); //Seed using the milliseconds of current time. ~UniformDeviate(); float draw(); // Draw a random number private: // as your implementation requires }; This class should implement the random number generator algorithm presented as "ran2.c" in Numerical Recipes, but this is of course to be hidden from the client. I also expect you will amend the ran2.c code to conform to good C++ practice. Test your random number generator by predicting the expectation value (adjacent values) for a uniform deviate, and then see what you get from a sequence of 100,000 random deviates. 3. Conduct an experiment to answer the following question: If a member function of a class has a static variable declared inside of it, do all instances of the class have access a single common variable, or does each instance of the class see a different version of the static variable? In other words, do different instances of a class share the same code/data for the member functions? 4. Blackjack simulator: This one you can do with 1 or 2 partners. We want to calculate the rate at which you will lose money to the house in blackjack. We will do this by creating a set of objects that communicate with each other. Our classes will be: Card: represents a single playing card. Hand: a set of Cards, which has a certain value in blackjack. Deck: the deck of cards from which the game is dealt; starts with all cards in order, and can be shuffled. Dealer: an entity that has a Hand, and draws cards according to a set of rules. Player: another entity that has a Hand, and draws cards according to some other set of rules (which might consist of asking the user at a terminal). The file Blackjack.h gives skeleton interfaces for all of these classes. Your job is to complete the class structure, and then use it to produce two results: (a) a program that will allow you to play hands of blackjack with the computer acting as dealer, asking you to make each Player decision, and allowing you to keep playing until you quit or run out of money. (b) you should implement a Player that has a set of rules for when to hit/stick. Then have this Player play 1 million hands of blackjack with the dealer, and tell me your derived expectation value for the return on a $1 bet is. ------------------------------------------------ We will consider a simplified form of blackjack: *No splitting or doubling down or surrendering. *Just one dealer and one player. *The player's strategy depends only upon his/her hand and the one visible dealer's card; no card-counting, etc. *Every hand is played for $1 bet. *The "shoe" starts with 2 decks' worth of cards. It is reshuffled if fewer than 15 cards are available at start of the hand. Here are rules of blackjack, for those of you who don't know: 1) Face cards count 10; Aces are either 1 or 11; number cards count their face value. The value of the hand is the sum of the cards' values. A value over 21 loses and is called a "bust." 2) If you are dealt 21 (ace and 10/face), you have "blackjack", you are instantly paid back $2.5 for each $1 you bet - unless the dealer also has blackjack, in which case you tie and just get your $1 back. 3) If you "bust" (see below) then you lose your bet (dealer wins). 4) If you do not "bust" but the dealer does, then you win the hand, receiving $2 for each $1 that you submitted as your initial bet. 5) If neither you nor dealer busts, then the one closer to 21 wins the hand. In case of tie, your initial $1 bet is returned unchanged. The value of aces are always chosen to yield the best possible hand for its owner. Play proceeds as follows: 1) From the cards remaining in the deck, you are given 2, and the dealer receives 1 (a second card is dealt face-down to dealer, but we'll ignore that for now). 2) If you have 21 (blackjack), dealer checks for blackjack, and hand is over. 3) Based on what you see - namely your hand and the dealer's 1 visible card - you may choose to either get another card ("hit") or stop with your current cards ("stick" or "stay"). 4) Step 3 iterates until Player chooses to stick, or Player's sum exceeds 21. The latter is a "bust" and the Player loses, hand is over. immediately. Aces count as 1 when deciding whether it's a bust. 5) Once player sticks, Dealer starts drawing cards. Dealer is obligated to obey the following rule: Dealer draws until sum of its cards is >=17, with aces counting at the largest value that does not cause bust. 6) If dealer busts, player wins, hand is over. If dealer sticks without busting, compare dealer/player hands to determine outcome of the bet. Hand is over. 7) Quit if Player does not wish to play any more. 8) If too few cards remain, then obtain and shuffle a fresh Deck. 9) Begin next hand at step (1).