Date: Tue, 05 Nov 1996 20:57:53 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Fri, 06 Sep 1996 19:01:56 GMT Content-length: 5194 Getting Started in CS367

Getting Started in CS367

I highly recommended that you immediately start learning the applications that you will be using to develop your CS367 programs. The environment in which you programmed in CS302 has differences than the one you'll use in CS367. Besides changing from the Macintosh or DOS/Windows operating system to UNIX, you'll also be working outside an integrated development environment. Many of the tools you've used before are still present, but as independent applications.

Since you are reading this page I am assuming that you have successfully created your computer science account using newuser and are now logged in. The following exercise takes you through the steps to get your first C++ program compiled and running under UNIX. I have provided a sample program that plays the game tic-tac-toe for your use and experimentation.

While working on this exercise, you will be reading pages that indicate UNIX commands to enter. These commands are preceded by a % , which it represents the UNIX prompt. You should not enter the % .

First, in your private sub-directory create a directory named P0 (i.e. Pzero). If you are unfamiliar with how to do this see the page on how to create a directory. Next get a copy of the sample tic-tac-toe program. This sample program can be obtained from the samples page that is linked to the CS367 home page. During the semester I will be providing sample code for data structures that we discuss in lecture. Find this link by going back to the CS367 home page and looking for the sample page link. If you are having difficulties, click here to go directly to that page. Further instructions are provided in the samples page for getting a copy of sample code files such as for this case tictactoe.cc.

Now that you have a copy of the source file for the tic-tac-toe game you should look at it with and editor. See edit your program for more information on how to edit your program. You do not need to make any changes to compile the program, which will be the next step. Before compiling the program I suggest that you open another terminal window. This can be done by clicking the left mouse button anywhere on the background and selecting Xterm from the pop-up menu. More information about the X-window system is available here. This new xterm window will be used for compiling your program. Change directories to the location where you have copied the source code by entering:

	% cd private/P0

You may compile your program by entering the g++ compiler command below. This command assumes that the source file is named tictactoe.cc.

       % g++ -Wall -g -o tictactoe tictactoe.cc
For more information about the compiler flags see the page on compiler flags.

When you are developing your own programs you usually encounter compilation errors. These are typically syntax errors that prevent the compiler from creating an executable version of your program. In this case you would need to go to your editor window and make corrections to your source code. For this program you should not experience any compiler errors, unless you accidentally changed the source with the editor. In that case you can simply get a new copy of this sample code.

The next step after your program compiles would be to run your program. This is doen by entering the following at the UNIX shell prompt:

       % tictactoe
More information about running programs is located here. While developing programs it is prefered to run your program in a debugging environment. In UNIX this requires you to execute another application as shown below.
       % gdb tictactoe
This start the debugger and allows you to control the execution of your program with breakpoints and by stepping through the program's instructions, and to examine the contents of variables and other memory locations. Two important commands for the debugger are run, which begins execution of you program, and quit to end the debugger. The are many other commands and some of the most useful are described here.

What you have completed above is called program development cycle: edit, compile, debug, repeat until it works. However I have made a working program for you, which simplifies the process a great deal. More information about the program development cycle can be obtained from the Working with C++ in UNIX page. Real practice is obtained by writing and debugging your own C++ program. See program 0 for more information.