An oil slick occurs when an underwater refinery pipe ruptures, pumping oil into the water. The spilled oil sits on top of the water and causes a natural disaster. For simplicity, suppose that the oil sits on top of the water in the form of a circle. Write a program that prompts the user to enter the rate at which the ruptured pipe pumps oil (in gallons) per minute, the thickness of the oil on top of the water, and the number of days for which the area is covered by the spilled oil. The program outputs the spilled area (in kilometers) and the volume of oil (in gallons) on top of the water after each day.

Respuesta :

Answer:

Here the code is given as follows,

Explanation:

#include <iostream>

#include <iomanip>

using namespace std;

const double CUBIC_CENTIMETERS_IN_ONE_GALLON = 3785.41;

const double CENTIMETERS_IN_ONE_KILOMETER = 100000.00;

double oilSlickArea(double oilThick,

double oilReleasedRate, double spilTimeInHours);

int main()

{

double oilThickness;

double oilReleasedGallonsPerMinute;

int slickDays;

double spillArea = 0.0;

cout << fixed << showpoint << setprecision(8);

cout << "Enter the oil spill rate per minute (in gallons): ";

cin >> oilReleasedGallonsPerMinute;

cout << endl;

cout << "Enter oil thickness on top of the water (in centimeters): ";

cin >> oilThickness;

cout << endl;

cout << "Enter the number of days for which you want to know "

<< "the area covered by the spilled oil: ";

cin >> slickDays;

cout << endl;

cout << "Oil slick area after each day for " << slickDays << "days."

<< endl << endl;

cout << setw(5) << " " << setw(20) << left << "Slick Area in"

<< setw(20) << left << " Volume of Oil in" << endl;

cout << setw(5) << left << "Day " << setw(20) << left << "Square Kilometers"

<< setw(20) << left << " in Gallons" << endl;

for (int i = 1; i <= slickDays; i++)

{

spillArea = spillArea + oilSlickArea(oilThickness,

oilReleasedGallonsPerMinute, 60 * 24);

cout << setw(4) << left << i << " " << setw(12)

<< setprecision(8) << spillArea / (CENTIMETERS_IN_ONE_KILOMETER * CENTIMETERS_IN_ONE_KILOMETER)

<< " " << setprecision(2)

<< right << setw (15) << (oilReleasedGallonsPerMinute * 60 * 24 * i) << endl;

}

return 0;

}

double oilSlickArea(double oilThick,

double oilReleasedRate, double spilTimeInHours)

{

double oilVolumeInGallons;

double oilVolumeInCubicCentimeters;

double spillArea;

oilVolumeInGallons = oilReleasedRate * spilTimeInHours;

oilVolumeInCubicCentimeters = oilVolumeInGallons * CUBIC_CENTIMETERS_IN_ONE_GALLON;

spillArea = oilVolumeInCubicCentimeters / oilThick;

return spillArea;

}