CSC 122: Computer Science II

C++ Lab Assignment #5

 

 

 

Purpose:

                       

This lab will illustrate the usage of an ADT, specifically the list ADT implemented in C++.

 

 

Introduction:

 

We have discussed the list ADT in class, and looked at an implementation of the ADT in C++.  We will be using this C++ class to implement a simple program.

 

 

Procedure:

 

Write a program that does the following:

1.      Prompt the user to enter a sequence of numbers.  The numbers should all be 0 or more (error-check to make sure), except that the user should enter a -1 to indicate that he or she is done entering numbers.

 

2.      After all the numbers are entered, the program should display the numbers back to the user (the -1 should not be included in the list of numbers).

 

3.      The program should then remove all numbers larger than 13 from the list, keeping the rest of the numbers in the same relative order.  We do this because the small size of integers on C++ means that calculations of the factorial of numbers larger than 13 will be incorrect.  Print the new list.

 

4.      The program should then print out the factorial of each number in the list, in the proper order.

 

For example, here is an example program run.  Assume that the user entered the following numbers in this order:  7 14 21 3 9 56 101 5 1 -1.

 

You entered: 7 14 21 3 9 56 101 5 1

 

After removing large numbers: 7 3 9 5 1

 

Calculating factorials: 5040 6 362880 120 1

 

 

The program should accomplish these things using the list class.