CS253: Software Development with C++

Spring 2021

HW 0

CS253 HW0: Light Bulb Joke                

Changes                

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

Purpose                

This assignment ensures that you can follow instructions, login to a Linux system, compile a C++ program, test your tar file, and check in homework, before homework #1. This assignment is not optional.                 

Description                

You will write a program called hw0 (not HW0). It will answer the question, “How many CU students does it take to change a light bulb?”                 

Where’s the GUI?                

In this class, we build software using cmake and make. We turn in a tar file. You don’t really need to know much about any of those programs—we supply a file CMakeLists.txt that is the data file for cmake, which produces a a file Makefile, the data file for make. All that you need to do is type cmake . once, and make every time afterwards. make will compile your code (if it can) and create an hw0.tar file for you to turn in when you’re finished.                 

“Yeah, but where’s the GUI? How do I edit my code?” Edit it any way you want. Use of a GUI is not required in this class. If you know how to use one, feel free. I use vim. If you need help using a text editor, come to me for help.                 

Sample Build                

In the following example, what you type looks like this. The percent sign, “% ”, is my shell prompt (yours might be “hostname:directory$”). Ignore the indentation. My CMakeLists.txt is shown as an example. You may copy it verbatim or create your own, as long as it meets the requirements below.                 

        % cat main.cc
        #include <iostream>
        using namespace std;

        int main() {
            // How many CU students does it take to change a light bulb?
            cout << "Three—one to hold the light bulb and two to debate\n"
        	    "whether or not an LED or a CFL bulb harms the environment more!\n";
            return 0;
        }
        % cat CMakeLists.txt
        cmake_minimum_required(VERSION 3.11)
        project(hw0)

        # 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 …
        % ./hw0
        Three—one to hold the light bulb and two to debate
        whether or not an LED or a CFL bulb harms the environment more!

Testing                

It is essential that you test what you’ve turned in (the hw0.tar file). Here’s an easy way, where % is my prompt:                 

    % rm -rf testdir
    % mkdir testdir
    % cd testdir
    % tar -xvf ../hw0.tar
    % rm -f hw0
    % cmake . && make
    % ./hw0
    % cd ..

That’s how the TA will test your program (though they will use a different directory name & location). This must work! If it doesn’t you won’t get any points—none.                 

Seriously: if your code works perfectly when you build it, but the hw0.tar file you turn in fails to unpack or fails to build, then you will not receive any points. We will not allow you a second try after the due date. Even if it’s just a tiny thing that you forgot. Even if it’s just one line that you changed but didn’t need testing. Even if it’s totally not your fault. Even if you worked really hard on the homework.                 

TEST

YOUR TAR FILE!

CMakeLists.txt                

Programming assignments in this course use cmake. You will need to modify your CMakeLists.txt slightly for each assignment (at the very least, to change project(hw0) to project(hw1) for HW1). Unlike other aspects of your work, it is not possible to cheat concerning CMakeLists.txt. You may show your CMakeLists.txt to others, share it freely, post it to Teams, copy a different CMakeLists.txt from a message board, etc. If two students have byte-for-byte identical CMakeLists.txt files, that’s just fine with me.                 

Debugging                

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

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements                

How to submit your work:                

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