Anda di halaman 1dari 4

# f:\Simply Supported Beam\Simply Supported Beam\Simply Supported Beam.

cpp 1
// Analysis of a single span simply supported beam
// Computation of end reactions, shear and bending moment
// Underlying Concept: Principle of superposition
// Environment: Visual C++ 2008 Express Edition
// Programmer: Prof. S A Vasanwala
// Debugger: Prakash Agarwal
// Date: 05/02/2010

## #include <iostream> // cin, cout objects

#include <iomanip> // setw(), setprecision() function
#include <cstdlib> // exit() function

## const int elements = 102; // maximum number of sections under...

// ...which user can split the beam
void
main(void)
{
double RL = 0.0, RR = 0.0, // Reactions at left and right support
R1, R2, // Reactions at left and right support...
l, // Span of beam
a, // Distance from left support
W, // Total weight of load under consideration
W1, // Weight of UDL load used in moment...
// ...calculation at a section
dist, // Distance of section from left support
s, t, b1, // Temporary variables
moment[elements] = {}, // Moment at a section
shear[elements] = {}; // Shear at a section

no_section, // Number of sections
j, k; // Loop control variables

## cout << "\nEnter span of beam [m]: ";

cin >> l;
cout << "\nEnter number of sections into which\n"
<< "the span is to be divided [max. 100]: ";
cin >> no_section;
cout << "\nEnter number of loads on the span [integer]: ";

## for (k = 1; k <= no_load; k++)

{

cout << "\nLoad number: " << k << endl << endl
<< " Type 2: Uniformly Distributed Load " << endl
<< " Type 3: Triangular Load - Left to Right " << endl
<< " Type 4: Triangular Load - Right to Left " << endl;

## cout << "\nEnter type of load [integer]: ";

cin >> type;
cout << "\nEnter total weight of the load [kN]: ";
cin >> W;
cout << "\nEnter distance from left support [m]: ";
cin >> a;
if (type != 1)
{
cout << "\nEnter load cover [m]: ";
cin >> c;
f:\Simply Supported Beam\Simply Supported Beam\Simply Supported Beam.cpp 2
}
else c = 0;

// Computation of reactions

switch(type)
{
case 1:
s = a;
break;
case 2:
s = a + (c / 2.0);
break;
case 3:
s = a + (2 * c / 3.0);
break;
case 4:
s = a + (c / 3.0);
break;
default:
cout << "\nInvalid Load Type "
<< "\nTerminating..." << endl;
exit(0);
}

t = l - s;
R1 = W * t / l;
R2 = W - R1;
RL = RL + R1;
RR = RR + R2;

// Computation of moments

## for (j = 2; j <= (no_section+1); j++)

{

dist = (j - 1) * (l / no_section);
if (dist <= a)
{
moment[j] = moment[j] + (R1 * dist);
shear[j] = shear[j] + R1;
}
else if (dist >= (a + c))
{
moment[j] = moment[j] + R2 * (l - dist);
shear[j] = shear[j] - R2;
}
else
{

b1 = dist - a;
if (type == 2)
{
W1 = W * b1 / c;
moment[j] = moment[j] + R1 * (a + b1)
- W1 * b1 / 2.0;
shear[j] = shear[j] + R1 - W1;
}
else if (type == 3)
{
W1 = W * (b1 / c) * (b1 / c); // Hint: Similar triangles
moment[j] = moment[j] + R1 * (a + b1)
- W1 * b1 / 3.0;
shear[j] = shear[j] + R1 - W1;
f:\Simply Supported Beam\Simply Supported Beam\Simply Supported Beam.cpp 3
}
else if (type ==4)
{
// Note: Computations from right side unlike in...
// ...previous cases
b1 = c - b1;
W1 = W * (b1 / c) * (b1 / c);
moment[j] = moment[j] + R2 * (1 - a - c + b1)
- W1 * b1 / 3.0;
shear[j] = shear[j] - R2 + W1;
}
}
} // End of j loop
} // End of k loop

## // Display of results in tabular format

char press;
cout.setf(ios::fixed | ios::showpoint);
cout.precision(2);

## cout << "\n\nAnalysis Results\n"

// Drawing of ~ character below the above title
<< setw(17) << setfill('~') << ""
<< endl;
// Resetting fill character as blank
cout << setfill(' ');

cout << "\nLeft hand reaction [kN]: " << RL << endl
<< "\nRight hand reaction [kN]: " << RR << endl;

## cin.ignore(100, '\n'); // Cursor set after '\n' character...

// ...in input stream

shear[1] = RL;

## cout << "\nLocation[m]" << setw(15) << "Moment[kN.m]" << setw(14)

<< "Shear[kN]\n" << endl;

## for (j = 1; j <= (no_section+1); j++)

{
if (j ==1)
dist = 0.0;
else
dist = (j - 1) * (l / no_section);
if (j == 10)
{
cout << "\nPress enter to continue...\n\n";
cin.get(press);
}
cout << setw(8) << setprecision(2) << dist
<< setw(15) << setprecision(3) << moment[j]
<< setw(14) << shear[j] << endl;
}

## for (j = 1; j <= (no_section+1); j++)

if (moment[j] > max_moment)
{
max_moment = moment[j];
dist_x = (j - 1) * (l / no_section);
}
f:\Simply Supported Beam\Simply Supported Beam\Simply Supported Beam.cpp 4

cout << "\nMaximum moment [kN.m]: " << max_moment << endl
<< "At a distance " << dist_x << " m from left support "
<< endl;
}