Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ *Please do not handwrite* Write a program that will calculate the safe load

ID: 3593590 • Letter: C

Question

C++ *Please do not handwrite*

Write a program that will calculate the safe load on a load bearing column given the slimness ratio.The slimness ratio will be input by the user from the keyboard and the program should output the calculated safeload.The safe load is calculated as follows:

S=17,000 - .485R2      for R<120

   Or

S=     18,000/( 1 +(R2/18,000))       for R 120

Where             S=safe load (pounds per square inch)

                        R=slimness ratio(dimensionless – it is a ratio of the column’s length to its width).   Note that this value can NOT be negative. Your program must account for this.

Execute this program twice using values of R = 20, and R = –100.

Explanation / Answer

#include <iostream>

#include <stdlib.h>

using namespace std;

int main()

{

float slimnessRatio;

float safeLoad;

//If slimnessRation is negative, it will run indefinitely

while(true){

    char input[10];

    cout << "Enter Slimness Ratio (R) <It can't be negative>: ";

    cin >> input;

    // atof function converts char array to float.

    if(atof(input)<0){

       cout << "Slimness Ration can't be negative" << endl;

        continue;

    }

    slimnessRatio = atof(input);

    break;

}

//calculate slimnessRation

if(slimnessRatio<120){

    safeLoad = 17000 - (0.485)*slimnessRatio*slimnessRatio;

}

else{

    safeLoad = 18000 / (1+(slimnessRatio * slimnessRatio / 1800));

}

cout << "Calculated Safe Load is : " << safeLoad << endl;

return 0;

}

+++++++++++++++++++++++++++++++++++++++++++

Output :

Enter Slimness Ratio (R) <It can't be negative>: -100
Slimness Ration can't be negative
Enter Slimness Ratio (R) <It can't be negative>: 20
Calculated Safe Load is : 16806

----------------------------------------------------------

Enter Slimness Ratio (R) <It can't be negative>: 120
Calculated Safe Load is : 10000