Question

In: Computer Science

The formula used to calculate the density of a substance is mass divided by volume. It...

The formula used to calculate the density of a substance is mass divided by volume. It is expressed as d = m/v. Ask users for the mass and volume of a substance and calculate the density for them.

Output:

Enter the mass of a substance in grams (integers only): [assume user inputs 10]
Enter the volume of a substance in milliliters (integers only): [assume user inputs 4]
The density of your substance is 2.5

Solve in C++.

Solutions

Expert Solution

Solution:

Explanation :

In this C++ program to calculate the density of the substance.We have taken 2 variables mass and volume of integer datatype and 1 variable density of type float to store the result in floating point number.

First the user have to enter the values of mass and volume of integer type only and after that we will use the formula of density= mass/volume to calulate the result.But to get the density in floating point number we have to typecast explicitly to get a floating point result.So after the typecasted formula will be  

density = float(mass)/float(volume). And at last print the result by using density.

Program Code: Comments are provided in the code to better understanding.

#include <iostream>
using namespace std;
int main()
{ int mass,volume;
float density;
//to input mass from user
cout<<"Enter the mass of the substance in grams :" ;
cin>>mass;
//to input volume from user
cout<<"Enter the volume of the substance in mililitres :" ;
cin>>volume;
//formula to calculate density
//typecasted explicitly to get a floating point number
density = float(mass)/float(volume);
//to print result
cout<<"The density of your substance is :"<<density;
return 0;
}

Programming and Output Screenshot : Programming screenshot is provided to get a better understanding at the code indentation.

Thanks.I hope the code and explanations are clear.Please VOTE UP ;)


Related Solutions

what does the formula mass/volume% mean
what does the formula mass/volume% mean
Find accepted values for the density, molar mass, and molar volume (you may need to calculate...
Find accepted values for the density, molar mass, and molar volume (you may need to calculate this from other literature or accepted values) of oleic acid and Avogadro’s number. Then, Write a formula for how you will calculate percent error.
1. Determine the volume of the aluminum foil using the density of foil. Volume = mass...
1. Determine the volume of the aluminum foil using the density of foil. Volume = mass (g) x density g/cm3 Volume = 4.29 g/ 2.70 g/cm3 Volume= 1.59 cm3 2. Determine the volume of one atom of aluminum. 3. Determine the number of atoms of aluminum in the foil sample. 4. Determine the moles of aluminum. 5. Calculate Avogadro’s number.
Calculate the volume, in milliliters, of a solid that has a density of 7.142g/cm3 and a...
Calculate the volume, in milliliters, of a solid that has a density of 7.142g/cm3 and a mass of 232.51g
If you know the formula of a substance, how can you determine its molar mass? Note:...
If you know the formula of a substance, how can you determine its molar mass? Note: Chemists often use the term weight for mass.
Question: Calculate the mass density (in kilogram per cubic meter) of a cylinder whose mass is...
Question: Calculate the mass density (in kilogram per cubic meter) of a cylinder whose mass is (13.77 ± 0.11) g, diameter is (1.83 ± 0.07) cm, and height is (3.25 ± 0.05) cm. In all calculations below, you must also determine the uncertainties in the calculated values. 1. Calculate the percent uncertainty for the mass of the cylinder. ( 1 2 3 4 5 ) (2.25 pts) 2. Calculate the percent uncertainty for the diameter of the cylinder. ( 1...
Define mass density and specific weight. Define specific volume. Define specific gravity.
Define mass density and specific weight. Define specific volume. Define specific gravity.
In the followinmg question, absolute uncertainties for mass, volume, and density must be included. Show units...
In the followinmg question, absolute uncertainties for mass, volume, and density must be included. Show units for each value. A student uses one of our 10mL pipettes to weigh out a known volume of liquid into a small beaker. Using the top loading balance, the beaker weighed 9.2g and 19.4g when empty and filled. a) What is the mass of the liquid? _____+-______ b) What is the volume of the liquid? _____ +-______ c) What is the density of the...
How to calculate density of mixture flowing through pipe, with 50% volume of one fluid and...
How to calculate density of mixture flowing through pipe, with 50% volume of one fluid and 50% volume of another fluid? Then for the mixture if temperature, internal diameter and pressure gradient is given. 1.Calculate Reynolds number 2. Volumetric flow rate 3. Local velocity at a perpendicular distance of X from inner wall of pipe.
Question:1 Calculate the density, in g/cm3, of a metal that has a volume of 41.3 L...
Question:1 Calculate the density, in g/cm3, of a metal that has a volume of 41.3 L and a mass of 70.05 kg. Question:2 You have 20.0 L of a 8.18% by volume (% v/v), water-based dye solution. Calculate the volume of pure dye and water that were used to prepare the solution. You may assume that volumes are additive. Question:3 How many mL of pure (100.0%) food dye are needed to prepare 437.4 mL of 34.8% by volume (%v/v) food...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT