Homework 3

 

1. 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

 

2.   Copy and paste the following program into a new main.cpp and compile (use VMWare or putty or whatever you like to get access to a g++ compiler). 

Examine the errors generated by the compiler.  For EACH error reported by the compiler, circle the line causing the error, and indicate what would need to be changed on the line in order to remove the error.  

 

// 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;

}

3. Using your favorite editor and compiler/linker fix each compiler error in question 2 above.   

Turn in: Printout this homework assignment and annotate with your answers to questions 1 and 2. For question 3, attach a printout of the source code for your program (e.g., the fixed main.cpp), and a screen capture of the window showing your program successfully compiling (also executing the program is encourage but optional).  See these suggestions on screenshots and printing. Don't forget to also turn in the answers to questions 1 and 2.