COM 1100 Fall 2000 -- Prof. Futrelle --
Lab 4 Directions
Using conditional ("if") statements, strings and scope
Lab date: Wednesday October 18th. NOTE DUE DATE CHANGE!
Assignment due by 4pm Tuesday, October 24th.
These directions were posted Sunday, October 15th and updated Wednesday AM,
October 18th.
Goal of Lab #4:
To develop programs that use logical expressions to control program flow using
the "if" statement. Also, our first use of string objects and functions.
Understanding the scope of identifiers.
The lab will include material through Section 4.3 of the book (FK).
Concepts and techniques you will use in the lab
- Logical expressions
- The if control statement
- String variables and simple string functions
- Variables of global scope and variables of identical names but distinct scopes
What your program should do. This is not a fully detailed description; a number
of aspects of the design are up to you. The program is to be a guessing game, with
a sequence of more specific hints to the user.
The overall operation of the program should be as follows:
- It should announce that the game is to guess a word.
- It should give a first hint and take a word as input from the user.
- Each word input should be echoed.
- The program should announce whether or not the guess was correct.
- If a guess was not correct, another more specific hint should be given and
the user should enter another guess.
- When the user guesses correctly, tell the user his or her score with
a comment on how well they did.
- After a certain number of hints, if the user has not guessed the word,
announce the answer and tell the user how to quit the program.
Things that are required to be in your program (you will need more than this and
you can add other things you choose):
- string variables for various things, including hints
- A global constant (FK pg. 193 note), the maximum number of tries allowed
- This constant should be used in the functions you define (global scope) for
computing the score.
- Another such constant for the answer string to be guessed
- A variable in main() that appears in separate scope in a function (same name)
- Input of string to variable
- Comparison of guess string with answer string (if statement)
using the string find() function (SIMPLER APPROACH: JUST USE "==" FOR
TESTING STRING EQUALITY)
- Define functions for the following tasks:
- Initial greeting
- Hinting (one function for all hints)
- Input of guess
- Checking of guess (right or wrong)
- Response to bad guess
- Response to good guess
- Response if user fails to guess by the end of the game
- Goodbye comment at end
- Function to allow them to quit -- read one character to take in any input
- To allow these functions to communicate with one another, you may want to
add additional global variables or pass more arguments to them or use their return
values.
How to proceed with the least trouble and the most success and confidence
- Do a lot of design on paper and before you come to the lab.
- Compile or compile and run frequently, after each small addition or
change to your program.
- Add one or two variables at a time. But most importantly, add only one function
definition at a time to your program and test each function separately before going
on to define any more functions. You don't need to test a function as part of
your entire system; you can just call it with some appropriate variables and print
out what it does.