School of Computing
College of Engineering
University of Nebraska-Lincoln
This lab introduces you to your programming environment and the software development workflow and handin/grading process used by this course.
In each lab there may be pre-lab activities that you are required to complete prior to attending lab. Failure to do so may mean that you are not prepared to complete the lab.
-
For this lab, you'll need to sign up with GitHub, a website that hosts software repositories using git (a distributed version control system). With GitHub you'll be able to store, manage and backup your source code. Git is an essential software development tool that you'll want to fully utilize.
Go to https://github.com and sign up if you don't have an account already.
-
Accept the invite that your instructor sent out from codepost.io and be sure you can sign in. Graders will provide line-by-line feedback on your hacks, exams and other assignments using this site.
Some other School of Computing (Soc) and university computing resources and policies can be found at the following:
-
SoC Website: http://computing.unl.edu
-
UNL Computing Policy: http://www.unl.edu/ucomm/compuse/
-
SoC Academic Integrity Policy: http://computing.unl.edu/academic-integrity-policy
-
SoC System Frequently Asked Questions (FAQ): http://computing.unl.edu/faq
-
SoC Undergraduate Advising Page: http://computing.unl.edu/advising
-
SoC Student Resource Center: http://computing.unl.edu/src
For students in online section(s): you may complete the lab on your own if you wish or you may team up with a partner of your choosing.
For students in the on campus section: your lab instructor may team you up with a partner.
To encourage collaboration and a team environment, labs are be structured in a peer programming setup. At the start of each lab, you will be randomly paired up with another student (conflicts such as absences will be dealt with by the lab instructor). One of you will be designated the driver and the other the navigator.
The navigator will be responsible for reading the instructions and telling the driver what to do next. The driver will be in charge of the keyboard and workstation. Both driver and navigator are responsible for suggesting fixes and solutions together. Neither the navigator nor the driver is "in charge." Beyond your immediate pairing, you are encouraged to help and interact and with other pairs in the lab.
Each week you should alternate: if you were a driver last week, be a navigator next, etc. Resolve any issues (you were both drivers last week) within your pair. Ask the lab instructor to resolve issues only when you cannot come to a consensus.
Because of the peer programming setup of labs, it is absolutely essential that you complete any pre-lab activities and familiarize yourself with the handouts prior to coming to lab. Failure to do so will negatively impact your ability to collaborate and work with others which may mean that you will not be able to complete the lab.
At the end of this lab you should be familiar with the following
-
The Visual Studio Code IDE that you'll use for this course
-
Basic unix commands
-
Cloning lab code from Github
-
Modifying, compiling and executing your first C program
-
Using codepost.io to view grader feedback
Let's get started. In order to develop programs in C you'll need:
- a code editor (plain text editor) to write your code
- a compiler to compile the C code into executable machine code, and
- a runtime environment to actually execute your program To do this, we'll walk you through how to use the Visual Studio Code (https://cs50.dev/) online IDE (Integrated Development Environment). This is a web browser-based IDE which means you don't have to install any software. It is free and you login using your GitHub account. It also offers a persistent environment: files you save in the IDE will be available next time you login.
- Point your browser to https://cs50.dev/ sign in with GitHub:
Be sure that you have enabled cookies in your browser
- The first time you'll be asked to authorize this site to access elements of your GitHub account, click Authorize cs50.
- Once logged in, it should looks something like the following.
- Observe the major layout areas:
-
File Explorer - This is a graphical file explorer in which you can right click and create new directories (folders) and files, drag and drop to move things around, etc.
-
Text Editor - Double click on a plain text file and it will open in this file editor so you can edit it. This is a tabbed environment so multiple files can be opened at once.
-
Console - this is a Text User Interface (TUI) console in which you can type and execute commands to compile and run (text-based) programs in a Linux (ubuntu) environment.
Let's get started an setup our environment.
-
First, we need to make some directories that we'll be using for the rest of the semester. Execute the following commands by typing each into the TUI console:
mkdir /workspaces/CS1 mkdir /workspaces/CS1/labs mkdir /workspaces/CS1/hacks mkdir /workspaces/CS1/misc
-
Next we'll create a symbolic link so that these directories will appear in the file explorer. Execute the following command:
ln -s /workspaces/CS1 CS1
-
Every time you start the IDE, your console will start out in a directory named something like
/workspaces/123456
, but we'll want to work in theCS1
directory where we made our directories. So, let's change directories by executing the following command:cd /workspaces/CS1
Note: you will need to change directories every time you login to your IDE (this is necessary because the IDE prevents you from using git in the
/workspaces/123456
directory for "reasons").HOWEVER: there is a nice permanent solution:
a) create a file in your file explorer and call it
profile
, edit it and place the following contents into it:echo "Moving to CS1 folder..." cd /workspaces/CS1
b) Copy this (configuration) file by executing the command:
cp profile /home/ubuntu/.profile
Now every time you login, the profile configuration will automatically take you to the correct directory in the terminal!
NOTE: if you ever update or "rebuild" your IDE, you will need to recopy this configuration file above to ensure you are in the correct directory.
You can create files in your IDE either by:
- Dragging and dropping files from your computer to the File Explorer or
- Right clicking a folder and selecting New File
-
Create a file named
info.md
(a markdown file) in themisc
directory and open it for editing by double clicking it. Enter your name in this file (changes are generally automatically saved). -
Now we'll get familiar with the console and some basic unix commands. Click in the console area. To execute a command you type it in the console and then hit enter.
-
Type the command
ls
(short for "list") and hit enter. This lists the files and directories in the current working directory. You should see your the three directories we created above. -
Let's change our current working directory so that we're in the
misc
directory. Type the following commandcd misc
(short for "change directory"). Typels
again and you'll see your the files in yourmisc
directory (should just be theinfo.md
file you created). -
You can determine where in the directory structure you are by typing the command
pwd
. Try it; you'll see that yourmisc
directory is actually under a/workspaces/12345678/CS1/misc
directory -
You can go back "up" the directory structure by typing the command
cd ..
(..
is short hand for the parent directory or one directory up in the hierarchy) -
You can also remove a file using the
rm fileName
command which will permanently delete the file. Careful, there is no undo or recycle bin! You can also remove a file by right clicking and deleting it in the File Explorer.
-
A more comprehensive tutorial on unix commands is available here: http://www.math.utah.edu/lab/unix/unix-commands.html.
Programming requires that you write code in a source file, a plain text file that contains syntactically valid programming commands. In general, you can use any plain text editor to edit code (MS Word is not a plain text editor). However, it is much better to use a text editor designed for code that uses syntax highlighting to help you differentiate various programming elements by highlighting them in different colors and fonts. This IDE provides such an editor. Let's practice writing some code.
-
In your
misc
directory create a new file namedhello.c
-
Open the file and edit its contents to look like the following but with your name and the current date.
/** * Author: Your Name * Date: 20xx/xx/xx * * A simple hello world program in C * */ #include <stdlib.h> #include <stdio.h> int main(int argc, char **argv) { printf("Hello World!\n"); return 0; }
-
Now let's compile this code into an executable program. In the console, type the following command (be sure you're still in the
misc
directory):gcc hello.c
gcc
(GNU Compiler Collection) is a C compiler. In general in unix/linux if a command is successful nothing will be displayed; "no news is good news." If you made a mistake the compiler will give you a (sometimes) helpful hint about what was wrong. If you made a mistake fix it and repeat until it successfully compiles. -
When successful, the compiler produces an executable file named
a.out
. Usels
to verify that the new file has been created. You should also observe that it has now appeared in the File Explorer. If it has not, you can click the refresh icon to refresh the File Explorer:
- Run your program by typing the following command:
./a.out
which should printHello World!
to the Console.
Congratulations on your first program!
Each lab will have some starter code and other artifacts (data files, scripts, etc.) that will be provided to get you started. The code is hosted on GitHub (https://github.com) and you must clone a copy of it to your own workspace.
-
Change your current working directory to your
labs
directory. To do this you can usecd ..
thencd labs
(assuming you are currently inmisc
) or you can do this in one step:cd ../labs
which means "go up one directory, then down to
labs
." -
To clone, use the the following command:
git clone https://github.com/cbourke/CSCE155-C-Lab01
-
A new directory,
CSCE155-C-Lab01
should be created, go into this directory by typingcd CSCE155-C-Lab01
-
List the contents of this directory by typing
ls
. If everything worked, there should be a (different)hello.c
file in your directory similar to the one you just wrote.
Boring. Been there done that. So, let's modify the program.
-
Open the
hello.c
source file (you now have two files with that name, so be sure you're editing the correct one or close the other). -
Modify the file by changing the author to you (and your partner if you have one) and change the date.
-
Add a new line below the line that prints
Hello World!
that printsI love the School of Computing!
using theprintf
line as an example. -
Save, compile and run your program to make sure it works.
Nearly all of your assignments (labs, hacks, exams) will include a programming portion that will require you to hand in source files for graders to compile and evaluate. To do this, we use a web-based assessment app called codepost.io (https://codepost.io).
You should have received an invitation to this website from your
instructor through your email account (typically your @huskers.unl.edu
email or whatever email you have associated with on Canvas). If
you have access, great. If not, go to https://codepost.io/forgot-password
and "reset" your password (even if you never initially set one). Be
sure to use your huskers email or whatever primary email is associated
with your canvas profile.
To handin and grade your lab, do the following.
-
First, we need to get your source file (
hello.c
) on to your computer. Right now, the files only exist on the IDE server. Right click on thehello.c
file and click download. -
Login to https://codepost.io. It should immediately take you to the assignment submission page:
- Click "Upload Assignment" which will bring up a dialog box:
Click "Upload files" and select the hello.c
source file you downloaded.
Then click
- You should see something like the following:
HOWEVER this does not mean that your program(s) worked, only that they were uploaded. You still need to view the results!!!
- Click on to view the test results which will give you more details. If any test(s) failed, you should see:
You can click on the + button to see more details. However, if all tests passed, you should see something like this:
Some things to understand about the grading process:
- If there are problems or errors with your program(s), you should fix/debug them and repeat the handin/grading process. You can do this as many times as you like up until the due date.
- Some programs and assignments may require the output to be exact including any upper/lower case text and numbers accurate to a certain number of decimal points
- Some programs and assignments may only require part of the output to be correct and may ignore other formatting (spaces for example).
- Some programs and assignments may need to be manually examined by graders to award points.
- Some programs and assignments have more sophisticated test suites that run hundreds or thousands of tests.
- In any case, it is your responsibility to read, understand and address any and all errors and/or warnings that the grader produces.
- The grader is a black box tester meaning you don't have access to its internal workings. You should properly and thoroughly test and debug your programs locally instead of relying on it as a "blind tester."
Congratulations on your first lab!