1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
#include <iomanip>
using namespace std;
//Functions
void input_data(double &length, double &thickness);
double cable_tension(double &length, double thickness, double stretch, double breakage, double maxLength, int pounds);
int main()
{ //Variables
double length, thickness, stretch, breakage, maxLength;
int pounds = 0;
//Calling functions
input_data(length, thickness);
cable_tension(length, thickness, pounds, stretch, breakage, maxLength);
return 0;
}
//Input, calcualtion, and output functions
void input_data(double &length, double &thickness)
{
cout << "Enter the lenght of the cable in feet: ";
cin >> length;
cout << "Enter the thickness of the cable up to 2.0 inches: ";
cin >> thickness;
while (length <= 0)
{
cout << "\nThis is not a valid cable length." << endl;
cout << "Enter a cable length greater than 0: " << endl;
cin >> length;
}
while (thickness <= 0 || thickness > 2.0)
{
cout << "\nThe cable thickness must be 2.0 inches or less." << endl;
cout << "Enter a cable thickness less than 2.0: ";
cin >> thickness;
}
}
//function to do the stretching / breakage calc
double cable_tension(double &length, double thickness, double stretch, double breakage, double maxLength, int pounds)
{
pounds;
stretch = thickness * .3;
breakage = length * 16 / 100;
maxLength = breakage + length;
double addedPounds;
while (length + addedPounds <= maxLength)
{
addedPounds = pounds * stretch;
cout << fixed << setprecision(2);
cout << "\nThe tension applied to the cable is: " << pounds << " lbs" << endl;
cout << "The length of the cable is: " << length + addedPounds << " feet" << endl << endl;
pounds++;
}
cout << "The cable broke!" << endl;
return pounds;
}
|