CS253: Software Development with C++

Fall 2021

HW 3

CS253 HW3: Arguments, reading from files                

       
       
       
       
       
0123456

Changes                

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

Description                

For this assignment, you will write a program called hw3 that improves on your work from HW1. Instead of assuming a range of 0…99, the first two command-line arguments will indicate the inclusive range of acceptable input values. If any arguments remain, they are files to read integers from. If no arguments remain, then read integers from standard input.                 

This is the Colorado State University CS253 web page https://cs.colostate.edu/~cs253/Fall21/HW3 fetched by unknown <unknown> with Linux UID 65535 at 2024-06-26T09:59:56 from IP address 3.16.82.82. 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(hw3)

# Are we in the wrong directory?
if (CMAKE_SOURCE_DIR MATCHES "[Hh][Ww]([0-9])$"
   AND NOT PROJECT_NAME MATCHES "${CMAKE_MATCH_1}$")
    message(FATAL_ERROR "Building ${PROJECT_NAME} in ${CMAKE_SOURCE_DIR}")
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

100003
100003 100001 100002 100003 100004
100002


100004 100005

% ./hw3 100000 100009 <data
100001x1 100002x2 100003x3 100004x2 100005x1
100001,100002,100002,100003,100003,100003,100004,100004,100005
% cat data | ./hw3 100000 100100
100001x1 100002x2 100003x3 100004x2 100005x1
100001,100002,100002,100003,100003,100003,100004,100004,100005
% ./hw3 100000 100009 data
100001x1 100002x2 100003x3 100004x2 100005x1
100001,100002,100002,100003,100003,100003,100004,100004,100005
% head d1 d2
==> d1 <==
81 49
64 100 4
16

==> d2 <==
9       36
25      1
% ./hw3 1 100 d1 d2
1x1 4x1 9x1 16x1 25x1 36x1 49x1 64x1 81x1 100x1
1,4,9,16,25,36,49,64,81,100
% ./hw3 1 100 d1 d2 d1 <data
1x1 4x2 9x1 16x2 25x1 36x1 49x2 64x2 81x2 100x2
1,4,4,9,16,16,25,36,49,49,64,64,81,81,100,100
% echo '-4 -12 -4 +0076 -12' | ./hw3 -200 100
-12x2 -4x2 76x1
-12,-12,-4,-4,76

Hints                

Debugging                

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

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements                

All requirements from HW1 apply, with these modifications:

Tar file                

    cmake . && make

How to submit your work:                

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