* Calculates and displays:
o The number of square centimeters of material that are needed to manufacture a specified quantity of flat washers
o The weight of the left-over material, after the washers are stamped.

In order to calculate the leftover weight - you will need to determine the total weight of the metal stock, and the weight of the actual washers. For this you will need the user to enter the DENSITY in grams/cubic cm., as well as the THICKNESS of the metal stock, and the inner and outer DIAMETERS of the washers.

// File: washer .cpp
// Compute the weight of a batch of flat washers


#include <iostream>
using namespace std;

int main()

{
    const float PI= 3.14159;
    float holeDiameter, // diamater of hole
    edgeDiameter,       // diameter of outer edge
    thickness,          // thickness of washer
    density,            // density of material used
    quantity,           // number of washers made 
    
    // Output
    weight,             // weight of batch of washers
    holeRadius,         // radius of hole
    edgeRadius,         // radius of outer edge
    rimArea,            // area of rim
    unitWeight,         // weight of one washer
    areastockmetal,     // areas of the stock metal
    Weightstockmetal,   // weight of the stock metal
    unitWeightstockmetal,  // weight of 1 units as a whole circle
    Leftmaterial;          // left material
    // 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;
    cin.get();
    
    //Compute the rim area and area of the stock metal
    
    holeRadius = holeDiameter / 2.0;
    edgeRadius = edgeDiameter / 2.0;
    rimArea = PI * edgeRadius * edgeRadius - (PI * holeRadius * holeRadius);
    areastockmetal = (edgeRadius * edgeRadius *PI) ;
    
    // Compute the weight of a flat washer.
    
    unitWeight = rimArea * thickness * density ;
    unitWeightstockmetal =  areastockmetal * thickness * density ;
    
    // Compute the weight of the batch of washers, weight of stock metal, the left material
    weight = unitWeight * quantity;
    Weightstockmetal = unitWeightstockmetal * quantity;
    Leftmaterial = Weightstockmetal - weight;
    
    // Display the weight of the batch of washers, left stock metal
    
    cout << " The expected weight of the batch is " << weight << " grams. " << endl;
     cout << " The left over is " << Leftmaterial << "grams. " << endl;
         
         cin.get();
         
        
         return 0 ;
         
         }

I am not sure about the algorithm for this problem, cause my English is not good, so I don't know what I have done is correct cause I don't know what is the stock metal..
mean , i first find the big circle's area and, its weight ,...everything, and then subtract for the weight calculated by the rim area...
thank you .. the program is running well but I am not sure that it's running correctly???and wait for some comment, is there any solution which are more efficient

Recommended Answers

All 2 Replies

looks fine to me but i dont have a compiler available.

No C++ syntax error that I see. The calculations look ok. But you recalculate this value (edgeRadius * edgeRadius *PI) twice, whcih you could avoid. Though that is a very minor nitpick.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.