CS 54 - Lab 3


Lab Assignment

The Stimsonian Institute of Physics was so pleased with your watermelon program, they sent you a certificate for free fruit salad for a year from Feynman Brother's Bagels. Another infamous educational activity at the Stimsonian Institute of Physics is that students make balsa wood bridges subject to mass, length, and width constraints. The bridge must be made up of 1.2 meters or less of balsa wood. The mass of the bridge must be less than 25 grams. After each bridge has met the contest requirements, weight is then applied to the bridge to see how much mass the bridge can sustain.


Lab Assignment - Part I (Required - 8 Points)

Students are issued a dozen 10 centimeter sticks of balsa wood to build their bridges. These sticks can be cut and shaped to the individual design. Each stick weighs an average 1.5 grams. After the sticks are cut, each junction must be glued together with an average of 0.5 grams of glue. So, the mass in grams of the bridge is:
m = 1.5s + 0.5j
, where s is the number of sticks used and j is the number of junctions that required glue. Write a program that will ask the user about their bridge and tell them if their bridge meets the mass requirement. Make sure the user does not enter negative sticks or joints. If either quantity is negative, multiply that quantity by -1 to change the sign. If the number of sticks is 0, then insult the user and set the number of sticks to a default value of your choice. Also, ensure that the number of sticks does not exceed the 1.2 meter limit on balsa wood length.


Lab Assignment - Part II (Required - 10 Points)

There are an infinitely many designs that will qualify for the bridge break-off. Physicists at the Institute have studied thousands of student designs and have “scored” a bridge based the bridge's specifications:
S = \frac{(s + j)^2}{ms} \, q
, where q = 1 if the bridge qualified in Part I and q = 0 if the bridge was disqualified in Part I. Write a program that reports the bridge's score if the score was non-zero (i.e., q = 1 and the bridge qualified). If the score was zero, insult the user's bridge (be creative).


Lab Assignment - Part III (Optional - 12 Points)

Masses are then applied to the bridge until it breaks. The Stimsonian Institute has 0.5 kg, 1 kg, 2 kg, and 5 kg masses. The typical bridge with n kg of mass applied to it will break according to the following formula:
B = \frac{n \left|m - j\right|}{m S^2}
If B is greater than or equal to half the bridge's score, the bridge is broken. Make sure to check that the bridge has neither 0 mass or a score of 0. In a loop, give the user the opportunity to apply a mass to the bridge and print the result of whether the bridge collapsed. If the bridge collapses or if the user chooses to exit, terminate the loop. HINT: You can use the fabs() function for the absolute value by using #include <cmath>.


Grading & Submission

Part I is worth 8 points. Part II is worth 10 points (Part I + 2 points). Part III is worth 12 points (Part II + 2 extra credit points). The lab is out of 10 points. When you're done, submit your lab03.cpp file on Blackboard. I will be grading your program on the following criteria:


[Dilbert]