Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ENG 1221 – Repetition Project Background: Your manager at the local supermarket

ID: 671694 • Letter: E

Question

ENG 1221 – Repetition Project

Background: Your manager at the local supermarket has asked you to create a produce display; he’s asked you to build a pyramid of apples from the upcoming shipment. The pyramid should be erected such that each square of four apples in one layer supports one apple on the next layer.

Example shown to right:

Top layer (1 apple)

Next layer (2 rows, 2 columns, i.e., 4 apples)

Base layer (3 rows, 3 columns, i.e., 9 apples)

Tasks: You are asked to compute each of the following items. Note: between items, you may or may not choose to duplicate or reuse any of your own code.

Given a specified number of layers, how many apples will be used? Show test cases:

5, 7, and 10 layers.

Not enough apples are being displayed. Given the dimension of the base of a square pyramid and the total number of apples to be displayed, how many complete, square pyramids can be made? How many apples are left over? Show test cases:

5x5 base from 1000 apples,

8x8 base from 800 apples

8x16 base

10x32 base

10x16 base with 8 layers,

12x32 base with 10 layers.

With so many apples in rectangular pyramids, your manager is concerned that the apple display will be so tall that it will interfere with the low-hanging signage in the store; the signage is only 2 feet above the surface of the display table. You think you can get a good estimate of the height of the apple display if you assume that the apples are spherical. You also simplify the height calculation by assuming each layer is 1 apple-diameter thick. Given the approximate apple diameter, the dimensions of the base, and the number of apples: How many layers of apples will fit on the display table without touching the sign? How many apples are left over? How tall is the pyramid (in inches and in number of layers)? Show test cases:

3.25 inch diameter, 10x16 base, max 10 layers, sign height 2 feet, 1000 apples are available,


2.75 inch diameter, 14x32 base, max 13 layers, sign height 2 feet, 1200 apples are available.

Bonus (~5 pts): Repeat the previous task without the assumption that a layer is 1 apple-diameter thick. Visualize the problem in 3 dimensions and use geometry.

Bonus (~15 pts): Create a script file to generate 3D figures of pyramids or incomplete pyramids as in the figures above. New commands: sphere, view, surf, and camlight. Hint: make each sphere individually.

Figure 1 File Edit View Insert Lools Desktop Window Help " 10- 1d2 5 10 15 2 25

Explanation / Answer

Solution :

  // Create and set a constraint layout manager for the parent layer.  
  theLayer.layoutManager=[CAConstraintLayoutManager layoutManager];  
       
  // Create the first sublayer.  
  CALayer *layerA = [CALayer layer];  
  layerA.name = @"layerA";  
  layerA.bounds = CGSquareMake(0.0,0.0,100.0,25.0);  
  layerA.borderWidth = 2.0;  
       
  // Keep layerA centered by pinning its midpoint to its parent's midpoint.  
  [layerA addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMidY  
                                                   relativeTo:@"superlayer"  
                                                    attribute:kCAConstraintMidY]];  
  [layerA addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMidX  
                                                   relativeTo:@"superlayer"  
                                                    attribute:kCAConstraintMidX]];  
  [theLayer addSublayer:layerA];  
       
  // Create the second sublayer  
  CALayer *layerB = [CALayer layer];  
  layerB.name = @"layerB";  
  layerB.borderWidth = 2.0;  
       
  // Make the width of layerB match the width of layerA.  
  [layerB addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintWidth  
                                                   relativeTo:@"layerA"  
                                                    attribute:kCAConstraintWidth]];  
       
  // Make the horizontal midpoint of layerB match that of layerA  
  [layerB addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMidX  
                                                   relativeTo:@"layerA"  
                                                    attribute:kCAConstraintMidX]];  
       
  // Position the top edge of layerB 10 points from the bottom edge of layerA.  
  [layerB addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMaxY  
                                                   relativeTo:@"layerA"  
                                                    attribute:kCAConstraintMinY  
                                                       offset:-10.0]];  
       
  // Position the bottom edge of layerB 10 points  
  //  from the bottom edge of the parent layer.  
  [layerB addConstraint:[CAConstraint constraintWithAttribute:kCAConstraintMinY  
                                                   relativeTo:@"superlayer"  
                                                    attribute:kCAConstraintMinY  
                                                       offset:+10.0]];  
       
  [theLayer addSublayer:layerB];