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.
Format your output with setprecision(8) to ensure the proper number of decimals for testing!
#include <iostream>
#include <iomanip>Â
int main()
{
  double oilSpeed{ 0 };
  double thicknessOil{ 0 };
  double timeDay{ 0 };
  double volumeOil{ 0 };
  double areaSplit{ 0 };
  std::cout << "Enter the speed of the oil in the pipe, gallons per minute: ";
  std::cin >> oilSpeed;
  std::cout << "Enter the number of days: ";
  std::cin >> timeDay;
  std::cout << "Enter the thickness of the oil slick in millimeters: ";
  std::cin >> thicknessOil;
  std::cout << std::setprecision(std::numeric_limits<float>::max_digits10);
  for (int i = 1; i <= timeDay; i++)
  {
    volumeOil = 1440.0 * i * oilSpeed;
    areaSplit = (0.00378541 * volumeOil) / (thicknessOil *1000);
    std::cout << "After " << i << " days the volume of oil will be: "<<std::setprecision(8) << volumeOil << " gallons."<<std::endl;
    std::cout << "Oil slick area : " << std::setprecision(8)<< areaSplit << " square kilometers" << std::endl;
  }
  system("pause");
  return 0;
}
Comments
Leave a comment