User Defined Functions and Procedures Programming Tasks
ONLY upload your HeAD with Code copied as text and Screenshots of console windows with the code running
Complete 10 chips worth of problems..
You should expect to have to put in extra time for this assignment, it will be worth the effort! You will be practicing EVERYTHING you have learnt so far. You may find that some of the problems below have appeared in previous homeworks in simpler forms. You should try and follow best practice structured programming as described in the B&L page.
75%of the marks are for the use of Procedures, Functions and Passing Parameters !
25% is for the solution and commenting etc..
Where no attempt to use parameter passing is made a mark of ZERO will be given .
The following problems are in no particular order
1) Calculator (3 Chips)
You have done most of the hard work for this but completing this will allow you to produce a "polished" program.
Your Program should:
- Have the following Procedures:
- GetNumbers , OperatorChoice and OutputResult
- And the following Functions:
- Addition , Subtraction , Division , Multiplication , Square and Inverse
- Your program should have the appropriate prompts and menus to be a "usable" calculator
- For an extra chip your program should allow the "natural" input of expressions (e.g. 3+4) and return the result. this is trickier than it sounds BUT a starting point is the split function
2) Random Number Guessing Game (2 Chips)
Write a game that asks the user to guess a random whole number between 1 and 100. The computer should tell the user if they are too high, too low or correct. [3 chips ]. For a bonus chip the user should be asked it they want easy, medium or difficult (e.g. Easy should have unlimited guesses, medium 10 guesses and difficut 5 guesses )
3) Chocolate Machine Simulator (3 Chips)
Write a simulator for a chocolate machine that has four different chocolate bars. Mars =50p, Twix=45p, Milkybar=20p, Freddo=10p. (you should display the bars in a simple menu). The user should select a bar and the program should ask for the appropriate amount of money. The user should then be able to type or select a coin to input, then the program should either give the choc bar or ask for more money. if they have put too much in then the program should offer change.
4) Letter Count (2 chips)
Write a program that works out how many letter a's there are in an inputted string.
Your program should:
- allow the user to input a string
- allocate each character to an element in an array (the split function does this).
- Count and output the number of times the letter 'a' appears
For an extra chip modify this program to count how many times each vowel appears, keeping a running total in a 5-element array.
5) NameSearch (2 Chips)
Write a program that will find a name in a list stored in an array
Your program should:
- Allow the user to enter the names (just first names will do).
- Allow the user to enter the name they wish to search for
- Return if the name is in the array and it's position
6) Yatzee Simulator (poker Dice)
Write a program that simulates the game Yatzee.
- Write a function that simulates a dice role
- write a procedure that call your dice roll function 5 times and assigns the values to an array
- Write a procedure that displays the dice value
- write a function that allows the user to record the score as per http://en.wikipedia.org/wiki/Yahtzee#Lower_section
(the user should choose which row the score is recorded) - EXT: the best option for the score is chosen automatically
- EXT: 2 player mode
7) Binary to Denary Conversion (2 CHIPs) (NB the use of built-in or downloaded converters is not allowed)
Write a Function that is passed an eight bit binary number (as an eight character string) and returns an integer. (I know MOST of you have done something like this in lesson but it still counts!) You should write a short program that tests the function (allowing the user to input the string and see an output of what the function returns) (BONUS CHIP: allowing the input of a variable length bit string).
8) Denary to Binary Conversion (2 CHIPs)
Write a Function that is passed an integer (below 256) and returns an eight bit binary number (as an eight character string). (I know MOST of you have done something like this in lesson but it still counts!) You should write a short program that tests the function.
(BONUS CHIP: allow any integer below 65537 to be entered and return a variable width bit string with no leading zeros)
9) Twos Complement Binary Conversion to Denary signed integer (2 CHIPs)
Write a Function that is passed an eight bit 2’s Complement number (as an eight character string) and returns a signed integer. You should write a short program that tests the function.
10) Signed integer to Twos Complement binary (2 CHIPs)
Write a Function that is passed an eight bit 2’s Complement number (as an eight character string) and returns a signed integer. You should write a short program that tests the function.
11) Binary addition(3 Chips)
Write a function that is passed 2 Binary strings (both 4-bit fixed width) and returns the sum as a binary string (fixed at 5 bits).
12) Fixed Length Binary Real Number to decimal conversion (3 chips)
Write a function that is passed an eight bit binary string with 4 bits associated with the fractional part, and returns a decimal number. You should write a short program that tests the function.
(2 bonus chips) if your function handles bit strings of any length AND any number of bits associated with the fractional part. (HINT you will need to pass the function the number of fractional bits as an integer).