Next: Exercises Up: A simple C++ program Previous: Multiple Choice Questions

Review questions

  1. Write a constant declaration that declares constants to hold the number of days in a week and the number of weeks in a year. In a separate constant statement declare a constant pi as 3.1415927.
  2. Write declaration statements to declare integer variables i and j and float variables x and y. Extend your declaration statements so that i and j are both initialised to 1 and y is initialised to 10.0.
  3. Write C++ instructions to ask a user to type in three numbers and to read them into integer variables first, second and third.
  4. Write C++ instructions to output the value of a variable x in a line as follows:
    The value of x is ......

  5. Write C++ instructions to generate output as follows:
    A circle of radius .....
              has area .....
     and circumference .....
    
    where the values of the radius, the area and the circumference are held in variables rad, area, and circum.
  6. Correct the syntax errors in the following C++ program:
    include iostream.h
    
    Main();
    {
     Float x,y,z;
     cout < "Enter two numbers ";
     cin >> a >> b
     cout << 'The numbers in reverse order are'
          << b,a;
    }
    
    Download copy to try it.

  7. Show the form of output displayed by the following statements when total has the value 352.74.
    cout << "The final total is: " << endl;
    cout << "$" << total << endl;
    

  8. What data types would you use to represent the following items?
    1. the number of students in a class
    2. the grade (a letter) attained by a student in the class
    3. the average mark in a class
    4. the distance between two points
    5. the population of a city
    6. the weight of a postage stamp
    7. the registration letter of a car

  9. Write suitable declarations for variables in question 8. Be sure to choose meaningful identifiers.


Next: Exercises Up: A simple C++ program Previous: Multiple Choice Questions