In: Computer Science
BUOYANCY
Buoyancy is the ability of an object to float. Archimede's Principle states that the buoyant force is equal to the weight of the fluid that is displaced by the submerged object. The buoyant force can be computed by:
buoyant force = (object volume) times (specific gravity of the fluid)
If the buoyant force is greater than or equal to the weight of the object then it will float, otherwise it will sink.
Write a program that inputs the weight (in pounds) and radius (in feet) of a sphere and outputs whether the sphere will sink or float in water. Use 62.4 lb/cubic foot as the specific weight of water. The volume of a sphere is computed by (4/3)π times the radius cubed.
INPUT and PROMPTS. The program uses this prompt ""Input weight of the sphere in pounds." for the first number it reads in, the weight of the sphere. The program uses this prompt "Input radius of the sphere in feet." for the second number it reads in, the radius of the sphere. Do not print out these numbers as they are read in
OUTPUT. The program either prints out "The sphere will float in water." or "The sphere will sink in water.".
//Assuming c++ language do comment if any other language needed
// do comment if any problem arises
//code
#include <iostream>
using namespace std;
//specific gravity of water
const float specific_gravity = 62.4;
const float pi = 3.14;
int main()
{
float weight, radius;
//read weight of sphere
cout << "Input weight of the sphere in pounds: ";
cin >> weight;
//read radius of sphere
cout << "Input radius of the sphere in feet: ";
cin >> radius;
//calculate volume of sphere
float volume = (4 / 3) * pi * radius * radius * radius;
//calculate Byouancy
float Buoyancy = volume * specific_gravity;
//if buoyancy is greater than or equal to specific gravity
if (Buoyancy >= weight)
cout << "The sphere will float in water.";
else
cout << "The sphere will sink in water.";
}
Output: