Solution

// Programmer: Jennifer Leopold

// Date: August 30, 2016

// File: hw2.cpp

// Purpose: Calculate the dimensions needed for an aquarium

// and the # fish it can hold.

//

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

//

// To execute: ./hw2

#include <iostream>

using namespace std;

// Tank width is certain % of tank length

const float TANK_WIDTH_PERCENTAGE = 0.25;

// Tank height is certain % of tank length

const float TANK_HEIGHT_PERCENTAGE = 0.67;

// Gallons per cubic ft.

const float GALLONS_PER_CUBIC_FT = 7.48;

// Gallons needed per fish

const int GALLONS_PER_FISH = 25;

// Nuclear waste (in gallons) that must be added to feed

// freak fish

const int NUCLEAR_WASTE = 2;

// Inches per foot

const int INCHES_PER_FT = 12;

// Liver Irradiation for Fish Existence Factor

// (in rads per inches)

const int LIVER_IRRADIATION = 11;

int main()

{

int tankLength; // user inputs

bool areFreakyFishPresent;

int numFish; // calc'd # fish tank can hold

int tankWidth, tankHeight; // calc'd tank dimensions, capacity

float tankVolume;

float waterCapacity;

float waste;

// Greeting

cout << "Welcome to the Fish Tank Computer!\n";

// Get user inputs

cout << "Enter the following info:\n\n";

cout << " length of tank (in feet): ";

cin >> tankLength;

cout << " any freak fish? (1 = yes, 0 = no): ";

cin >> areFreakyFishPresent;

// Calculate tank dimensions, capacity, and # fish

tankWidth = static_cast<int>

(TANK_WIDTH_PERCENTAGE * tankLength);

tankHeight = static_cast<int>

(TANK_HEIGHT_PERCENTAGE * tankLength);

tankVolume = tankWidth * tankLength * tankHeight *

GALLONS_PER_CUBIC_FT;

waterCapacity = tankVolume -

(areFreakyFishPresent * NUCLEAR_WASTE);

numFish = static_cast<int>(waterCapacity / GALLONS_PER_FISH);

waste = LIVER_IRRADIATION / static_cast<float>(tankHeight * INCHES_PER_FT);

// Output tank dimensions, capacity, and # fish

cout << "\n\nYour tank dimensions are:\n";

cout << " length\t" << tankLength << " ft\n"

<< " width\t\t" << tankWidth << " ft\n"

<< " height\t" << tankHeight << " ft\n"

<< " tank cap\t" << tankVolume << " gals\n"

<< " water\t\t" << waterCapacity << " gals\n"

<< " waste\t\t" << waste << " rads\n";

cout << "\n\nYour tank will hold "

<< numFish << " fishies.\n";

// Sign-off

cout << "\nHave fun with your fishies...bye now!\n";

return 0;

}