CS35 Lab 0: Git and C++ warm-up

Due 11:59pm Sunday, September 10, 2017.

The goals of this lab are to:

This is an individual lab to help you learn the basic C++ syntax, so try to complete it on your own.

As with all lab assignments this semester, you will use git to get starting files as well as handing in your assignments.
Using Git

Git is a popular piece of open-source software which is installed on the Swarthmore CS computers. Git is a version control system---it can be used to manage changes and updates in software and facilitate collaborative programming across large teams of developers. We'll be using git to manage assignment distribution and submission. When you start an assignment, you'll execute a git command to grab some starting files. Similarly, when you want to submit an assignment, you'll execute a couple of git commands. Later on in the course, you'll be using git to facilitate paired lab assignments.

Git is a large piece of software, and there is a lot to learn with git. Fortunately, it is easy to get up and running on git with just a small number of commands.

  1. There are a couple of steps you need to take to start using git. First do the initial setup steps listed here.
  2. Create a cs35 folder and change to that directory
    cd ~/
    mkdir cs35
    cd cs35
    
  3. Finally, clone the git repo for lab00 by executing this command:
    git clone git@github.swarthmore.edu:CS35-F17/lab00-<user>.git  ./lab00
    
    where <user> is your username.
  4. At this point, you should have the lab starter code and be ready to program the lab.
  5. We recommend that you read the "Commands for using a git repo" that lists the commands that you will need to submit your lab assignments. In particular, you should understand how to use "git add", "git commit" and "git push".

This might seem like a lengthy sequence of commands to remember, but don't worry! We'll go over this in lab next week, and the commands will be the same for each assignment during the semester.

To recap, the git commit cycle is git add, git commit, git push. Don't forget to git push when you have completed an assignment.

Programming Exercises
In this part of the lab, you will create some simple C++ programs using the coding skills you've recently gained.
  1. Strings, Input/Output: In the file greeting.cpp, write a short program that asks the user for their name, and then greets the user using that name. For example:
    $ ./greeting
    I am a computer greeting program.
    What is your name?  Alice
    Hello Alice, it is nice to meet you!
    
  2. Loops: In the file guess.cpp, write a program that repeatedly asks the user to guess a number between 1 and 10, until the user enters such a number. Then, tell the user they guessed correctly. Feel free to "cheat" and always assume the user guessed correctly! Or pick a number in advance and print an appropriate message if they guessed incorrectly. For example:
    $ ./guess
    Please guess a number between 1 and 10.  12
    Please guess a number between 1 and 10.  0
    Please guess a number between 1 and 10.  -4
    Please guess a number between 1 and 10.  6
    You guessed: 6.  That's the right number.
    Good job!
    
    You can assume the user will enter an integer, but don't the user enters an integer in the proper range.

Compiling and testing

Compile, run, and test your program with the C++ compiler clang++
clang++ greeting.cpp -o greeting
./greeting

clang++ guess.cpp -o guess
./guess

Submit

Once you have edited the files, you should publish your changes using the following steps:

$ git add greeting.cpp guess.cpp
The git add step adds modified files to be part of the next commit to the github server.
$ git commit -m "completed lab0"
The git commit step makes a record of the recently added changes. The -m "completed lab0" part is a descriptive message describing what are the primary changes in this commit. Making a commit allows you to review or undo changes easily in the future, if needed.
$ git push
The git push command sends your committed changes to the github server. If you do not run git push before the submission deadline, the instructor will not see your changes, even if you have finished coding your solution in your local directory.

If you make changes to files after your push and want to share these changes, repeat the add, commit, push loop again to update the github server.

To recap, the git commit cycle is git add, git commit, git push. Don't forget to git push when you have completed an assignment.

DO NOT add the compiled programs greeting and guess. git is only for maintaining human created files, not files generated automatically by the compiler.

You can review the basic git commands on the github help pages. Eventually, you should get in the habit of using git status to see if everything has been published, but we will talk about this more throughout the semester.

Remember to add, commit, push. You may commit and push as often as you like, and only the most recent push will be graded.