Solution

/*

Programmer: Jennifer Leopold

Date: January 24, 2018

File: hw2.cpp

Purpose: Calculate the dimensions needed to build a

seahorse aquarium.

To compile: fg++ hw2.cpp -o hw2

To execute: ./hw2

*/

#include <iostream>

#include <cmath>

using namespace std;

// Gallons needed per seahorse

const int GALLONS_PER_SEAHORSE = 20;

// Extra gallons for baby seahorse milk

const int GALLONS_FOR_BABY_SEAHORSE_MILK = 1;

// Gallons per cubic ft.

const float GALLONS_PER_CUBIC_FT = 7.47;

// Aquarium depth (proportion of aquarium length)

const float AQUARIUM_DEPTH_PROPORTION = 1.5;

// Aquarium width (proportion of aquarium length)

const float AQUARIUM_WIDTH_PROPORTION = 0.25;

// Glass thickness proportion (mm)

const int GLASS_THICKNESS_MM = 10;

// Glass thickness proportion (per inches depth)

const int GLASS_THICKNESS_INCHES_DEPTH = 20;

// Inches per foot

const int INCHES_PER_FT = 12;

int main()

{

int numSeahorses; // user inputs

bool areBabySeahorses;

float tankWidth; // calc'd tank dimensions

int tankVolume;

float tankLength;

float tankDepth;

int glassThickness;

// Greeting

cout << "Welcome to the Aquarium Calculator!\n\n";

// Get user inputs

cout << "How many seahorses do you want in your "

<< "aquarium: ";

cin >> numSeahorses;

cout << "Will there be baby seahorses that will "

<< "need milk? (1 = yes, 0 = no): ";

cin >> areBabySeahorses;

// Calculate aquarium (i.e., tank) dimensions

tankVolume = (numSeahorses * GALLONS_PER_SEAHORSE) +

(areBabySeahorses *

GALLONS_FOR_BABY_SEAHORSE_MILK);

tankLength = pow(tankVolume /

(GALLONS_PER_CUBIC_FT *

AQUARIUM_DEPTH_PROPORTION *

AQUARIUM_WIDTH_PROPORTION),

0.33);

tankWidth = AQUARIUM_WIDTH_PROPORTION * tankLength;

tankDepth = AQUARIUM_DEPTH_PROPORTION * tankLength;

glassThickness = static_cast<int>

(GLASS_THICKNESS_MM *

(tankDepth * INCHES_PER_FT) /

GLASS_THICKNESS_INCHES_DEPTH);

// Output tank dimensions, capacity, and # fish

cout << "\n\nSpecifications of your aquarium:\n";

cout << " Volume:\t\t" << tankVolume << " gallons\n"

<< " Length:\t\t" << tankLength << " ft\n"

<< " Width:\t\t" << tankWidth << " ft\n"

<< " Depth:\t\t" << tankDepth << " ft\n"

<< " Glass thickness:\t" << glassThickness << " mm\n";

// Sign-off

cout << "\nHave fun with your seahorse aquarium!\n";

return 0;

}