Objectives and Overview: This lab will help you become familiar with writing and running C++ programs using the CodeWarrior system on a Mac PowerPC. It will also help you become familiar with basic C++ syntax and its differences from Pascal.
The document Writing CodeWarrior C++ Applications contains a complete tutorial for starting CodeWarrior on the Macs, and writing and running a C++ program. Please complete this tutorial before going on to Part 2.
After you finish this tutorial, notice that there is a folder called Courses -> CS210 (Tucker) on the Mac desktop, which has two items inside it (see below):
The Drop Box folder is the place where you drag completed C++ program files to turn them in. To ensure your identity, please add your name to the program file before submitting it. For instance, if I have just finished writing and testing the program myfirst.cpp, I would rename it myfirst.atucker.cpp before dragging it to the Drop Box.
The source folder contains the C++ source code for all the programs and classes shown in your text. You may copy and run any these programs as you need them to complete assignments or clarify the discussion in the text.
The first few lines of a program that appears on page 22 of your text are shown below. A complete electronic copy of this program is in the source folder as the file named GetInts.cpp.
This program reads an arbitrary number of integers and then displays them. It allocates an array that grows dynamically in response to the size of the input.
The program exhibits several Pascal-like ideas in C++ form -- assignment statements, arrays, for loops, if statements, and output statements. To exercise this program, follow the steps below (starting from the project Lab1 which you created in Part 1.
Your project window should now look like this:
Now run this program (using the Project -> Run menu option). The output should appear in a window like the one shown below; this window is also used for typing input. For instance, when you type the integers shown on the first line, a fresh copy of these integers will be listed below that line. Note that you must signal the end of your input by typing ctrl-d.
Your new program should ba named myfirst.cpp, and will have a similar overall structure to the one discussed above. However, its output should be a rearrangement (sorting) into ascending order of the integers entered, along with a count of the number of integers that are negative, zero, and positive. For instance, the above input should yield the following output:
You may use any sorting algorithm that you know, as long as it is written as a separate C++ function with parameters Array and NumItems (the array and its size) and it calls the function SwapRef shown on page 31 of your text.
Now submit your revised C++ program from Part 4 of this lab by dragging it to the CS210 (Tucker) -> Drop Box folder. Don't forget to rename your program file by affixing your name to it. For example, if I were submitting it, the program file would be called myfirst.atucker.cpp, not just myfirst.cpp.
Also, hand in a hardcopy listing of your program with your name on it, along with the answers to the questions in Part 3.