The objective of this first lab session is for you to practice some basic commands of the Unix operating system, and to use the g++ compiler to translate a C++ source file into a machine language file that the computer can actually run.
mkdir CS1005at the Unix prompt.
cd CS1005 (press enter)To double check that you're in the right place, print the name of the current working directory by typing
pwd (press enter)This should display a long string of characters ending in CS1005. The characters preceding CS1005 constitute a "pathname", meaning a sequence of nested directory names that specify the location of the CS1005 directory within the global Unix directory structure.
cp /cs/cs1005/samples/lab1/lab1.cxx ./ (press enter)Note the full pathname for lab1.cxx. The period+slash at the end is shorthand for the current working directory.
ls (enter)at the Unix prompt. The listing should show the newly copied file lab1.cxx. For a more informative listing, use the -l option:
ls -l (enter)This will display file sizes, the date/time when each file was last modified, as well as other file information. To explore the ls command further, look at the relevant manual pages by typing
man ls (enter)
more lab1.cxx (enter)Notice that the C++ program in lab1.cxx is made up of a main() function plus two other functions: ReadNumber() and NextNumber(int). Study the program to understand what it is intended to do.
g++ -o lab1prog lab1.cxx (enter)at the Unix prompt. This produces an executable machine language file named lab1prog. If you're curious, type
man g++ (enter)at the Unix prompt for information about other compiler options and details.
lab1prog (enter)If this doesn't run the program, you may have to explicitly tell the operating system to look for the program in the current working directory, by typing
./lab1prog (enter)Try the program out using different input values. Is it clear to you how the output values are related to the input values?