CS99 Fall 2001 Prelim2 Sample Problems: 1. DIS.com needs you to simulate the number of boxes a worker can stack on eight carts in one day. A chute issues one box at a time for the worker to place on a cart. The boxes have random sizes, which are ranked from 1 to 5. A box of size 5(#5) must be at the bottom of the stack on each cart. All other boxes may be stacked in any order. Since the worker does not want to bother with removing boxes from a cart, the simulation has these assumptions: + A cart has no limit to the number of boxes it can store + The worker will not shuffle the boxes + Each time a #5 box appears, the worker starts stacking a new cart with the #5 box at the bottom + Another worker has already filled the first and second carts with three and seven boxes, respectively + The third cart currently has two boxes stacked on it, so far + The first cart has a #5 box at the bottom Since the company is very cheap, it has only five more empty carts for the worker to use. So, when the ninth#5 box appears, the worker cannot continue stacking boxes. However, the company will only produce forty boxes in one day. So, the worker might not need to use all of the carts. 1a. Write a brief algorithm that describes how to simulate this problem. Ultimately, the program must report the following: + the total number of carts needed + the total number of boxes stacked on all of the carts, which is the sum of all boxes on all carts. 1b. Write a program that determines the number of carts used and the number of boxes that the worker stacked on all of the carts by doing the following: + Initilize the following variables: maximum number of boxes that the company produces (maxBoxes), total number of boxes placed on the carts (totalBoxes), total number of carts for storing boxes (cartTotal), current count of cart that is being used (cartCount), and the current box size that worker will attempt to stack (currentBox). + Use a loop with selection statements inside of it to simulate whether or not the current box gets stacked and if a new cart must be chosen. Boxes of size#5 must be placed on a new cart, assuming that the carts have not been exhausted. + Report the number of carts that were used and the total number of boxes stored on all carts. 2. Probelm 4.21 (no need to plot) from Matlab Programming for Engineers by Chapman 3. Problem 4.24 from Matlab Programming for Engineers by Chapman 4. For character graphics, draw a circle. You could use the equation x^2+y^2=r^2, along with x=r*cos(theta), y=r*sin(theta). 5. Write a program that converts a 1-D array into a 2D array with the 1D array on the diagonal and "reverse diagonal". For example, [1 2 3] becomes [1 0 3] [0 2 0] [1 0 3]