::::: Homework Assignment #2 ::::: Due Wednesday, October 21, 2009 by midnight! *** All work has to be done individually! *** 2 written questions and 1 programming question inside. Written question #1: Size of arrays Instructions: What is the size of the following arrays? a) int primenumbers[] = { 2, 3, 5, 7, 11 }; b) char greeting[] = "hello!"; Grading: a) 5 points b) 5 points Written question #2: Function prototypes Instructions: Write the following into a C function prototypes. The expression should give correct intended results and it should compile without error. a) The function fahrenheit2celsius receives a real number and returns a real number, both of type 'double'. b) The function silenceTreatment receives nothing and returns nothing. c) The function meaningOfLife receives three worded questions, e.g. "Is there a God?", and returns an integer. Grading: a) 5 points b) 5 points c) 5 points Programming question #1: Bender's Blackjack Table Intro: Bender is opening a new blackjack casino. He has started writing an automated blackjack dealer program but he can't finish it. (He's been having nightmares.) You must finish the program for him. These are his blackjack rules, modified from www.hitorstand.net: # The goal of blackjack is to beat the dealer's hand without going over 21. # Face cards (J, Q, K) are worth 10. Aces are worth 1 or 11, whichever makes a better hand. # Each player starts with two cards, one of the dealer's cards is hidden until the end. # To 'Hit' is to ask for another card. To 'Stand' is to hold your total and end your turn. # If you go over 21 you bust, and the dealer wins regardless of the dealer's hand. # If you are dealt 21 from the start, you got a blackjack. # Blackjack means you win twice the amount of your bet. # You win and the dealer loses if both have a blackjack. # The player starts first. His turn continues until he stands or he's bust. # When it's the dealer's turn, dealer will hit until his/her cards total 17 or higher. # Doubling is like a hit, only the bet is doubled and you only get one more card. # You cannot double if you don't have enough money left. # The minimum bet is 10. Bets are multiples of 10. (10, 20, 30, ...) Instructions: - Write Bender's automated blackjack dealer program according to his rules. - Bender has written part of the program already. Don't add or change any part of his code within blackjack.h and the main() function. You can change/add code anywhere else within blackjack.c. - blackjack.h contains many useful functions that you will need to use. - Instead of using scanf(), use Bender's readInt() for integer input and readChar() for character input. Bender's functions handle spaces, tabs, and newlines. But you still have to check whether the int or char returned is valid. Hints: - Don't panic! You already know everything there is to know to write this program. (Functions, integer arrays, loops, switch or if) - Try to understand Bender's main() and playGame() before you start. Compile the program and run it to see what it does and how the functions from blackjack.h were used. - Design and write functions that are easy to understand. To do this, you need to break the problem into smaller, manageable pieces. main() is an example of such a function. - You will have to use Bender's functions like drawRandomCard(), printCard(), and getCardValue(). Don't worry about understanding how the function works. You just need to understand *what* they do and use them to your advantage. Read the comments on each function by Bender to understand what they do. Grading: Your program will be graded out of 100 with the following breakdown: - Correctness (70 points) The automated dealer should work as stated above. And it should compile!!!!! We will not accept any program that does not compile in CUNIX. A program that compiles but is less complete is better than one that does not compile. - Elegance (10 points) Simple code is better than complex code. Sometimes, complex code comes from the programmer not thinking clearly about the problem that the program is trying to solve. Write simple, elegant code. - Format (10 points) Use indentation so that your code is readable. Your code should look neat. - Comments (10 points) Write comments liberally at the top of your code, and also inside the code. What to submit: 1) README file README file is a text file that contains your name, UNI, name and explanation of files that you're submitting, and your comments on your program. 2) Answer to written questions This should go in a separate text file with an extension .txt. 3) Your source code file This is the blackjack.c file you'll submit as the programming part of your homework. How to submit: 1) make a directory called homework2 2) copy or move your README, written answer file, source code file to homework1. 3) 'cd homework2' to get into that directory make sure you check that you're in homework1 by issuing a 'pwd' Unix command. 4) Type '~jk2520/submit hwk2' in shell prompt. For example, this is what it'd look like with the CUNIX shell prompt, $ ~jk2520/submit hwk2 The submit script will ask some questions and let you submit homework. You will receive a confirmation email if the homework was submitted properly.