CS253 HW1: Word Guessing                
Changes                
You must produce an error message if the dictionary file contains no contains no five-letter words.
A dictionary with many words, none five letters long, is of no value when you’re looking for five-letter words.
                
Description                
For this assignment, you will write a C++ program called hw1
that will read words from a file given as an argument, select a
five-letter word as a target, and let the user guess the target, giving
feedback. If the guess is correct, say so and stop. You get six
guesses.
                
Feedback                
After each guess, write a line of feedback. Underneath each letter
of the guess will be a character indicating how good that letter was:
=
: this letter is correct, and in the right place
-
: this letter is wrong, and but it does occur somewhere else
in the target word
: a space means this letter doesn’t appear anywhere in the target
word.
Think of the number of lines as a measure of correctness.
=
, double-underline, is super correct.
-
, single-underline, is kind of correct.
                
Dictionary                
The first command-line argument must be a path of a file containing
words. You may assume that the file contains one word per line, all
lower case. The words in the file may be of any length.
                
To select a random word from a vector of words,
#include <random>
, and do this:
random_device rd;
return words[rd() % words.size()];
Later in the semester, we will find better ways to do this.
                
This is the Colorado State University CS253 web page
https://cs.colostate.edu/~cs253/Fall22/HW1
fetched by unknown <unknown> with Linux UID 65535
at 2024-08-30T16:20:57 from IP address 18.117.93.145.
Registered CSU students are permitted to copy this web page for personal
use, but it is forbidden to repost the information from this web page to the
internet. Doing so is a violation of the rules in the CS253 syllabus,
will be considered cheating, and will get you an F in CS253.
Sample Run                
Here is a sample run, where %
is my prompt.
                
% cat CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
project(hw1)
# Are we in the wrong directory?
if (CMAKE_SOURCE_DIR MATCHES "[Hh][Ww]([0-9])$")
if (NOT PROJECT_NAME MATCHES "${CMAKE_MATCH_1}$")
message(FATAL_ERROR "Building ${PROJECT_NAME} in ${CMAKE_SOURCE_DIR}")
endif()
endif()
# Using -Wall is required:
add_compile_options(-Wall)
# These compile flags are highly recommended, but not required:
add_compile_options(-Wextra -Wpedantic)
# Optional super-strict mode:
add_compile_options(-fmessage-length=80 -fno-diagnostics-show-option
-fstack-protector-all -g -O3 -std=c++17 -Walloc-zero -Walloca
-Wconversion -Wctor-dtor-privacy -Wduplicated-cond
-Wduplicated-branches -Werror -Wextra-semi -Wfatal-errors
-Winit-self -Wlogical-op -Wold-style-cast -Wshadow
-Wunused-const-variable=1 -Wzero-as-null-pointer-constant)
# add_compile_options must be BEFORE add_executable.
# Create the executable from the source file main.cc:
add_executable(${PROJECT_NAME} main.cc)
# Create a tar file every time:
add_custom_target(${PROJECT_NAME}.tar ALL COMMAND
tar -cf ${PROJECT_NAME}.tar *.cc CMakeLists.txt)
% cmake . && make
… cmake output appears here …
… make output appears here …
% head words.txt
scramble
theological
accent
possibly
approach
ceremony
swim
measure
play
motor
% ./hw1 words.txt
I am thinking of a 5-letter word.
Guess: arose
= =-
Guess: until
Guess: hyped
--
Guess: sassy
- -=
Guess: press
=====
You won!
% ./hw1 words.txt
I am thinking of a 5-letter word.
Guess: later
--
Guess: chump
-
Guess: grout
=
Guess: teach
-- -
Guess: cheat
- = =
Guess: bleat
= =
You lost, the word was "scent".
Hints                
- The rules produce interesting results for words containing duplicate
letters. Note the “s” in “sassy”, above.
- You don’t have to explicitly display the user’s guess.
It will naturally be displayed as it is typed.
- Produce a program called
hw1
, not HW1
and certainly not hw1.exe
.
- If your program goes crazy, use control-C to rudely interrupt it.
- In some programming languages, the word “dictionary” means an
advanced data structure. In this writeup, we’re using it to simply
mean a list of words.
- We will test your program with our own dictionary file, which might
not be called
words.txt
and might be in some other directory.
- When opening the dictionary file, what directory is the file in!?
Don’t worry about it. Just take the path that was given to you,
and pass it to ifstream. It will either work or it won’t. If it’s
a relative path, then it’s relative to the current directory. If it’s
an absolute path, then it’s an absolute path. You don’t care which.
- You might find the file
~cs253/pub/common-words.txt
useful for testing. Or, create your own
words.txt
that only
has two words in it. That might make debugging easier.
Debugging                
If you encounter “STACK FRAME LINK OVERFLOW”, then try this:
export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a
Requirements                
- This may remind you of some other, legally distinct, game. The rules
stated here, and the behavior of the sample runs, are what matter.
- Produce an error message if:
- there was not exactly one argument given
- the dictionary file cannot be read
- the dictionary file contains no five-letter words
- the user’s guess was not exactly five characters long.
- Error messages:
- go to standard error
- include the program name as given by
argv[0]
- include the dictionary file name, if complaining about that file
- stop the program.
- If multiple things are bad, pick one, complain, and stop.
You don’t have to mention all problems.
- Creativity is a wonderful thing, but your output format is not
the place for it. Your output should look exactly like
the output shown above. The output contains no tab characters.
- UPPERCASE/lowercase matters.
- Spaces matter.
- Blank lines matter.
- Extra output matters.
- You may not use any external programs. You may not use
system(), fork(), popen(), execl(), execvp(), etc.
- You may not use C-style I/O
such as printf(), scanf(), fopen(), and getchar().
- You may not use endl. Use flush if needed.
- You may not use dynamic memory via new, delete,
malloc(), calloc(), realloc(), free(), strdup(), etc.
- It’s ok to implicitly use dynamic memory via containers
such as string or vector.
- You may not use the .eof() method.
- No global variables.
- Except for an optional single global string called
program_name
containing argv[0]
.
- For readability, don’t use ASCII int constants (
65
) instead of
char constants ('A'
) for printable characters.
- We will compile your program like this:
cmake . && make
- If that generates warnings, you will lose a point.
- If that generates errors, you will lose all points.
- There is no automated testing/pre-grading/re-grading.
- Test your code yourself. It’s your job.
- Test with the CSU compilers, not just your laptop’s compiler.
- Even if you only change it a little bit.
- Even if all you do is add a comment.
If you have any questions about the requirements, ask.
In the real world, your programming tasks will almost always be
vague and incompletely specified. Same here.
                
Tar file                
- For each assignment this semester, you will create a tar file,
and turn it in.
- The tar file for this assignment must be called:
hw1.tar
- It must contain:
- source files (
*.cc
)
- header files (
*.h
) (if any)
CMakeLists.txt
- This command must produce the program
hw1
(note the dot):
cmake . && make
- At least
-Wall
must be used every time g++ runs.
Remember how HW0 went on & on about testing your tar file?
It applies here, too, and also to all other assignments.
                
How to submit your work:                
In Canvas, check in the
file
hw1.tar
to the assignment “HW1”.
It’s due 11:59ᴘᴍ MT Saturday, with a 24-hour late period for a 25% penalty.
                
How to receive negative points:                
Turn in someone else’s work.