Вы находитесь на странице: 1из 8

Faculty: Nitin Jauhari,

Assoc. Prof-ME Deptt, IPEC


MD-2 Lab NME-652 C++ Programs

PART-A: (Computer & Language)


1. Program to Convert Temperature from Fahrenheit to Cesius
#include<stdio.h>
#include<conio.h>
void main()
{
float c,f;
printf("enter the temperature in fahrenheit");
scanf("%f",&f);
c=5.0/9.0*(f-32.0);
printf("the temperature in celius is %f",c);
getch();
clrscr();
}
2. Program to Find the Factorial of a Number
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int i,n;
clrscr();
printf("Enter the number for factorial:\t");
scanf("%d",&n);
i=fact(n);
printf("The factorial of %d is %d",n,i);
getch();
}
int fact(int n)
{
int c;
if(n==0)
return 1;
else if(n==1)
return 1;
else
{
c=n*fact(n-1);
return c;
}}
1
Faculty: Nitin Jauhari,
Assoc. Prof-ME Deptt, IPEC
MD-2 Lab NME-652 C++ Programs

3. Program to find the sum of N integers


# include<stdio.h>
# include<conio.h>
void main ()
{
float n,sum;
printf ("enter the value of integer");
scanf("%f",&n);
sum=n*(n+1)/2;
printf("\n\n the sum of no from 1 to %f is %f\n",n,sum);
getch();
}
4. Program to determine whether a year is leap
#include<stdio.h>
#include<conio.h>
void main()
{
int YEAR;
printf ("ENTER THE YEAR:");
scanf ("%d", & YEAR);
if(YEAR %4==0 && YEAR %100!=0 || YEAR %400==0)
printf("n\n\%d is a LEAP YEAR\n ",YEAR);
else
printf("\n\n%d is not a leap year\n", YEAR);
getch();
clrscr();
}
5. Program to determine elements of fibonacci series
#include<stdio.h>
#include<conio.h>
int fib(int);
void main()
{
int i,n;
clrscr();
printf("Enter the number for fibonacci series:\t");
scanf("%d",&n);
printf("The fibonacci series is :\n");
for(i=1;i<=n;i++)

2
Faculty: Nitin Jauhari,
Assoc. Prof-ME Deptt, IPEC
MD-2 Lab NME-652 C++ Programs
{
printf("%d\t",fib(i));
}
getch();
}
int fib(int n)
{
if(n==1)
{return 0;
}
else if(n==2)
{return 1;}
else
return(fib(n-1)+fib(n-2));
}

PART-B (Computer Program for Conventional Design)


1. Program to determine Spur Gear Dimensions
#include<stdio.h>
#include<conio.h>
void main()
{
int zp,zg,m;
float cd,dp,dg,ha,hd,t,c,g;
clrscr();
printf("Enter the number of teeth on pinion and gear ");
scanf("%d %d",&zp,&zg);
printf("enter module ");
scanf("%d",&m);
cd=m*(zp+zg)/2;
dp=m*zp;
dg=m*zg;
ha=m;
hd=1.25*m;
t=1.5708*m;
c=0.025*m;
g=zg/zp;
printf("\n centre distance %f",cd);
printf("\n PCD of pinion and gear %f %f",dp,dg);
printf("\n addendum and dedendum %f %f",ha,hd);
printf("\n tooth thickness %f",t);
3
Faculty: Nitin Jauhari,
Assoc. Prof-ME Deptt, IPEC
MD-2 Lab NME-652 C++ Programs
printf("\n gear ratio %f",g);
printf("\n clearance %f",c);
getch();
}
2. Program to determine involute profile of gear
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdlib.h>
#define PI=3.14
#define div=100
void main()
{
int gd= DETECT,gm,p,q,z,i,n;
float alfa, alfa1,zi,fi,m,R,Ra,Rb,Rr,S,x,y,w,theta;
float x1,y1,y2,x2,y3,x3,x4,y4,x5,y5,x6,y6;
printf("enter module, no. of teeth,pressure angle in rad");
scanf("%f %d %f",&n,&z,&f);
alfa = PI;
p=200; q=250;
zi=tan(fi)-fi;
R=m*z/2;
Ra=R+m;
Rb=R*cos(fi);
Rr=R-1.157*m;
theta=sqrt(Ra*Ra-Rb*Rb)/(Rb*div);
int graph (p,q,Rr);
circle(p,q,R);
for(i=0;i<z;i++)
(
for(n=0;n<div;n++)
{
w=Rb*n*theta;
r=p+Rb*cos(alfa-n*theta);
s=q+Rb*sin(alfa-n*theta);
x=r-w*sin(alfa-n*theta);
y=s+w*cos(alfa-n*theta);
put pixal(x,y,15);
}
x1=x; y1=y;

4
Faculty: Nitin Jauhari,
Assoc. Prof-ME Deptt, IPEC
MD-2 Lab NME-652 C++ Programs
alfa=(alfa-(PI/z+2*z));
for(n=0;n<div;n++)
{
w=Rb*n*theta;
r=p+Rb*cos(alfa1+n*theta);
s=q+Rb*sin(alfa1+n*theta);
x=r+w*sin(alfa1+n*theta);
y=s-w*cos(alfa1+n*theta);
put pixal(x,y,14);
}
x2=x; y2=y;
line(x1,y1,x2,y2);
x3=p+Rb*cos(alfa);
y3=q+Rb*sin(alfa);
x4=P+Rr*sin(alfa);
y4=q+Rr*sin(alfa);
x5=p+Rb*cos(alfa);
y5=q+Rb*sin(alfa);
y6=q+Rr*sin(alfa);
line(x3,y3,x4,y4);
line(x5,y5,x6,y6);
alfa=alfa-2*PI/z;
}
getch();
close graph();
}

3. Program for design of a roller bearing


#include<math.h>
#include<conio.h>
void main()
{
float fa=0,fr=0,Co=0,e=0,X=0,Y=0,P=0,l=0,n,C=0,a;
int v;
clrscr();
printf("Enter Fa,Fr,Co:");
scanf("%f%f%f",&fa,&fr,&Co);
if((fa/Co>=0.025&&fa/Co<=0.040)||fa/Co<=0.025)
{
e=(((0.24-0.22)/(0.040-0.025))*((fa/Co)-0.025))+0.22;
}

5
Faculty: Nitin Jauhari,
Assoc. Prof-ME Deptt, IPEC
MD-2 Lab NME-652 C++ Programs
else if(fa/Co>=0.040&&fa/Co<=0.070)
e=(((0.27-0.24)/(0.070-0.040))*((fa/Co)-0.040))+0.24;
else if(fa/Co>=0.070&&fa/Co<=0.130)
e=(((0.31-0.27)/(0.130-0.070))*((fa/Co)-0.070))+0.27;
else if(fa/Co>=0.130&&fa/Co<=0.250)
e=(((0.37-0.31)/(0.250-0.130))*((fa/Co)-0.130))+0.31;
else if((fa/Co>=0.250&&fa/Co<=0.500)||fa/Co>=0.500)
e=(((0.44-0.37)/(0.500-0.250))*((fa/Co)-0.250))+0.37;
else
printf("invalid input");
if(fa/fr<=e)
{X=1;
Y=0;
}
else
{X=0.56;
if((fa/Co>=0.025&&fa/Co<=0.040)||fa/Co<=0.025)
Y=(((1.8-2.0)/(0.040-0.025))*((fa/Co)-0.025))+2.0;
else if(fa/Co>=0.040&&fa/Co<=0.070)
Y=(((1.6-1.8)/(0.070-0.040))*((fa/Co)-0.040))+1.8;
else if(fa/Co>=0.070&&fa/Co<=0.130)
Y=(((1.4-1.6)/(0.130-0.070))*((fa/Co)-0.070))+1.6;
else if(fa/Co>=0.130&&fa/Co<=0.250)
Y=(((1.2-1.4)/(0.250-0.130))*((fa/Co)-0.130))+1.4;
else if((fa/Co>=0.250&&fa/Co<=0.500)||fa/Co>=0.500)
Y=(((1.0-1.2)/(0.500-0.250))*((fa/Co)-0.250))+1.2;
}
P=X*fr+Y*fa;
printf("Enter the value of L10:");
scanf("%f",&l);
printf("For ball bearing press 1 and for roller bearing press 2:");
scanf("%d",&v);
if(v==1)
n=0.333333;
else if(v==2)
n=0.3;
else
printf("Invalid input");
a=pow(l,n);
C=P*a;
printf("Value of equivalent dynamic load: %f",P);

6
Faculty: Nitin Jauhari,
Assoc. Prof-ME Deptt, IPEC
MD-2 Lab NME-652 C++ Programs
printf("\nValue of dynamic load capacity is: %f",C);
getch();
}

4. Program to Design a shaft


#include<stdio.h>
#include<conio.h>
#define PI=3.14
void main()
{
int i,rpm;
float p,t,x,fs,w,bm,fb;
printf("for design by torsion press /n");
printf("for design by bm press 2/n");
printf("for design by torque t and bm press 3/n");
scanf("%d",&i);
switch
{
case1;
printf("enter the value of power to be transmitted by the shaft and its rpm");
scanf"%f%d",&p&rpm);
t=(p*60)/(2*PI*rpm);
printf("enter the value of allowable shear stress for the material");
scanf("%f",&fs);
ds=pow(x,0.333)
printf("diameter of shaft=%F",ds);
break;
case2;
printf("enter the value of load");
scanf("%f",&w);
printf("enter the length of shaft");
scanf("%d",&l);
bm=w*l;
printf("enter max. bending stress ");
scanf("%d",&fb);
x=(bm*32)/PI*fb;
ds=-pow(x,0.333);
printf("diameter of shaft = %f",ds);
}
getch();
clrscr();}

7
Faculty: Nitin Jauhari,
Assoc. Prof-ME Deptt, IPEC
MD-2 Lab NME-652 C++ Programs

5. Program to determine torque on a shaft


#include<stdio.h>
#include<conio.h>
#define PI=3.14
float torque(float d,float f);
void main()
{
float T,D,fs;
printf("/n enter the value of diameter in cm");
scanf("%f",&D);
printf("/n enter max. allowed shear stress N/mm^2");
scanf("f",fs);
T=torque (D,fs);
printf("/n torque = %f",T);
}
float torque (float d, float f);
{
float t;
t=(PI/16)*d*d*d*f;
return(t);
getch();
clrscr();
}

PART-C: Mini – Project ( To be given Later)

Вам также может понравиться