CS253: Software Development with C++

Fall 2022

HW 1

English spelling can be a hurdle.  “hurdle” is a metaphor that means a difficulty, something that’s hard to do.

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:

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://www.cs.colostate.edu/~cs253/Fall22/HW1 fetched by unknown <unknown> with Linux UID 65535 at 2024-04-18T02:05:57 from IP address 18.116.37.228. 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                

Debugging                

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements                

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                

    cmake . && make

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.