Homework 3

Note there are three parts here: part A, B, C.

Part A.  Identify which of the following are legal variable names.  For those that are not legal, indicate why.

  1. theUnitedStatesNavalAcademyIsLocatedInAnnapolis
  2. average CPR     
  3. class_Of_83                
  4. averageSum
  5. 7thCompany


Part B. The purpose of this homework is to ensure you have installed Visual C++ 2005 Express Edition. Do not worry if you do not understand everything you are typing; it will be explained as the course progresses.  This part is designed to be completed ON YOUR OWN MACHINE IN BANCROFT after Lab 1. Do the following:

1.      Complete steps 1-5 of lab 1.

2.      In place of step 6 copy the following code:

#include <iostream>


int main () {


            std::cout << "Midn YOURNAMEHERE YOURALPHAHERE installed express 2005 correctly!" << std::endl;


                        return 0;



  1. Enter your name and alpha at the appropriate points in the code.
  2. Complete steps 7 – 10 of lab 1.
  3. Print out a screen shot (see directions below) of your program running and turn it in to your instructor at the beginning of the next lecture.


Obtaining a Screen Shot:


1.      Click anywhere on the display containing program output.

2.    Press Alt-printscreen to “capture the screen shot”

3.    Open microsoft paint start -> all programs -> accessories -> paint

4.    Paste the image into paint by selecting edit -> paste

5.    Print the image by selecting file -> print.  OR you can paste into Microsoft Word and use that.


Part C: Copy and paste the following program into the Microsoft Visual C++ and compile.  Examine the errors generated by the compiler, then FIX each error.  Turn in a printout of the source code for your (fixed) program AND a printout of the screenshot showing your program running.


// cents.cpp

// Convert nickels and dimes to cents.

#include <iostream>

using namespace std;


int main()


   int nickels, dimes, cents;

   nickels = 3;

   Dimes = 7;

   cents = 5 * nickels + 10 * dimes;

   cout << nickels << " nickels and ";

   cout << dimes << " dimes " << endl;

   cout << "= " << cents << " cents "

   return 0;