CS 1620 Assignment #6 Spring 2001

How to handin.
Due : Thursday Mar 22, 2001 @ midnight

!! Note: Your grade will be awarded for program correctness, readability, and documentation.

  1. Given the following fragment of C++ code.
    int prod, i;
    prod = 1;
    i = 2;
    while (i <= 10)
         prod *= i;
         i++;
         cout << prod;
    
    1. What would be the output of the C++ fragment? (Run your program and elaborate on the results obtained).
    2. If the purpose of this fragment of C++ was to output the value of 1*2*3*4*5*6*7*8*9. How should it be changed? Once you have made the necessary changes, run your program.
    3. Now if the purpose of this fragment of C++ was to output the value of 2*4*6*8*10*12*14*16*18*20; How should the above program be changed? Once you have made the necessary changes, run your program.
      Note: For questions (b) and (c), do not write a new program from scratch you only need to add the necessary changes to the above program.

  2. A user has to enter positive float values from the keyboard when prompted by the program. To indicate the end of the input, the user enters a negative number1. When all data has been entered the program should output the number of numbers entered, the minimum value entered, the maximum value entered and the average of the positive values entered.
    If there is no data to be entered (the user enters a negative number initially,) then the program should output a message indicating that no data has been entered.
    1. Note: If the user enters a negative number when there are no more numbers to process, then the program can easily recognize this entry as not being a data entry and hence terminate the entry of data. This technique of placing a sentinel to terminate an input list is very common

    Here is a sample of output:

    There were 15 numbers entered
    The average of all positive values is: 145.67 
    The minimum value is:  43.67 
    The maximum value is: 323.35 
    
    Here is another possible sample of input/output:
    Enter next value: -145.67
    No data has been entered
    
  3. Write a program that asks the user to enter a word. The program then repeats the word for as many times as it has characters. Use string and any related functions.

    Here is an example of input/output:

    Enter a word: Zombie
    Zombie
    Zombie
    Zombie
    Zombie
    Zombie
    Zombie
    

  4. Textbook: Page 225, problem #9. (Use the switch statement for the usage code).

  5. Write program which will print out a table of ascending powers of 2.
    1. The greatest value than should be printed must be less than 10,000.
    2. Now change your program so that the user can enter a value for the stopping value (i.e., a value to replace the 10,000).

    Here is a sample of output:

    0    1
    1    2
    2    4
    3    8
    4    16
    5    32
    6    64
    7    128
    8    256
    9    512
    10   1024
    ...  ...
    

Assignment List | Prev | Next | Computer Science 1620
Department of Mathematics & Computer Science
University of Lethbridge Home Page