next up previous
Up: APS105F Home

APS 105F - Computer Fundamentals

Assignment #2:  Basic OOT

Fall 1997

(To be completed in your lab period Sept. 17/18)

 

Objective

Learn how to use OOT, and how to write simple programs, perform simple input, and format output.

Object-Oriented Turing (OOT) Environment

The OOT environment can be started up by entering the following:

spark1.ecf%  oot &

From the Object Oriented Turing Software Development Environment window that appears, select the ``Start Up OOT'' button. Three new windows will open up. At the top left is the OOT Control Panel Window. This window is used by you to issue commands for controlling OOT and also for OOT to display information messages to you. At the bottom left is the OOT File Viewer window. This is where your Turing programs will be composed and edited. It is essentially a text editor built especially for use with OOT. The OOT Directory Viewer window on the right allows you to look for files that are available in your directory and to retrieve program files that you will use in the File Viewer window. Remember, these three windows conform to the standard manipulations that could be done to any window in the X Window environment. You could move, iconify, resize and manipulate these windows much like you would the xterm windows. Furthermore, only the window that is pointed to by the cursor is the active window.

Look at the Directory Viewer window. If you started up OOT from your home directory, the window will list all the files and subdirectories of your home directory. Move into the aps105 directory by double clicking on aps105/ in the window. The window will now display the files located in your aps105 directory. If you wanted to move back to your home directory, you could double click on the ../ symbol in the window. (Remember that the .. symbol represents the parent directory.)

In Assignment 1, you put a program into your aps105 directory and called it test.t. To use the test.t program, it must be loaded into a File Viewer window. To do so, double click on test.t in the Directory Viewer window. A new File Viewer window appears on top of the old one and some text will be written inside. This is the test.t program. At the top of the File Viewer window, there are some control buttons used to manipulate the window and the file it contains. In one of these buttons appears the word ``Run''. Click on this button to run the program. (Or alternatively, with the cursor in the File Viewer window, enter Ctrl-R.) A new window, called an OOT Run window appears in which the execution of the program occurs. When you have finished watching the test program, click on the ``Close'' button in the File Viewer window to close the test.t file. (Or alternatively, enter Ctrl-W.)

Now it is your turn to create and run a simple program. In the original File Viewer window, type in the following one-line program: put "Hello World"

Now run the program (by clicking on Run, or entering Ctrl-R). If you have typed the line correctly, the output of your program will appear in a refreshed OOT Run Window. If errors are indicated, go back to the edit window, make corrections, and run the program again. If you get it right the first try, erase the closing quotation mark and run the program again and see what happens.

Save the program by dragging on the ``File'' menu button and selecting the ``Save'' option. A small dialog window will open up and prompt you for a file name. While pointing to this window, enter hello.t and hit RETURN. You should now see hello.t in the list of files in the Directory Viewer Window. Now in the File Viewer Window, point and click at the very beginning of the line put "Hello World". Hit the RETURN key to insert an empty line, click the cursor on this blank line and type in: put "5 + 3 = ", 5 + 3

Run the program and note that what is printed as a result of the second 5 + 3 is the actual value of this arithmetic expression, i.e. 8. Save the program as you did before. Notice that this time you do not need to enter the file name as the program will be saved under the previous name given: hello.t.

If you have to close down OOT now or before the end of this assignment, this is done by clicking and dragging on the ``File'' menu button in the Control Panel window and selecting ``Quit''.

2 Simple Turing Program With Input and Output

In the lectures, an example of a simple Turing program was shown. Based on this discussion and on the examples above, write a simple Turing program that solves the problem described below and call the program quad.t:  Obtain three values for the variables a, b, and c from the user. With these values, find the roots of the quadratic equation, tex2html_wrap_inline118

Does your program work for any values of a, b, and c?

3 Using Loops and Selection

Modify your program so that it repeatedly requests input for a, b, and c, and solves for the roots in the quadratic equation. When the input values are all zeroes, the program ends.

4 Optional Section

Each week, your lab assignment will include an optional portion at the end. This section describes additional exercises that will further your understanding of programming with OOT. These exercises are not compulsory to complete for your assignment mark.

4.1 Output Formatting

For this assignment, improve the formatting of the output and add input prompts to make what is written on the screen aesthetically pleasing. Although you do not need to do this as a requirement for this assignment, you will be expected to understand how to do this type of formatting in future assignments.

Specifically, work on the following:

You may need to look up the put, skip and get statements in the Turing Reference Manual. The program should output something like what is shown below:

                  Quadratic Equation Solver

This program accepts three values from the user that 
correspond to the three variables in the quadratic equation:

                     ax**2 + bx + c = 0

and solves for the roots of the equation.

Enter values -- all zeroes will terminate the program:
Enter the value of a:  5
Enter the value of b:  6
Enter the value of c: -7

The solutions of 5x**2 + 6x + -7 = 0 are

Root 1: 7.2665e-01
Root 2: -1.9266e+00


.... function repeats until all zeros are input


Enter values -- all zeroes will terminate the program:
Enter the value of a:  0
Enter the value of b:  0
Enter the value of c:  0


End of Program

4.2 Command Line Compilation

Turing programs do not have to be executed from the OOT environment. It is possible to run Turing programs from the UNIX command line prompt (which is useful if you happen to be logging in from home via a modem). In an xterm window, with aps105 as the working directory, enter the command:

spark1.ecf%   toot quad.t

The program executes directly from UNIX.

Try compiling your program using the Turing Plus Compiler with the following command:

spark1.ecf%   tpc quad.t

The compiler takes your Turing program and creates an executable file, and in this case calls it quad.x. An executable file is a self-contained program that can be run simply by typing its name, like a UNIX command. Try entering the following:

spark1.ecf%   quad.x


next up previous
Up: APS105F Home

Paul Chow
Thu Sep 11 13:47:39 EDT 1997