Assignment 01

Due: Friday, Jan. 29, 2016 at noon 50 pts.

For this assignment, you will type and submit three (3) algorithms. Make your algorithms clear and concise step-by-step procedures that solve the problems given. I think that each of these should require at least three steps and probably (though, possibly) no more than thirty steps. Think about your answers.

To help you out, you will find examples of problems and algorithms to solve those problems HERE. Perhaps reading these examples will help you in devising algorithms for the problems below.

You are to edit a single file in your DFS account using an editor (I like jpico) that your lab instructor has shown you in your CS 1580 lab #1( or #0 depending on who your lab instructor is). First though, make a new directory under your home directory and call it cs1570 (from home, type mkdir cs1570 and enter). Change into that directory (cd cs1570). Now, make a new directory under this cs1570 directory and name it hw1. Change into that directory and then create the file with your answers in it, naming it something clever like "hw1.txt". The .txt extension is used for files that are nothing but text (not to be compiled). What ever you name that file, make sure it has a .txt extension. This assignment is NOT C++ programming. You are not to compile this. In this (one and only) file (for this assignment), you are to number your answers for the following 3 problems. Also, be sure to put your name and section letter at the top!!

  1. Suppose you are in a class at a typical engineering-type, math-oriented kinda university. The requirements for the course is that you complete three types of exercises during the semester. The grades on these exercises will determine the final grade you get for the class for the semester - your "semester grade". Assume a 'straight scale' for that semester grade: A for an average from 90 to 100; B for an average from 80 upto 90; etc. Now, 40% of your semester average is your average on 9 homework exercises (one of which is 50 pts and the rest of them are each 100 pts). In addition, 50% of your average is you average on three 100-pt tests during the semester. And finally, the remaining 10% of your average is your score on a single 100-pt semester project. Write an algorithm that will compute and output your grade for the semester for this class.

    1. Write an algorithm that simulates a vending machine. The inputs to your algorithm are: (1) the cost of an item and (2) the payment amount inserted by the customer into the machine. The output from your algorithm should be the customer’s change in terms of # quarters, # dimes, # nickels, and # pennies – this should be in terms of the least number of coins possible.

  2. Write an algorithm to play (a simplified version of) the blackjack card game. Assume that this is just played between a single player and the dealer, and that the deck of cards is already shuffled upon entering the game (you don’t need to shuffle it). Each game starts with the player being dealt 2 cards and the dealer being dealt 2 cards. The player then can decide whether s/he wants 0-3 more cards (i.e., “hit me!”). The player’s minimum card point total must be 15 (unless s/he reaches the 5 card limit before that). In terms of points, an ace can count as 1 or 11 (whichever is most advantageous). Numeric cards (2..10) count the number of points shown on the card. All face cards (jack, queen, and king) count as 10 points. The objective is to come as close to, but not exceed, a total of 21 points. If the player’s total exceeds 21, the dealer wins (but the dealer still has taken his/her 2 cards from the deck). After the player plays his/her cards, the dealer does the same. The dealer only needs to take as many more cards (minimum 0, maximum 3) as necessary to have a point total greater than the player has. The winner of the game is the one with the highest point total not exceeding 21. If both the player and the dealer have 21, the dealer wins. Your algorithm should keep playing games until there are not enough cards in the deck for both the player and the dealer to have the opportunity to have a hand of 5 cards. Your algorithm also should keep track of how many games the player wins and how many games the dealer wins, and output that at the end.

To submit this homework, you are going to use the cssubmit program for your section of cs1570. This assignment will be used for all sections. Your answers should be written up using your favorite editer in a subdirectory called hw1 hanging off your cs1570 subdirectory. Remember: make a different directory under cs1570 for every one of your assignments. From that directory, at the UNIX command, type "cssubmit 1570 a 1" if you are in section a. If you are in section b, type "cssubmit 1570 b 1". If you are in section c, type "cssubmit 1570 c 1", etc. (Can you see the pattern?) Hit enter. Of course, when submitting homework #2, your last entry in that command should be a 2. Don't type cssubmit 1570 a h2 or some other variant like that; just the digit 2. Use this scheme for subsequent submissions. If you have any questions about using the editor or submitting, just ask. You can look here for guidance on submitting using the cssubmit command.

NOTE: You can submit the same assignments multiple times. If you submit and then remember something you forgot, you can edit your file, save it, then submit again. The new submission will overwrite the old; we won't see the old one. Time stamps on submissions apply to the latest submission. Always run the submit script from the directory in which the file(s) to be submitted reside(s). Any questions, just ask. Remember, there is a due date/time. Try not to exceed that.