Hi,Iam Qasim and I am undertaking C++ course. I am working on my project which allows the user to calculate shear force and bending moments on a beam. What basically is the output are the graphs drawn on the beam which show the forces acting after calculation. I am facing two problems in it, Firstly, how can I draw a rectangle with the length equal to the length given by the user. Secondly, how can I use the answers obtained in drawing a graph.
int check=1;
int shear(float p[][2], int num,float reaction1,float reaction2,float length,float e[][3],int num1);
float add(float r1,int point,float q[][2],int random);
float momentpoint(float u[][2],float w[][3],float shearvalue,int momentnum, float previous,float end1,float end2);
void body();
int shear(float p[][2], int num,float reaction1,float reaction2,float length,float e[][3],int num1)
{
float force=0;
float area=0;
float torque=0;
float ans=0;
float pre=0;
float ls=0;
srand(time(NULL));
for(int x=0;x<num;x++)
{
int a;
int b;
a=p[x][1];
b=0;
if(x>0)
b=p[x-1][1];
else
b=0;
float end=0;
if(x>0)
end=p[x-1][1];
else
end=0;
float req=p[x][1]-end;
int sub=a-b;
int d=sub+1;
int result=b+rand()%d;
force=add(reaction1,num,p,result);
int count=0;
for(int y=0;y<num1;y++)
{
if(e[y][1]<=end && e[y][1]>=p[x][1])
count++;
}
printf("Shear force in %d section is %.2fkN from %fm-to-%fm\n",x+1,force,end,p[x][1]);
if(count==0)
{
area=force*req;
printf("The BM for this section lies btw %.2fkNm-to-%.2fkNm\n",torque,area);
torque=area;
}
else if(count>0)
{ans=momentpoint(p,e,force,num1,pre,end,p[x][1]);
pre=ans;
}
if(x==(num-1))
ls=p[x][1];
}
float r;
r=reaction2;
printf("The shear force in last section is %.2fkN\n", -r);
if(num1==0)
{
printf("The BM in the last section lies btw %.2fkNm-to-0.00",area);
}
else
momentpoint(p,e,-r,num1,pre,ls,length);
return 0;
}
float add(float r1,int point,float q[][2],int random)
{
int counter=0;
void init();
void myMouseFunction( int button, int state, int mouseX, int mouseY );
void myKeyboardFunction( unsigned char key, int mouseX, int mouseY );
void mySpecialKeysFunction(int key, int x, int y);
void myReshapeFunction( int width, int height );
void myTimerFunction( int val );
void myDisplayFunction();
int main(int arg, char** argv)
{
glutInit( &arg, argv );
void myMouseFunction( int button, int state, int mouseX, int mouseY )
{
if (check==1)
check=0;
else
check=1;
if (check==1)
body();
printf("%d %d %d %d\n",button,state,mouseX,mouseY);
glEnd();
//return(0);
}
void myKeyboardFunction( unsigned char key, int mouseX, int mouseY )
{
if( key == 27 ) // i.e. Esc key
exit(0);
}
void mySpecialKeysFunction(int key, int x, int y)
{
switch( key )
{
case GLUT_KEY_UP:
break;
case GLUT_KEY_DOWN:
break;
case GLUT_KEY_LEFT:
break;
case GLUT_KEY_RIGHT:
break;
case GLUT_KEY_HOME:
break;
case GLUT_KEY_END:
break;
case GLUT_KEY_PAGE_UP:
break;
case GLUT_KEY_PAGE_DOWN:
break;
}
}
void myReshapeFunction( int width, int height )
{
glClear(GL_COLOR_BUFFER_BIT);
void myTimerFunction( int val )
{
glutTimerFunc( 33, myTimerFunction, 0 );
myDisplayFunction();
}
void myDisplayFunction()
{
glClear( GL_COLOR_BUFFER_BIT );
glBegin(GL_LINE_LOOP);
static int x;
if (x<=303)
x++;
else x--;
glColor3ub(0, 0, 255);
glVertex2i( 50, 50+x );
glVertex2i(50 , 100+x );
glVertex2i( 100, 100 );
glVertex2i( 100, 50 );
glEnd();
glutSwapBuffers();
//printf(" %d", x);
}
void body()
{printf("Enter the value of reaction 1\n");
float react1=0;
scanf("%f", &react1);
printf("Enter the value of reaction 2\n");
float react2=0;
scanf("%f", &react2);
printf("Enter the length of the beam\n");
float l=0;
scanf("%f", &l);
printf("Enter the number of point loads\n");
float number;
scanf("%f", &number);
float u[max][2];
for(int x=0;x<number;x++)
{
for(int y=0;y<2;y++)
{
if(y==0)
printf("Enter the magnitude of %d load",x+1);
else
printf("Enter its point of application");
scanf("%f", &u[x][y]);
}
}
printf("Enter the number of moments acting on our beam");
int number1=0;
scanf("%d", &number1);
float w[max][3];
for(int g=0;g<number1;g++)
{
for(int h=0;h<3;h++)
{
if(h==0)
printf("Enter the magnitude of %d moment",g+1);
else if(h==1)
printf("Enter its point of application");
else
printf("Enter '0' if clockwise and '1' if anticlockwise");