Functions and Parameters
Pre-lab reading materials
Until Chapter 5 on Zyante, especially 5.10, 5.11 and 5.12.
Announcements
We will have a simple 5 minutes’ quiz at the beginning of the lab on Blackboard. Please sign in to your Blackboard account and finish the quiz individually. Most of your time should be focussed on finishing the lab activity questions. To access the quiz, go to CS 141 course on Blackboard, and click on Lab Quizzes, there you can find Lab 4 quiz. To access the quiz, you will need a password, which will be announced by the TA in the lab.
The full version of lab assignment is on Blackboard, under the link "Lab Assignments" > "Lab 4 Programming Activity". To access the assignment, you need a password, which will be announced by the TA in the lab.
You must work with a single partner, in a group of 2. You must take turns being the “driver” and the “navigator”. (If there are an odd-number of students in the class, your TA will make an adjustment.)
There are 3 question. The maximum score is 2, where each question is worth 1 point. Question 3 is extra credit. To get a grade, you must submit your work onto Blackboard before your lab session ends. Late submission is not accepted. Once you finish your work, please raise your hand and show your work to your TA during the last 10 minutes of lab.
Lab Activity
During the lab section today, you need to implement three individual functions for a game program, with progressing complexities. We will also supply a sample function for you. In order to complete these functions, you should review and have a firm knowledge about function, char, pointer, string.
In this game, your program will choose a random 4-letter word from a predefined list. Your program will then display that word to player with 2 letters hidden. You will ask the player to input their guess (you can assume that player always input 4-letter word). When the player makes a wrong guess, you will ask them to input again. The program will finish when they make the right guess.
Here is the pseudo-code for the main program, divided into function:
Function to select a random word from the list (supplied to you in sample file)
Function to display that word with 2 letters hidden (extra credit question, you should create this function last)
In the loop: until player make the right guess:
Function to get user input (question 1)
Function to compare the 2 words (question 2)
1. Question 1 (1 credit): write a function to get player's input
2. Question 2 (1 credit): write a function to compare 2 words (both are 4-letter words). Return 1 if the 2 words are same, return 0 otherwise
3. Question 3 (extra credit): write a function that when you supply a word, the function will display the word with 2 random letters with *. For example, the word "bold" may be displayed as *ol*
Link to file sample: Google Drive link