Assignment 02

Background: Many people in the U.S. don't know of the existence of an 8th continent on planet earth. Many more people in Europe know of it because their high schools are better. It was called Atlantis, and it now resides below the surface of the Atlantic Ocean. (The White Star line tried to send a titanic cruise liner to port there, but .... succeeded. Unfortunately. But, I digress.) Anyway, one of more noteworthy inhabitants of Atlantis is a fella named BoJack Horseman. I'm really not sure what this guy is, but he's kind of a horse and kind of a man. Centaur perhaps...I dunno. He comes from Atlantis where all other horse-like oddities live, like unicorns. He has a couple close friends, Todd and Mr. Peanutbutter, and a sister. Mr. Peanutbutter is half dog and half man, and his sister is also half horse. After recently attending the Atlantis Film Festival, BoJack has decided that he wants an aquarium of seahorses in his house. His friends Todd and Mr. Peanutbutter have offered to build an aquarium for him. However, they’d like to have a program to calculate the dimensions, and hence the amount of glass that will be needed. If this works out, Todd may do this as a side business and use the program for other customers (about time that slacker stopped free-loading off of BoJack!).

Due: Friday, February 2, 2016 at noon 100 pts

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Remember, to electronically submit a file for this course, first change to the directory in which the file resides and then type in, at the UNIX prompt, the command:

cssubmit 1570 section_letter assignment_number

Be sure that only the file you want to submit is in that directory - make a directory for every assignment! Remember that the submit system will deliver every .cpp file in the current directory to me, so you should only have the file for hw 2 in that directory. Name your file a meaningful name and give it a .cpp extension since you will be compiling it. Also, make sure that you compile and run your program using the GNU (g++) compiler before submitting to make sure that it will work for the submit script.

Foreground: This semester you will be writing code in C++ to help solve real-life problems, advance the cause of humanity, destroy desperation and solve world hunger, and generally make the planet a better place to live. Mostly, your code is going to be used by you, but there is always that distinct possibility that some world leader bent on world domination will get a hold of your program and use it for nefarious porpoises as well as sea horses. Be careful what you code!

Specifications: The information needed is: (1) the number of seahorses that will be kept in the aquarium, and (2) whether or not seahorse milk will need to be added periodically for baby seahorses.The primary material needed to build the aquarium is glass. So your program has to compute the length, width, and depth for the aquarium as well as the thickness of the glass. To do that, your program should take into account the following information:

  • Each seahorse (regardless of its size) requires 20 gallons of water.

  • If there will be baby seahorses, a capacity of 1 gallon of water must be allocated for periodically adding seahorse milk (regardless of the number of baby seahorses).

  • Volume of water in gallons = length * width * depth * 7.47, where length, width, and depth are in feet.

  • Since seahorses are vertically oriented, the depth of the aquarium should be 1.5 times the length of the aquarium.

  • Width of the aquarium should be 1/4 of the length. This is for aesthetic purposes.

  • The thickness of the glass should be 10 mm for each 20 inches of depth of the aquarium (rounded down to the nearest mm).

Your program should prompt the user (e.g., BoJack) to enter the necessary information. It should then do the appropriate calculations, and output the volume, dimensions, and glass thickness of the aquarium that Todd and Mr. Peanutbutter would need to build. For the computations, you might find that you need to raise a quantity to a power. In order to perform this mathematical operation, you need to use a special function called pow. You don't know anything yet about functions, but in about 4 weeks we'll show you how to write them. For now, you can use functions in C++ that are already written and provided to you in a system library. In order to use pow, you will need to include the library that contains the code for that function. So, right after your #include<iostream>, on the next line write #include <cmath>. Then, you can use pow and the compiler will recognize it. You need to know that pow will return a double precision float and takes two arguments, the first is the base and the second is the exponent. For example, if you want to compute x = y3, you would have this code:

x = pow(y, 3);

Sample input and output are given below.

Welcome to the Aquarium Calculator!How many seahorses do you want in your aquarium? 10 Will there be baby seahorses that will need milk? (Y/N) Y Specifications of your aquarium: Volume: 201 gallons Length: 4.155 ft Width: 1.039 ft Depth: 6.233 ft Glass thickness: 37 mm

..................So ends this run of the Aquarium-o-matic.....

You should notice something very important here. The output of this program is "user friendly" in that it has a greeting and a sign-off, the prompts for input are clear and neat, the summary of output is very clear. Here's an example of really crappy output:

seahorses? 10

babies? y

v is 201

l = 4.1

w = 1.039 and dipth is 6

Special Note: For this assignment, you are NOT to use the if or if-else statement in your code. There is one point in the coding where you are going to really want to use an if statement. Don't. You can effectively deal with this problem by thinking about types for the variables you use. As a hint: remember that boolean variables can take on values of true or false. But there is also a relationship between a boolean value and numbers and how the values of true and false map to numbers. You might want to use this relationship. Also, if you choose to input from the user a value into a boolean type variable, your prompt is going to have to reflect how C++ operates. Your prompt should look like this:

So you see, this is really bad output formatting: no greeting, no salutation, no consistency of presentation of info, unkorrekt spilling, no units of measurements, etc. Make your output nice!

glass: 37

cout<<"blah blah blah (1 for yes, 0 for no ): ";

cin>>my_bool_var;

If the user input "yes" or "no" or "true" or "false" or anything else, your program will not work as expected.

Optional (w/o extra points): If you're bored by this basic assignment, prompt the user for the maximum length of the space in which this aquarium will be placed in the room. Then, make the final line of output a statement telling the user whether or not the aquarium will actually fit in the space. For this part, you will need to use the if statement. Look ahead in the material and learn how to use it....but don't expect to be "paid" for looking ahead.

When you submit: When you submit this, and all subsequent programs for this class, cssubmit will compile and run (assuming it compiles) your program during the submission process. Thus, when you submit, you will have to enter inputs as a user of the program. Now, in order to make the output uniform for the grader and to keep them sane, ALL OF YOU will enter the same information. For this assignment, it is:

    • enter 25 for the number of seahorses

    • enter an answer indicating the need of seahorse milk

    • and if you go for the optional part, enter 33 feet

This is a bunch of nonsense. But you really need to get used to that.