CS253: Software Development with C++

Fall 2022

HW 3

CS253 HW3: Options!                

Changes                

The option -t +5 is undefined behavior. That is, a leading plus-sign on the number argument for -t may or may not work. We will not test this case.                 

Description                

For this assignment, you will build upon your previous work in HW1, adding command-line options parsed with getopt(). Also, more than one dictionary file may be given as arguments, with the target word randomly selected from all words in all files. This is a complete program, not a library.                 

Arguments                

The first command-line arguments should be options :                 

-v
User guesses must be valid words—they must appear in a dictionary file. If not, emit an error message.
-t turns
Use this number of turns (guesses) instead of the default, 6.
-g good-string
For a letter in the correct place, emit the characters in good-string instead of =.
-w wrong-place-string
For a letter in the wrong place, emit the characters in wrong-place-string instead of -.
-b bad-string
For a letter that doesn’t appear anywhere in the target, emit the characters in bad-string instead of a space.
-3 or -4 or -5 or -6 or -7 or -8 or -9
Select random words of the given length, instead of the default word length of 5.

After the options come dictionary filenames. If no dictionaries are given, produce an error.                 

This is the Colorado State University CS253 web page https://www.cs.colostate.edu/~cs253/Fall22/HW3 fetched by unknown <unknown> with Linux UID 65535 at 2024-03-28T05:01:50 from IP address 44.200.39.110. 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 Runs                

Here are sample runs, where % is my prompt.                 

% cat CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
project(hw3)

# 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 -6 words.txt
scramble
grass
theological
trail
accent
devil
% ./hw3 -bX -g☺ -w- -t 3 words.txt
I am thinking of a 5-letter word.
Guess: mercy
       X-X☺X
Guess: space
       XX-☺☺
Guess: dance
       ☺☺☺☺☺
You won!
% ./hw3 -6t2 ~cs253/pub/common-words.txt
I am thinking of a 6-letter word.
Guess: classy
        -=   
Guess: leader
       === - 
You lost, the word was "league".

Debugging                

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

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Hints                

    ./hw3 -t99 -g $'\e[102m=\e[m' -w $'\e[103m-\e[m' -b $'\e[101m \e[m' words.txt

Requirements                

Tar file                

    cmake . && make

How to submit your work:                

In Canvas, check in the file hw3.tar to the assignment “HW3”. 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.