CS253: Software Development with C++

Spring 2021

HW 1

CS253 HW1: Word Recognition                

Don’t read too much into this image—it’s just a pretty picture that contains many words.  You will not be writing a Scrabble program.

Changes                

Updates to the assignment will be noted here. None yet!                 

Description                

For this assignment, you will write a C++ program called hw1 that will read from standard input, recognize words, and display some statistics of questionable value about the input. It will display the words found, the number of words encountered, and the range of word lengths. If no words are encountered, display an error message, and nothing else.                 

Input Format                

The input will be any number of lines, containing words. A word is defined as a series of consecutive non-whitespace characters, separated by whitespace. However, parentheses, ( and ), are always separate single-character words, no matter where they appear.                 

Whitespace is defined as any of the six characters " \f\n\r\t\v", or, equivalently, what isspace() says it is.                 

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(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
    -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 …
% cat data

Price:  $8716287.99(+tax)
        +15% gratuity-which-is-RATHER-stingy

% ./hw1 <data
Word is "Price:"
Word is "$8716287.99"
Word is "("
Word is "+tax"
Word is ")"
Word is "+15%"
Word is "gratuity-which-is-RATHER-stingy"
Words: 7
Word range: 1-31
% echo -e "\tQ\f" | ./hw1
Word is "Q"
Words: 1
Word range: 1-1

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 10:00:00ᴘᴍ MT Saturday, with a 24-hour late period for a 25% penalty.                 

How to receive negative points:                

Turn in someone else’s work.