Problem Constant
PI 3.14159
Problem Inputs
double hole_diameter /* diameter of hole */
double edge_diameter /* diameter of outer edge */
double thickness /* thickness of washer */
double density /* density of material used */
double quantity /* number of washers made */
Problem Outputs
double weight /* weight of batch of washers */
Program Variables
double hole_radius /* radius of hole */
double edge_radius /* radius of outer edge */
double rim_area /* area of rim */
double unit_weight /* weight of 1 washer */
Relevant Formulas
area of a circle = * radius 2
radius of a circle = diameter / 2
rim area = area of outer circle − area of hole
unit weight = rim area * thickness * density
PROGRAM
#include <iostream>
using namespace std;
int main()
{
const float PI = 3.14159;
float holeDiameter; //input-diameter of hole
float edgeDiameter; //input-diameter of outer edge
float thickness; //input-diameter of washer
float density; //input-thickness of material used
float quantity; //input-density of washer made
float weight; //input-number of weight of washer batch
float holeRadius; //radius of hole
float edgeRadius; //radius of outer edge
float rimArea; //area of rim
float unitWeight; //weight of 1 washer
// Get the inner diameter, outer diameter, and thickness.
cout << "Inner diameter in centimeters: ";
cin >> holeDiameter;
cout << "Outer diameter in centimeters: ";
cin >> edgeDiameter;
cout << "Thickness in centimeters: ";
cin >> thickness;
// Get the material density and quantity manufactured.
cout << "Material density in grams per cubic centimeter: ";
cin >> density;
cout << "Quantity in batch: ";
cin >> quantity;
// Compute the rim area.
holeRadius = holeDiameter / 2.0;
edgeRadius = edgeDiameter / 2.0;
rimArea = PI*edgeRadius*edgeRadius -
PI*holeRadius*holeRadius;
// Compute the weight of a flat washer.
unitWeight = rimArea * thickness * density;
// Compute the weight of the batch of washers.
weight = unitWeight * quantity;
// Display the weight of the batch of washers.
cout<<"The expected weight of the batch is "<<weight<<"grams"<<endl;
return 0;
}