Wyo C++ - Ch. 4 Worksheet #2 Name -

1. Identify each of the following as either a declaration statement (D), an initialization statement (I), an assignment statement (A), or a comment (C). Print the letters D, I, A, or C to the left of the statement. If a statement is both a declaration and an initialization statement then only label it as an initialization statement (I).

  a/ apples = 50;
  b/ int dollars;
  c/ // John Doe
  d/ cost = 0.50 * apples;
  e/ double cost = 0.0;
  f/ // variable declarations
  g/ const double SALES_TAX = 0.06;

2. Which data type - char, double, and int - is most appropriate for a variable that would be used in a program to store.....

  a/ the quantity of apples purchased
  b/ the cost of a daily newspaper (in dollar units)
  c/ the number of people that live in New York City
  d/ the number of people that live on Earth
  e/ the letter grade that you expect to earn in this CMPSC 101 course
  f/ the total tips earned by a bartender in one evening (in dollars)
  g/ a constant used to store the number of hours in a day


3. Write a single cout statement that would display your first and last name separated by a single space on one line of output along with your phone number on a second line of output. Do not use two cout statements.

 

4. Write a single assignment statement that would compute the number of bagels purchased and store that value in an int variable named totalBagels, assuming that the variable dozenBagels stores the number of dozens purchased.

 

5. On the back of this paper, write a program that prints the your first name 10 times across the screen with exactly 5 blank spaces between each occurrence of your name. Don't worry about word wrapping occuring in the output window but make sure that no lines of your code would be cut off by the printer if the source file were printed.