Using the C++ Compiler on Paprika

A. Creating a C++ Program File

  1. Login as usual
  2. At the $prompt type vim yourfilename.cpp
  3. When the empty workspace appears, press a to go into "append" mode so what you type is put into the workspace.
    Continue to enter your source program.
    You must press ENTER to move the cursor to the next line.
  4. Type each line as needed. The vi editor will automatically indent each line to align with the previous line. Press TAB to indent and CTRL-D to move back one tab.
  5. After completing the entry of your program, press ESC and then enter :wq

B. Compiling a C++ program

  1. At the $ prompt start a script file and invoke the C++ compiler
    by entering
         script listing
       cpp yourfilename.cpp -o yourfilename.R
       exit
  2. These commands will result in the following:
    Your source program (yourfilename.cpp) is examined for syntax errors by the compiler and if there are any they are displayed on the screen and copied to the file named listing.
  3. You can print the file named listing by entering
        lp listing
  4. If there are no errors then the file machine language file yourfilename.R is created. It contains the executable version of your program.
  5. If your source file contains syntax errors then use the vi editor to correct them. Enter
        vim yourfilename.cpp
    Save the modified version using :wq
    Go back to step 1 in this section.

C. Executing a program

  1. If your program compiled (if there were no errors reported in the steps in the previous section) then an executable program was produced. To execute it, at the $prompt enter
           yourfilename.R
  2. If your program fails to run to completion, doesn't stop running, or otherwise fails to run as you expect then you're going to have to find the source of the problem.
    Try reading the source file again to see if you can spot a flaw in the logic.
    Another way to approach this problem is to put cout statements at strategic points in your program and noting where execution was suspended.
    Modify the source file by using the vim editor, as described above, to correct the situation.
  3. If your program runs to completion then examine the results to verify that the program yields correct results. If there is problem then you'll have to reread the source, use cout statements and vi as described above.

D. Preparing your assignment for submission

  1. Compile your program using
    cpp yourfilename.cpp -o yourfilename.R
  2. Open a script file to capture the results
    script results
  3. Execute your program
    yourfilename.R
  4. Close the file opened with script
    exit
  5. Append line numbers to your source file using
    cat -n yourfilename.cpp >> results
  6. Print
    lp results