CS107 - Lab 7
High Level Languages and C++ Programming

Due Thursday 04/01

Overview:

This assignment introduces the elements of C++ programming. The key challenge here is, "How do software designers write programs for real applications, and how are they translated (compiled) to run on a computer?" The readings and exercises for this assignment are taken from portions of chapter 7 of your text.


Compiling and Running a C++ program

Following the same steps that you used for Assignment 2, double-click the icon csci107 - Invitation (OSX) that you copied to the desktop. The button C++ Compiler is used for this assignment. To get started, Open the file example1.cpp in the Desktop -> Invitation -> Examples directory, and then select Compile in the Compiler menu. A window should appear on your screen. This window has two columns. On the left is a listing of the original C++ program and on the right is a copy of that listing that is checked for errors and compiled (The actual machine code doesn't appear here). Now select Execute in the Compiler menu, and then select the Run button at the bottom.

Load in turn each of example2.cpp, example3.cpp,example4.cpp and example5.cpp, Compile them and execute them. Look at the code and at the output.

1. Describe briefly in English what each program does.

2. Now open, compile, and run the program "fig25.cpp". Describe briefly in English what this program does.

3. Write a C++ program that computes the sum of two m-digit binary numbers. Assume that m <= 10. The program should ask the user for the value of m and for two m-digit binary numbers and should output the resulting sum. This program should behave just like the pseudocode algorithm that we first saw in Figure 1.2, but now it's been rewritten in C++. Submit your completed program to the csci107 -> Drop Box.

4. Write a C++ program that reads integer values until a 0 value is encountered and then writes out the sum of the positive values read and the sum of the negative values read. Submit your completed program to the csci107 -> Drop Box.

Algorithmic Problem Solving

Complete Exercises 2, 5, 6, 11, 14, 19 and 22 on page 367 of your text.



You may do these exercises (except the last one) either by hand or with a word processor (e.g. MS Word). Also, you may choose to do this assignment either by yourself or in a group. However, solutions should be written up individually and handed in on the due date.

To submit a file electronically, you should first rename it so that you are identified as the author (e.g., give it a name like lab-x-ltoma). Then drag the file to the csci107 -> Drop Box folder. Be careful not to drag an entire folder into the Drop Box; only a single file at a time can be submitted.

Once you are finished in the lab, be sure to drag the CS107 icon to the Trash - this step disconnects you from the server and prevents someone else (who may use this iMac later in the day) from accidentally accessing files in your personal folder.