SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Flow Of Control
Exercise:
Programming Projects
Question:6 | ISBN:9780132846813 | Edition: 5

Question

Buoyancy is the ability of an object to float. Archimedes’ 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

where is the buoyant force, is the volume of the submerged object, and is the specific weight of the fluid. If 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/ft3 as the specific weight of water. The volume of a sphere is computed by (4/3)r3.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

#include <iostream>
using namespace std;
int main()
{
   //Variables
   double weight,radius,Fb;
  //User input
  cout<<"Enter weight(pounds):"; 
  cin>>weight;
  cout<<"Enter radius(feet): ";
  cin>>radius;
  //Compute  buoyant force by using
  //the volume of a sphere is computed by (4/3)πr3
  Fb =62.4*((4 *3.14 * radius * radius * radius )/3);
 
  //Print Output
  //If Fb is greater than or equal to the weight 
  //of the object, then it will float, otherwise 
  //it will sink.
  if(Fb>=weight)
	cout<<"The sphere will float in water \n";
  else  cout<<"The sphere will sink in water \n";
}

Result output:

Enter weight(pounds):85
Enter radius(feet): 10
The sphere will float in water

 

0 0

Discussions

Post the discussion to improve the above solution.