Programming at CMU
Following is a step-by-step description of how to compile and run
the ``hello, world'' C++ program using Metrowerks CodeWarrior.
Go through the steps, trying to understand what you are doing.
If you get stuck, ask a classmate or a PGSS CS staff member for
help.
(Most of the Macintosh computers around campus also have
Metrowerks CodeWarrior, and the programming procedure for them
is nearly identical to what appears here.
Feel free to use them, especially if all the PCs are occupied.)
The CodeWarrior environment is slightly nonstandard; it requires
a additional line reading ``using namespace std;''.
#include <iostream>
#include <string>
using namespace std;
int main() {
// this program prints the words ``hello, world'' and exits
cout << "hello, world" << endl;
return 0;
}
- Find a PC and log in with your Andrew ID and password.
Start up CodeWarrior by choosing
``Programs:Programming:CodeWarrior 4.0:CodeWarrior'' from the Start
menu on the bottom left-hand corner of the screen.
- Set up the project. A project tells CodeWarrior which
pieces to put the program together in order to build the program.
- In CodeWarrior, select New Project... from the File menu.
This will bring up a dialog box labeled ``New Project''.
Open up the ``Win 3.2-x86'' submenu by
clicking on the plus sign next to it. Now open up the ``C, C++''
submenu. And finally select ``C++ Console App''.
Click OK.
- A new dialog box ``Name new project as'' asks you where the
project should go. From the menu beneath the ``Save in'' text field,
choose the ``home on...'' disk. Double-click the ``private'' folder
in the main part of the dialog box. Type ``helloworld'' in the
``File name'' text field, and click Save.
- Now a window titled ``helloworld.mcp'' should appear.
This is the project window.
- Open up the ``Sources'' submenu of the project window.
Double-click on ``hello.cpp''; this should bring up a window titled
``hello.cpp'', which is where your program should go.
- Write the program.
- Replace the contents of the ``hello.cpp'' window with the
``hello, world'' program listed above.
- To run your program, select Run from CodeWarrior's Project
menu. This should compile the program and (if you wrote the
program perfectly) run it. The program will run in a black MS-DOS
window. When the program finishes, the window will display
``Press Enter to continue''. Do so; you should return to
CodeWarrior automatically.
- Now see what happens if the program has an error. Insert a
compile-time error into ``hello.cpp'' by removing a quotation mark.
Try running the program again; a window should appear labeled ``Errors
& Warnings'' describing problems with the program. Close the window
(click in the X at the upper right side of the title bar),
fix the problem, and run the program again to make sure it now works.
- Hand the assignment in.
Remember: When you do a programming project as a team, you should
only submit the project once for the entire team.
- You're done with the assignment. Copy the entire program to the
clipboard by selecting all your code in the ``hello.cpp'' window and
choosing Copy from the Edit menu.
- Enter Netscape Navigator. (It's
``Programs:Communications:Netscape 4.08'' under the Start menu.)
- Go to www.cburch.com.
Log into the Web page by typing your login id and password beneath the
menu on the
left-hand side of the page and clicking ``Log in''.
(Select Continue whenever you see the dialog box about insecure
transmission.)
- Hand in your assignment by going to the `handin' section
via the left-hand menu.
Fill out all the blanks required. When you get to the Answer
section, paste the clipboard by clicking in the Answer text area
and choosing Paste from the Edit menu.
Now click on the Submit button. (Again, select Continue if warned
about insecure transmission.)
- To make sure this worked, go to the `grades' portion of the page
and click ``program 1 handin''. If your program appears,
your assignment has been successfully submitted.
- Be sure to log out of the computer when you're finished,
by selecting Shut Down from the Start menu and clicking Yes.