Setting up for the course:
In your home directory create a new directory for programs in this course and set the permissions for this directory. Call it cs203, for example. For each program you write, create a new directory within cs203. Call the directory Lab1 for lab 1, Assignment1 for assignment 1, etc. Naming them properly is important so that I can easily find the correct program in your submit-folder later on. The commands to create the directory and set the permissions are:
$ mkdir <dirname> $ chmod 700 cs203
Create a directory for Lab 0 in your cs203 directory. Open an editor, create a simple program, and save it as lab0.cpp in your Lab0 directory. You can use the gui editor gedit, or if you are using a text based screen you can use the editor nano. The editors vi, vim, emacs, and others may also be available if you wish to use them.
Create a test program:
Here is a very simple program:
//Hello world program
#include <iostream>
//function main begins program execution
int main()
{
std::cout << "Hello world! \n"; //output statement
return 0; //signifies a successful conclusion
} //end of function main
Compile your program:
In a terminal, go to the Lab0 directory: cd ~/cs203/Lab0
The compiler is called g++, so you would compile the program as:
g++ lab0.cpp -o lab0
The -o option specifies that the name of the executable produced by the compiler will be called lab0. If you leave it out, the default output program is called a.out.
Run your program:
If you then type lab0 you will get an error message saying something like, “Program not found.” This is because your directory is not on the Path for your account. This is a Good Thing ™, so that if you inadvertently give your program a name that is the same as the name of a system program your program will not hijack that name and possibly cause your system to mess up.
To run your program you must include the path in the command. If you are in the lab0 directory the command is:
./lab0
The dot refers to the current directory (assuming you are in the Lab0 directory).
Submit your program:
When your program compiles and runs correctly, submit it by going up to the parent directory with the command:
cd ..
and typing:
submit203 Lab0