CO311: Introduction to Modern Programming II

Lab Practical #4: February 21, 2000

You will be randomly assigned one of two programs to write. Please read the entire problem before jumping into the code! Your program should consist of several functions in addition to main():

  1. An array operation function, called by main(), to do the “work” of the program.
  2. A mathematical function, called by the array function, to be used as a “helper” function.
  3. A display function, called by main(), to appropriately display the results.

Use good programming style including comments, useful object/variable names, and descriptive function names. Take a moment before jumping into the code to sketch out the framework of the program: what objects are needed to store what information, which functions you’ll be needing (including the input and output of the function itself), etc. Only once you have an outline for your program should you begin to code it!

Submit the finished CPP file to the FTP site in its own folder called P4.

You will have 60 minutes to complete the assignment; late submissions will be penalized 5 points for every 5 minutes late.

The following are the two different program requirements:

Problem A

Create a program that uses an array to print a table of the first 20 whole numbers (1..20) in one column, and the corresponding factoral (n!) in the other. As a reminder, the factoral function (n!) is a running multiplication from the starting number to one (example: 5! = 5󫶗󫎽=120). Hint: you’ll need to use an array of double-precision floating-point objects in order to store the factoral of all the numbers.

Problem B

Create a program that uses an array to print a table of the powers of 2 from 0 to 19, where one column is n, and the other is 2n. Write your own function to generate the result of 2n, remembering that any number to the 0 power (n0) equals 1.