Last time (I hope!) I am writing a large C++ program that figures out the deflec
ID: 3546437 • Letter: L
Question
Last time (I hope!) I am writing a large C++ program that figures out the deflection of a beam. Thanks to some fantastic help previously from here, I was able to fix my incrementing problem. I have one last problem with the program and I am lost. This piece of code is for calculating the deflection of a beam with a load place at a user determined point on the beam. For this you need to use two equations depending on where your measuring point is. Here is what I have:
#include <iostream> //pre-processor directs - iostream talks to screen
#include <iomanip> //pre-processor directs - string
#include <cmath> // allows math functions
using namespace std;
const int size=100;
int main ( void )
{
double x[size], y[size];
double L = 10.0, I = 1.5375e-7, E = 6.90e+10, a = 5, f;
int N = 20, W = 500;
f = L-a;
for (int i=0;i<=N;i++) //initiates, defines and sets counter
x[i]=(i*(L/N)); //initiates the first value of the array
cout<<" This program has calculated the deflection of the beam";
cout<<" from the information supplied by you."<<endl;
cout<<" Distance from end of beam: x(m) "<<" Deflection: d(m)"; //prints column headers to screen
cout<<" ------------------------------------------------------------"<<endl;
for (int i=0;i<=f;i++) //initiates, defines and sets counter
y[i]=(-W/(6*E*I))*(pow(-a,3)-3*pow(a,2)*L-3*pow(a,2)*x[i]); //calculates beam deflection
for (int i>f;i<=N;i++) //initiates, defines and sets counter
y[i]=(-W/(6*E*I))*(pow((x[i]-f),3)-3*pow(a,2)*(x[i]-f)+2*pow(a,3)); //calculates beam deflection
for (int i=0;i<=N;i++)
//initiates, defines and sets counter
cout<<setiosflags(ios::scientific)<<setprecision(3)<<setw(10)
<<x[i]<<setprecision(3)<<setw(35)<<y[i]<<endl;//prints values in arrays to screen
cout<<endl;
system("pause");
return 0;
}
I can't seem to get this part to work. i keep getting multiple errors. Anyone have an idea of what I am doing wrong?
Explanation / Answer
#include <iostream> //pre-processor directs - iostream talks to screen
#include <iomanip> //pre-processor directs - string
#include <cmath> // allows math functions
using namespace std;
const int size=100;
int main ( void )
{
double x[size], y[size];
double L = 10.0, I = 1.5375e-7, E = 6.90e+10, a = 5, f;
int N = 20, W = 500;
f = L-a;
for (int i=0;i<=N;i++) //initiates, defines and sets counter
x[i]=(i*(L/N)); //initiates the first value of the array
cout<<" This program has calculated the deflection of the beam";
cout<<" from the information supplied by you."<<endl;
cout<<" Distance from end of beam: x(m) "<<" Deflection: d(m)"; //prints column headers to screen
cout<<" ------------------------------------------------------------"<<endl;
for (int i=0;i<=f;i++) //initiates, defines and sets counter
y[i]=(-W/(6*E*I))*(pow(-a,3)-3*pow(a,2)*L-3*pow(a,2)*x[i]); //calculates beam deflection
for (int i=f;i<=N;i++) //initiates, defines and sets counter
y[i]=(-W/(6*E*I))*(pow((x[i]-f),3)-3*pow(a,2)*(x[i]-f)+2*pow(a,3)); //calculates beam deflection
for (int i=0;i<=N;i++)
//initiates, defines and sets counter
cout<<setiosflags(ios::scientific)<<setprecision(3)<<setw(10)
<<x[i]<<setprecision(3)<<setw(35)<<y[i]<<endl;//prints values in arrays to screen
cout<<endl;
//system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.