Using the C++ Compiler on Paprika
A. Creating a C++ Program File
- Login as usual
- At the $prompt type vim yourfilename.cpp
- 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.
- 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.
- After completing the entry of your program, press ESC and then enter :wq
B. Compiling a C++ program
- At the $ prompt start a script file and invoke the C++ compiler
by entering
script
listing
cpp yourfilename.cpp
-o yourfilename.R
exit
- 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.
- You can print the file named listing
by entering
lp listing
- If there are no errors then the file machine language file yourfilename.R
is created. It contains the executable version of your program.
- 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
- 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
- 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.
- 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
- Compile your program using
cpp yourfilename.cpp
-o yourfilename.R
- Open a script file to capture the results
script results
- Execute your program
yourfilename.R
- Close the file opened with script
exit
- Append line numbers to your source file using
cat -n yourfilename.cpp
>> results
- Print
lp results