Editing the Program


In addition to all the XEmacs commands you are already familiar with, the Resolve/C++ environment defines a number of additional commands. Notice the menu titled "Resolve/C++" in addition to the other XEmacs menus. This menu contains some special commands that will simplify your task. You will see how most of them work in this walk-through. Also notice how some of the words of the program are bold or have different colors. For example, comments are brownmost keywords are bold black, and names of #include files are green. This will prove to be of great help in recognizing when you incorrectly type a keyword or when you forget to close a comment, for example.

Your XEmacs window should look something like this.

Now let us begin completing and debugging the program.
 
Start by marking the first three lines of the program (i.e., the first three lines in the XEmacs buffer) using the mouse, as follows:
  • Press the left mouse button at the beginning of Line 1 and drag the mouse to the end of Line 3, keeping the button pressed while dragging, and then release the button. This selects the "region" (shown in gray) as the text to be operated on in the next step.
  • Choose the "Comment Out Region" option from the "Resolve/C++" menu. 
  • Note that you can press Ctrl-c Ctrl-c to do the same thing. The three lines of text are now preceded by // to mark this as a comment. A comment is not included as part of the executable program. This can be very useful when you are trying to debug a program and want to comment out a portion of your code in attempt to locate the error. Later you can uncomment that portion of the code by selecting the commented code with your mouse, and then choosing the "Uncomment Region" command from the "Resolve/C++" menu.

    Now go to the end of the program. After the comment that reads // Close input and output streams, we need to add a statement that closes the output stream. In Resolve/C++ programs if you open up a Character_IStream or Character_OStream object you must remember to close it.
     
  • Go to the end of the next-to-last line (the one just before the "}") and type the Enter (or Return) key, followed by
    output.Close_External ();
  • Note that the line is automatically indented when you press Enter, which is something you can do manually for any line by pressing the Tab key while anywhere on the line. In other words, Tab doesn't insert a tab character when you're using Resolve/C++ mode in XEmacs, but indents the line to where XEmacs thinks it should be. That it is indented too far is an indication that XEmacs thinks there is a syntax error somewhere above it. We will find and correct this error later. In the absence of such syntax errors, the current line would usually be aligned with the rest of the statements.

    Occasionally you might have to manually change the indentation from what XEmacs wants to do. However, if you find yourself doing this a lot, then probably you're making it hard on yourself by trying to use different indentation conventions than XEmacs tries to support. We strongly recommend sticking with the indenting conventions used in code samples, which is what XEmacs automatic indenting tries to achieve, and usually (but not always) does.

    Save the current version of Euclid.cpp by using the "Save Euclid.cpp" command from the "File" menu or by pressing Ctrl-x Ctrl-s.



     
    Previous Table of Contents Continue


    Last modified: Fri Dec 15 15:45:44 EST 2006