Machine Design-II Lab
Machine Design-II Lab
La
b MACHINE DESIGN-II LAB
(KME-652)
or
AKTU syllabus
at
For
or SEMESTER
y
M
an
Copyright
For more i Page 1
Lab Manual MD-II LAB (KME-652)
TABLE OF CONTENTS
1 Basics of C language.
Introduction of C language.
2 Basics of C language.
Types, Operators, and Expressions of C language.
3 Basics of C language.
Branching and Iteration in C language.
Experiment – 4
4
Write a programme in C language for design of spur gear.
Experiment – 5
5 Write a programme in C language for design of helicalgear.
Experiment – 6
6 Write a programme in C language for design of cylinderhead.
Note:
2|Page
Lab Manual MD-II LAB (KME-652)
Basics of C language
Introduction:
C is a general-purpose programming language, and is used for writing programs in many
different domains, such as operating systems, numerical computing, graphical applications, etc.
It is a small language, with just 32 keywords. It provides “high-level” structured programming
constructs such as statement grouping, decision making, and looping, as well as “low level”
capabilities such as the ability to manipulate bytes and addresses. C achieves its compact size
by providing Spartan services within the language proper, foregoing many of the higher-level
features commonly built-in to other languages.
A First Program
A C program, whatever its size, consists of functions and variables. A function contains
Statements that specify the computing operations to be done, and variables store valuesused
during the computation.
main(void)
{
printf("Hello World!\n");
}
start with /* and are terminated with */. They can span multiple lines and are not
nestable. For example,
/* this attempt to nest two comments /* results in just one comment,
ending here: */ and the remaining text is a syntax error. */
Inclusion of a standard library header-file. Most of C’s functionality comes from
libraries. Headerfiles contain the information necessary to use these libraries, such as
function declarations and macros.
All C programs have main() as the entry-point function. This function comes in two
forms:
int main(void)
int main(int argc, char *argv[])
The first takes no arguments, and the second receives command-line arguments from the
environment in which the program was executed—typically a command-shell. The function
returns a value of type int (i.e., an integer)
3|Page
Lab Manual MD-II LAB (KME-652)
The braces { and } delineate the extent of the function block. When a function
completes, the program returns to the calling function.
In the case of main(), the program terminates and control returns to the environment
in which the program was executed. The integer return value of main() indicates the
program’s exit status to the environment, with 0 meaning normal termination.
This program contains just one statement: a function call to the standard library
function printf(), which prints a character string to standard output (usually thescreen).
Note, printf() is not a part of the C language, but a function provided by the standard
library (declared in header stdio.h). The standard library is a set of functions mandated
to exist on all systems conforming to the ISO Standard. In this case, the printf() function
takes one argument.
#include <stdio.h>
#include <conio.h>
main(void)
{
printf("Hello World \n ");
}
The next program also prints “Hello World!” but, rather than printing the whole stringin one
go, it prints it one character at a time. This serves to demonstrate several new concepts,namely
4|Page
Lab Manual MD-II LAB (KME-652)
Basics of C language
Introduction:
Variables and constants are the basic data objects manipulated in a program. Declarations list
the variables to be used, and state what type they have and perhaps what their initial values are.
Operators specify what is to be done to them.
Identifiers
Identifiers (i.e., variable names, function names, etc) are made up of letters and digits, and are
Case-sensitive. The first character of an identifier must be a letter, which includes underscore
(_).1 The C language has 32 keywords which are reserved and maynot be used as identifiers (eg,
int, while, etc).
Types
C is a typed language. Each variable is given a specific type which defines what values it can
Represent, how its data is stored in memory, and what operations can be performed on it. By
forcing the programmer to explicitly define a type for all variables and interfaces, the type
system enables the compiler to catch type-mismatch errors, thereby preventing a significant
source of bugs.
C Data Types
Char usually 8-bits (1 byte)
Int usually the natural word size for a machine or OS (e.g., 16, 32, 64
short int bits)
long int at least 16-bits
float at least 32-bits
float double usually 32-bits
long double usually 64-bits
usually at least 64-bits
Constants
Constants can have different types and representations. This section presents various constant
types by example. First, an integer constant 1234 is of type int. An constant of type long int is
suffixed by an L, 1234L; (integer constants too big for int are implicitly taken as long).
5|Page
Lab Manual MD-II LAB (KME-652)
Conversion Specifies
The standard function printf() facilitates formatted text output. It merges numerical values of
any type into a character string using various formatting operators and conversion specifiers.
printf("Character values %c %c %c\n", ’a’, ’b’, ’c’);
printf("Some floating-point values %f %f %f\n", 3.556, 2e3, 40.1f);
printf("Scientific notation %e %e %e\n", 3.556, 2e3, 40.1f);
printf("%15.10s\n", "Hello World\n");
Declarations
All variables must be declared before they are used. They must be declared at the top of a block
(a section of code enclosed in brackets { and }) before any statements. They maybe initialized by
a constant or an expression when declared. The following are a set of example declarations.
{ /* bracket signifies top of a block */
int lower, upper, step; /* 3 uninitialised ints */ char
tab = ’\t’; /* a char initialised with ’\t’ */ char
buf[10]; /* an uninitialised array of chars */ int m =
2+3+4; /* constant expression: 9 */
int n = m + 5; /* initialised with 9+5 = 14 */ float
limit = 9.34f;
const double PI = 3.1416;
Arithmetic Operations
The arithmetic (or numerical) operators come in two varieties: unary and binary. The binary
operators are plus +, minus −, multiply ∗, divide /, and the modulus operator %. The first four
operators can be used on integer or floating-point types, although it is important to notice that
integer division truncates any fractional part.
int a=2, b=7, c=5, d=9;
printf("a*b + c*d = %d\n", a*b + c*d);
6|Page
Lab Manual MD-II LAB (KME-652)
Basics of C language
Introduction:
The C language provides three types of decision-making constructs: if-else, the conditional
expression?:, and the switch statement. It also provides three looping constructs: while, do-
while, and for. And it has the infamous goto, which is capable of both non-conditional branching
and looping.
If-Else
The basic if statement tests a conditional expression and, if it is non-zero (i.e., TRUE),
executes the subsequent statement. For example, in this code segment
if (a < b)b
= a;
the assignment = a will only occur if a is less-than b. The else statement deals with the
alternative case where the conditional expression is 0 (i.e., FALSE).
if (a < b)b
= a; else
b += 7;
The if-else statement can also command multiple statements by wrapping them in braces.
Statements so grouped are called a compound statement, or block, and they are syntactically
equivalent to a single statement.
if (a < b) {b
= a;
a *= 2;
}
else {
b += 7;
--a;
}
Conditional Expression
The conditional expression is a ternary operator; that is, it takes three operands. It hasthe
following form
(expression 1) ? (expression 2) : (expression 3)
If the first expression is TRUE (i.e., non-zero), the second expression is evaluated, otherwise the
third is evaluated. Thus, the result of the ternary expression will be the result of either the
second or third expressions, respectively. For example, to calculate the maximum of two values,
c = (a > b) ? a : b; /* c = max(a,b) */
7|Page
Lab Manual MD-II LAB (KME-652)
As a branching construct, the ?: operator appears far less frequently than the if-else andswitch
constructs.
Switch
The switch statement is a multi-way decision that tests whether an expression matchesone of a
number of constant integer values, and branches accordingly.
The general form of the switch statement is as follows.switch
(expression) {
case const-int-expr: statements
case const-int-expr: statements
default: statements
}
While Loops
The while loop has the general form while (expression) statement;
If the conditional expression is TRUE, then the while will execute the following statement, after
which it will reevaluate the conditional. It continues this iteration while ever the conditional
remains TRUE. As with the if-else statement, the while loop can execute multiple statements as a
block by enclosing them in braces. For example, the following code segment computes the
greatest common divisor (GCD) of two positiveintegers m and n (i.e., the maximum value that will
divide both m and n). The loop iterates until the value of n becomes 0, at which point the GCD is
the value of m.
while (n) {
int tmp = n;
n = m%n;
m = tmp;
}
Do-While Loops
The do-while loop has the general form
do
statement;
while (expression);
Its behavior is virtually the same as the while loop except that it always executes the statement
at least once. The statement is executed first and then the conditional expression is evaluated
to decide upon further iteration. Thus, the body of a while loop is executed zero or more times,
and the body of a do-while loop is executed one or more times.
For Loops
The for loop has the general formfor
(expr1; expr2; expr3) statement;
8|Page
Lab Manual MD-II LAB (KME-652)
Its behavior is equivalent to a while loop with the following arrangement of expressions.expr1;
while (expr2) {
statement;
expr3;
}
In the for loop, expressions 1, 2, and 3 are optional, although the semicolons must remain. If
expressions 1 or 3 are not there, then the loop simple behaves like the while loop above
without expressions 1 or 3. If expression 2 is omitted, then the conditional is always TRUE, and
an infinite loop results.
Goto
The goto statement has a well-deserved reputation for being able to produce unreadable
“spaghetti”code. It is almost never necessary to use one, and they should be avoided in general.
However, on rare occasions they are convenient and safe.
#include <stdio.h> /* for printf() */ 2
#include <stdlib.h> /* for rand() */
3 #include <string.h> /* for memset() */ 4
5 #define SIZE 1000
6 enum { VAL1=’a’, VAL2=’b’, VAL3=’Z’ };
7
23
8 int main(void)
9 /* Demonstrate a legitimate use of goto (adapted from K&R page 66). This example is
contrived, but the idea is to
9|Page
Lab Manual MD-II LAB (KME-652)
10 | P a g e
Lab Manual MD-II LAB (KME-652)
EXPERIMENT – 1
#include<stdio.h>
#include<conio.h>
#include<Math.h>
void main()
{
Clrscr();
float cv,m,dg,dp,Vr,Sp,Yp,y,w,wt,v,n,ng,np,s,d,b,tg,tp,Yp,Sg,t; printf(“enter
the values”);
printf(“module, pinion speed, gear diameter, velocity ratio, pinion stress, gear stress,face
width, pinion teeth, tangential load, gear speed”);
scanf(“%f%f%f%f%f%f%f%f%f%f”, &m,&np,&dg,&Vr,&Sp,&Sg,&b,&tp,&ng,&wt); ng=np*Vr;
dp=dg/Vr;
tg=tp*Vr;
Yp=0.175 – 0.951/tp;
Yg=0.175 – 0.951/tg;
if(Yp*Sp>Yg*Sg);
{
S=Sp;
n=np;
t=tp;
d=dp;
Y=Yp;
}
t=tg;
d=dg;
n=ng;
Y=Yg;
S=Sg;
V=3.14*d*n/60;
Cv=6.1/(6.1+v);
11 | P a g e
if(wt<w);
printf(“design is not safe”);
printf(“calculate tangent load=%f”,wt);
getch();
}
EXPERIMENT – 2
Objective: - Write a programme in C language for Sliding Contact Bearing.
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int w,n,d;
float l,c,z,p,k,bm,u,q,kj,N;printf(“enter
the values”);
printf(“diameter, load, speed, viscosity, bearing, clearance”);
scanf(“%d%d%d%f%f”,&d,&w,&n,&z,&c);
k=0.002;
l=1.5*d;
p=w/l*d;
bm=z*n/p;
u=33*bm*c*10*10*10*10*10*10*10*10+kj;
q=u*w*3.14*d*N/60;
printf(“length of the bearing=%f”,l);
printf(“heat generated=%f”,q);
getch();
}
EXPERIMENT – 3
include<stdio.h>
include<conio.h>
include<math.h>
void main ()
{
int bp,n,em,s;
float p,d,l,t,ip,k,ns,q,gf,dc,du,dp,pm,b,D,dcl,r;printf
(“enter the values” );
printf (“brake power, speed, mean effective pressure, stress, diameter, mechanicalefficiency” );
scanf(“%d%d%f%d%f%d” ,&bp,&n,&pm,&s,&d,&em);ip=bp*100/em;
1=1 .5*d;
p=q*pm ;
r=p/s;
ns=0.015*p+4;
gf=3.14*d*d*pm/4;
dcl=(gf*4)/(ns*3.14*s);
dc=sqrt(dcl) dp=d+3*4;
p=3.14*d+1.5;
t=0.045*d+1.5;
printf (“the calculated values are”) ;
printf (“thickness of cylinder head=%f ”, t);printf
(“no of stubs=%f ”,ns);
printf (“length=%f ”, l);
printf (“pitch=%f ”, p)
getch();