You are on page 1of 7

Practical No: 9

Program to Implement Inline Function


ObjatOricnd PregrurnniegUsing C+ (22316)
Practical No. 9: Program to Implement Inline Function

Practieal Signifcance:
The elasses and objects help to represnt real life entity with dinerent attributes and
related membor functioms.
The use of inline funetions facilitates faster execution of the
progrum
Redevant Program Outcomes (POs)

o Basie knowedger Apply knowiedge of bavie mathenatics, sciences and basc


engincering to wolve the beoad-based Compurer engineering problens
Dihcipline knowledget Apply Computer engineering discipline spocific
knowledge to solve oore conmputer engineering relatod problema.
Experiments and practiee: Plan to perfom experinents and pracices to use the
results to olve broud-busod Conpuler enginocring poblems.
Eagineering tools: APply relevant Computer tochnologies and tools wilh an
understanding of the limiatons,
o
Communeation:Communicate effectively in onal and writen fon

I Competency and Practieal skil


This practical is expected to develop the following skils in you 1

DevelopC+ programs to volve bread-baved problem


1. Detine real life entity into clawss and object.
2. Define und use of inline function
3. Compile the program
4. Debug and execute thbe peogram.

IV Redevant Course Outcome(s)


Devvlop C prognims uing elassens itnd objocts,

Pratieal Outcome (POs)


Write Compile' debug/ Execute simple C+ program uning clases, objocts and
inline functions

Relevant Affective domain related Outcomets)


Seleet peuper prograhmingenvinonmentin C
2. Follow safety imeasures
3, Follow ethical
practices
VI Minimum Theoretieal Background
Tnline Function: Ct+ inline function is concept that is commonly used with clasoes
Ifa Aunction is inline, the compiler places a copy of the code of that lunction at cach
point where the function is callod at compile time.
Afunction detinition in a class definition is an inline tlunction definition, even without
the use of the inline keyword.

To inline a function, place the keyword


inline before the function name and the
the function before any calls are made to the function. The compiler can igoone define
inline qualifier in cave defined funetion is more than a line
Delaring inline function:
Masrsra stase Beued of Tochnical Esdazaion
MAEER'S MIT Polytechnic, Pune-38

actical Keloded Questions


What daes the inline Keyuwosd do
aIndicate oa tuncho declorohion.
b. lells the
Compilex to use the tunetion
only uithin the some Saurce Code ile.
c. Cowse all funcBions calls to beepla.cec by
the Cade tom the functia0
d. Allows ane -ine tunction cdelaxohon.
Cause Oll tunchion Callc to be eplaceo by
C
h e Code om the tuncho.

2 Whywouldqou oant TOse inline tuncthion


a lo deczeaue the Siee gB the
atbaltinghocron
b) lo inCaee the speeri ot the 2ltinqpa0gaam
C. To Simplitty fhe Source Code ile
d) lo>emove OnoecesSay unctions
lo inceabe the speed
Othe atdltiog
pacaom.

3hich of the tollowinq is a limit on aline


Funchons
a.Inline hunchans Cannat dehun O Value
bnline unchon Mast eurn o ualue
C. Inlinc tunchons MOst be less han ten line
d. The Camplier ma
chooce to l9noe Qn
iolae dixtchwe
MAEER'S MIT Polytechnic, Pune-38

The Complie My Chooge ianore an


inline dinectiue

G hchb of the hollous.nq is a valid ialine


D x hunchoo t o 0
inline void tool)
b oid too ) inline 3
C. inline void too ()3
dNone o f the obove
ialine void too ) {3-
Run DebugStop CShare H Save ()Beautify Language C++

main.cpp
//SYIF HARSH KAMBLA
1/ROLL NO 38
3 #include<iostream>
using namespace std;
class Number

int x,y,add, sub, mul, divi;


3 public:
9 void accept ();
10 void sum); void substracted (); void product(); void division();

11
12
13 inline void Number accept()
14
5 10;
16 y=5
17 }
8
19 inline void Number sum()
20 {
21 add-x*y
22 cout<e"\n addition: "<<add;
23
24 inline void Number: substracted()
25
26 sub x-y;
27 cout<e"\n substraction: "<<sub;
28
29 inline void Number product ()
30
31
32
mul-x*y multiplication : "<smul;
cout<"\n
33

35
34

inline void Number: division ()


36
37
divi-x/y;
cout"\n division: "<<divi;
38
39
40 int main()
41 {
42 Number n1:
43 n1.accept();
44 n1.sumO;
45 n1.substracted();
46
47
n1.product ():
n1.division();
48 return 0;
49
addition: 15
substraction: 5
multiplication: 50
division: 2

. .
.Programfinished with exit code 0
Press ENTER to exit
console.
Debug H Save () Beautify
RunORun Stop Share
main.cppP
1/SYIF HARSH KAMBLE
2 1/ROLL NO: 38
3 #include<iostream>
4 using names pace std;
5 class InlineDemo
64
7 public:
8 int square(int s); //declare the function
9

10 / use Inline prefix


11
12 inline int InlineDemo :: square(int s)
13-{
14 return s*s;
15 }
16
17 i n t main()

18-{
19 InlineDemo s;
20 cout< Square of a No is: "<<s. square( 10);
21 return 0;
22
23
Square of a No is: 100

.Program finished with exit code 0


Press ENTER to exit
console.|

You might also like