Closed Lab 3 – Honors 1170 – Fall 2003
Using NEdit and Writing Karel Program

 

Unix Review

In Lab 2, you found that the computer system you will use for CSCI 1170 is an HP9000. Its name is frank. Frank runs the UNIX operating system, an extremely powerful and popular system. If you are having any difficulty with Unix, I recommend that you read Tutorial One and Tutorial Two from Unix Tutorial for Beginners.  Even if you aren’t having trouble, you may have to refer to the tutorial to answer the following questions.  To help with these exercises, you may also refer to Lab 2 in the closed lab manual.


Exercise 1:  You may write (by hand) the answers to the following questions on a sheet of paper or you may type in the answers using notepad.  Give a Unix command or answer the following:

1.      Make a copy of the file document.txt and call the new file backup.txt

2.      Create a directory called goodPrograms

3.      Change to the directory goodPrograms

4.      Display the current directory on the screen

5.      Change back to the previous directory

6.      Remove the file backup.txt

7.      Display the contents of the file document.txt on the screen

8.      Get a printout of the file document.txt

9.      What does the symbol ~ mean?


Logging on to the Server
 

Exercise 2:
LOG ON USING THE X WINDOW SYSTEM: We will be using the UNIX X Window system for the exercises below. Do NOT use telnet for the exercises below.  

 

Note:  The XTerm  window is available in computer science labs on campus so for a while, you won’t be able to do this at home.

To connect to frank via the X Window system, we will be using the xterm program. Double-click the mouse on the XTerm frank.mtsu.edu desktop icon that looks something like this:


XTerm Icon

A box, similar to the one below, will pop-up.


XTerm Login

In this box, enter your username in the field labeled "User ID". After entering your username, use the tab key to skip to the field labeled "Password" and enter your password. Once both fields are filled in, click the "OK" button to log on. (If you have forgotten your username or password, ask the lab assistant for help.) If the log in is successful, an xterm window will pop up on the desktop. In this xterm window, you will find the UNIX  frank%   prompt at which you can enter UNIX commands. Once you are logged in, you need to arrange the windows for the browser and xterm so that one is not completely over the other. Click the left mouse button on the title bar of the xterm window, hold it down and drag the window until at least part of it is outside the browser window. It is OKAY to minimize an xterm window; for now, don't resize the xterm window. You can make either window active by clicking the mouse on it. Try that now and leave the browser window active.

 

If the font size is too small in the xterm window, you can simultaneously right click in the xterm window and hold down the Ctrl key.  This will cause a menu to pop-up from which you can select a different font size.


 

The "nedit" Editor


Read the following. Do not type in any commands until you start the next exercise!

In closed lab 2, we discussed the “vi” editor.  Today we will discuss the NEdit editor. In the computer world, an editor is a program that facilitates the creation and modification (editing) of a text file. For us the text file will usually be a C++ source file (i.e. a file of instructions to the computer written in the syntax of the C++ language). To create a new file, say lab.cc using nedit (technically, the real name is the NEdit editor), you would type

% nedit lab.cc

and press enter.


Exercise 3:
Drag the top or bottom border of the xterm window so it is as large as it will extend vertically.

Now type in a command in the xterm window that will start nedit and will create the new file document.txt

A new window, resembling a Microsoft WordPad window, should now open. If it does not, ask for help from your lab assistant.


Exercise 4:
Insert the following three lines of text:

                                                It is time for all
                                                good men to come to
                                                the aid of their planet.


Exercise 5:
We will continue to work on the three lines of text that we typed in above. We notice that we have made a mistake and we want the text to read "Now is the time" instead of "It is the time". Using the mouse, highlight the two letters of the word "It". Next type, "Now". We also want to insert the word the before the word time, so position the cursor at the t in time. Type the and a space. The corrections are done.


Exercise 6:  Place the answers to the following on your answer sheet.  Read the NEdit tutorial: http://www.sis.pitt.edu/~icucart/ssavor/index.html and read http://web.ccr.jussieu.fr/ccr/Documentation/Calcul/NEdit5.1/index.htm  (only the section “Features for Programming”).  Note:  The second URL contains nice documentation for NEdit 5.1 – we are using NEdit 5.3.  As you read these two documents, describe how you would do the following:

1.      Change the indentation (tab) level

2.      See what line you are on

3.      Search forward for a string

4.      Search backward for a string

5.      Enable syntax highlighting (also tell what this means)

6.      Find a particular line in a source program

7.      Save changes you have made without exiting, to be prepared in case of a power failure

8.      To exit nedit



Exercise 7:  Exit nedit.  Nothing will be turned in concerning the document.txt file.

 


Exercise 8:  Change directories to your closed lab directory.  What did you type to do this? Place your answer on the answer sheet.

 


Exercise 9:  In class on Friday, I asked you to write down a solution to the Newspaper retrieval problem.  Create a file called newspaper.cc that solves this problem.  You may use nedit or vi to type in your solution.  If you use nedit, set the language mode to C++ so you can see what syntax highlighting does for you.  After you have finished typing in your solution, exit the editor.


Exercise 10:  Compile your karel program by typing in the following command:

 

% kCC newspaper.cc –o newspaper

If the compiler generated errors, then they have to be corrected before continuing to the next step.  Thus you must open your program with the editor and correct any typing mistakes.


Exercise 11:  You will need a situation (beginning world) file to use with your karel program.  Copy the file pickpaper.wor to your account using the following command.

% cp $PUB/pickpaper.wor .                    (remember the dot at the end of this command is necessary)


Exercise 12:  Now run the program from Exercise 9 using the situation file from Exercise 11.  To do this, type:

% newspaper pickpaper.wor

Hopefully, karel will run outside the door and pick up his paper and return to bed with his paper in his beeper bag.  If he doesn’t, you may have to open your program using the editor again, make corrections, recompile, and run the program again.  Do not continue until Karel is behaving properly.

During a successful run of a karel program, a report file is automatically generated.  The report file will be saved in the file newspaper.wor.rpt


Exercise 13:  Now create a script log to be turned in at the end of lab today.  Type in the following commands to produce the log file.

% script log
% cat newspaper.cc
% kCC newspaper.cc –o newspaper
% cat pickpaper.wor.rpt          (notice I did not ask you to run your program – this would not be possible in a script log)
% exit



Exercise 14:  Type in a command to send your log file to the line printer.   Go pick up your printout.  This printout will be turned in at the end of the lab.


Exercise 15:  The wall sections in the figure below represent a mountain (north is  up). Write a Karel program to cause Karel to climb the mountain and then plant a flag, represented by a beeper, on the summit; Karel then must descend the other side of the mountain. Assume that Karel starts with the flag-beeper in the beeper-bag. Remember Karel is not a super-robot who can leap to the top of the mountain, plant the flag and then jump down in a single bound. As illustrated, Karel must closely follow the mountain’s face on the way up and down.

 

 

        

Type in your program using the editor, compile it, and run it with the situation file mountain.wor that can be copied from the $PUB directory.  Do not create a script log until Karel is doing what is required.  Only then should you create a script log (use the steps from Exercise 13) to demonstrate that you were successful with this exercise.  Print your log file.  This printout will be turned in at the end of lab.

Using the Web and Netscape

You've heard of the World Wide Web and "surfing the net." In Lab 1, you looked at some existing web pages. In this lab, you will modify your own Web page which was created for you when you customized your account. At the end of this section, you will be asked to print something that will be handed-in.

Modifying a Web Page:

 

The World Wide Web is like a giant electronic scrapbook. Using a program known as a Web Browser, you can read the pages in this scrapbook. There are several browsers; you will use the one called Netscape Communicator or just "Netscape", for short).

A URL is the name of a page--think of it as a unique identifier. URLs are case-sensitive. (Actually only part of a URL is case-sensitive, but it is better to be careful in specifying the whole thing for now.)

 


Exercise 16:  Open Netscape.  Take a quick look at your web page by typing in http://www.mtsu.edu/~xxxxxxx where xxxxxxx is replaced by your class account username. You will be modifying this web page during this section of the lab.


The objectives of this section include practicing our editing skills and creating a usable personal homepage (that you can later customize as you wish).

Your personal homepage must exist in a directory off your home directory called public_html. This directory was created for you when you "customized" your account.


Exercise 17:  Make the xterm window active. Change to the public_html directory by typing:
        cd
       
cd public_html


During customization, a skeleton home page file, index.html, was created for you. You just saw this home page as it would appear in the Netscape Web browser.


Exercise 18:  Using an editor of your choice make the following changes to index.html.  

Inside the index.html file, after the line containing the sentence
This Web page was constructed as part of my CSCI 1170 course.
enter the following HTML code:

       <UL>
       <LI>  Major:  MAJOR
       <LI>  Hometown:  HOMETOWN
       </UL>

substituting the name of your major and hometown for MAJOR and HOMETOWN. When done, save and exit

SAMPLE HTML: Below is an excerpt of an example index.html file showing what the modified section of HTML should look like after you've made the required changes. (Of course, your major and hometown may differ.)

<HR SIZE=3>
 
Hi!  I am a student at <B>Middle Tennessee State University</B>.
<BR>
This Web page was constructed as part of my CSCI 1170 course.
<UL>
<LI>  Major:  Computer Science
<LI>  Hometown:  Tullahoma, TN
</UL>
 
<HR SIZE=3>

If you have been successful, you can view your changed homepage using Netscape. Make the Netscape window active and click on the "Reload Current Page" button.

After modifying your homepage as described above, use the Print tool icon on Netscape to print a copy of your homepage. Label your output with your name and course-section number (e.g. CSCI 1170-06) in the upper right-hand corner of the first page and hand it in along with the other requested items.  


Congratulations!!  You have reached the end of this lab.  Turn in the two printouts from the Karel programs, the printout of your web page, and your answer sheet to the lab assistant.