Assignment 01: Hello CS223!

Due Wednesday, January 25, before midnight

The goals for this assignment are:

  • Try slack

  • Sign-up for Github

  • Look at the website

  • Write a simple C program

  • (Optional) Setup your development environment on your own machine

1. Try slack

I will be inviting you all to join the course slack channel. In the introduction channel, say and introduce yourself:

  • What is your preferred name and pronouns?

  • Share with us your favorite emojji. :)

We will use Slack for

  • Course announcements

  • Links to zoom and calend.ly

  • Questions and errata for assignments and labs

You can also use Slack to talk directly to me and the TAs, or even to each other!

2. Sign-up for Github

Please go to github.com and register. We will use github for assignments. Email the instructor (anormoyle at brynmawr.edu) with your github username.

*You will need to setup an SSH key for Github. Click here for instructions.

We have made the decision to open-source our assignments and projects for this class. The benefit of this decision is that you will have a portfolio of work that you can easily keep and share.

Having open-source assignments means that your work is publicly viewable, should someone search for it. It also means that if you copy other people’s work, it is in plain view for anyone to see! We will compare assignments and expect everyone to adhere to the honor code at Bryn Mawr and Haverford.

You will discover that there are many open-source coding resources for online. Some of it is boiler plate and intended to be re-used, such as when we use API documentation in order to use a function. Any non-trivial code (longer than a single statement) that you re-use in your own program should be attributed. In this class, 99% of all code should be your own.

3. Read the class web pages

Start by reading through all of the class webpage! Bookmark this page on your browser, or use some other method that helps you keep this information handy. All course materials will be posted on the course webpage!

Pay special attention to the Schedule.

4. Hello C

Verify that you can use Github, git, and C. You can try this using a lab machine, or your own machine if you have setup your development environment there.

Fork the repository

Fork the repository from here:

Fork is a button located on the top, right on Github.

Clone the repository

From your own account, clone the repository you just forked. The URL should look something like the following

git@github.com:<YOURUSERNAME>/cs223-assignments[]

Use the "Code" button on Github to copy the URL. Then run the following command from terminal.

git clone git@github.com:<YOURUSERNAME>/cs223-assignments[]

This will download a local account of the repository to your computer.

Build hello.c

In the directory A00, you will have a sample file, hello.c and makefile Makefile. Try building and running.

$ make hello
$ ./hello
Hello World

Math Game

In the directory, A00, implement a simple math game that asks a user a series of addition problems and keeps track of the number of correct responses.

$ make mathgame
gcc -g mathgame.c -o mathgame
$ ./mathgame
Welcome to Math Game!
How many rounds do you want to play? 3

2 + 8 = ? 10
Correct!

1 + 8 = ? 5
Incorrect :(

6 + 8 = ? 14
Correct!
You answered 2/3 correctly.

Requirements:

  • Ask the user for the number of questions

  • Use printf and scanf for interactions with the user

  • Use a loop to ask each question

  • Maintain the number of correct questions

  • Generate random questions. Use rand() to generate random integers between 1 and 9.

  • Print a welcome message

  • Print a completion message

  • Compiles with make

  • No memory errors using valgrind

To check for valgrind errors, run your program like so. Look for the message "no leaks are possible". Make sure there are no errors reported. We will talk more about valgrind in week 2 and 3.
$ valgrind ./mathgame
==5184== Memcheck, a memory error detector
==5184== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==5184== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==5184== Command: ./mathgame
==5184==
Welcome to Math Game!
How many rounds do you want to play? 3

2 + 8 = ? 10
Correct!

1 + 8 = ? 5
Incorrect :(

6 + 8 = ? 14
Correct!
You answered 2/3 correctly.
==5184==
==5184== HEAP SUMMARY:
==5184==     in use at exit: 0 bytes in 0 blocks
==5184==   total heap usage: 2 allocs, 2 frees, 2,048 bytes allocated
==5184==
==5184== All heap blocks were freed -- no leaks are possible
==5184==
==5184== For lists of detected and suppressed errors, rerun with: -s
==5184== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Submit your work to Github

Add and check in your program using git and then push your changes to Github. Run the following command inside your A01 directory.

$ cd A01
$ git add *.c
$ git commit -m "Descriptive message"
$ git push

Run git status to check the result of the previous git command. Check the Github website to make sure that your program uploaded correctly.

5. (Optional) Set up your own development environment

Having your own development environment will allow you to write code outside of lab.

All programs must run on the lab’s Linux environment. Make sure you test your work on the lab machines if you work on your laptop!

5.1. Windows

  1. Open PowerShell and install wsl2: wsl --install. See documentation. Note that you may need to open powershell as an administrator.

  2. From the windows store, install Ubuntu.

Once installed, you can setup your development environment from a bash shell.

  1. Open PowerShell

  2. Type wsl to start the windows subsystem for linux. This will give your a bash prompt

  3. Then install your development tools

    1. sudo apt-get install cmake

    2. sudo apt-get install git

    3. sudo apt-get install g++

    4. sudo apt-get install vim

    5. sudo apt-get install libc6-dev-i386

    6. sudo apt-get install gcc-multilib

    7. sudo apt-get install hexedit

    8. sudo apt-get install valgrind

    9. sudo apt-get install gdb

For example, you get something like the following

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\alinen> wsl
WSL alinen@Balthazar:~$ sudo apt-get install make

etc
A quick way to open powershell is to type <WindowsKey>-'Q' and type 'powershell'.

5.2. MacOS

From terminal, run command xcode-select --install

You can follow the instructions here

Then, to install additional dependencies, execute the following commands form terminal

$ brew install vim
$ brew install git
$ brew install hexdump
$ brew install cmake
A quick way to open terminal is to use spotlight. From the keyboard, type the <cmd> and <spacebar>. Then type terminal at the popup edit field.

Unfortunately, valgrind and gdb cannot be run natively on mac. However, you may try running leaks or lldb which are similar. However, we recommend you still test on goldengate or a lab machine.

6. Grading Rubric

Assignment rubrics

Grades are out of 4 points.

  • Github setup (0.5 points)

  • Slack setup and introduction (0.5 points)

  • C program (3 points)

Code rubrics

For full credit, your C programs must be feature-complete, robust (e.g. run without memory errors or crashing) and have good style.

  • Some credit lost for missing features or bugs, depending on severity of error

  • -12.5% for style errors. See the class coding style here.

  • -50% for memory errors

  • -100% for failure to checkin work to Github

  • -100% for failure to compile on linux using make