Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita9cd120

Browse files
authored
Merge pull request#250 from Piyali31/main
Inline Using CPP
2 parents6b77dc2 +516b5f0 commita9cd120

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
//Friend Function of multiple class
3+
#include<iostream>
4+
usingnamespacestd;
5+
classSecond;
6+
7+
/*
8+
Prorotype Declaration---->class Second;
9+
Reason:
10+
because we are using a friend funtion of multiple class,
11+
so,when we going to declare compare function as friend of First &
12+
Second,then at the time of declaration within First class still
13+
class Second is not defined,So,if we don't write prototype
14+
declaration the compiler will not identify what is "Second".
15+
16+
*/
17+
18+
classFirst
19+
{
20+
private:
21+
int a;
22+
public:
23+
voidtake_val();
24+
voiddisplay();
25+
friendvoidcompare(First,Second);
26+
};
27+
28+
void First :: take_val()
29+
{
30+
cout<<"Enter value for a:\n";
31+
cin>>a;
32+
}
33+
void First :: display()
34+
{
35+
cout<<"a="<<a<<endl;
36+
}
37+
38+
classSecond
39+
{
40+
private:
41+
int b;
42+
public:
43+
voidtake_val2();
44+
voiddisplay2();
45+
friendvoidcompare(First,Second);
46+
};
47+
48+
voidSecond::take_val2()
49+
{
50+
cout<<"Enter the value for b:\n";
51+
cin>>b;
52+
}
53+
void Second :: display2()
54+
{
55+
cout<<"b="<<b<<endl;
56+
}
57+
58+
59+
voidcompare(First F,Second S)
60+
{
61+
62+
if(F.a>S.b)
63+
cout<<"max:"<<F.a;
64+
else
65+
cout<<"Max:"<<S.b;
66+
67+
}
68+
69+
intmain()
70+
{
71+
First F1;
72+
F1.take_val();
73+
F1.display();
74+
75+
Second S1;
76+
S1.take_val2();
77+
S1.display2();
78+
79+
compare(F1,S1);
80+
return0;
81+
}
82+

‎Inline.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//Inline
2+
#include<iostream>
3+
usingnamespacestd;
4+
5+
inlineintMax(int x,int y)//compiler may accept or may not accept
6+
{
7+
//it increases the speed of the execution of the code
8+
//if compiler does not accpet inline request
9+
return (x>y)?x:y;
10+
}
11+
intmain()
12+
{
13+
cout<<"The result is:"<<Max(20,50)<<endl;
14+
cout<<"The result is:"<<Max(30,5)<<endl;
15+
return0;
16+
}

‎Nested_Class.cpp‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//One nested class within an outer class
2+
#include<iostream>
3+
usingnamespacestd;
4+
5+
classA
6+
{
7+
public:
8+
classB
9+
{
10+
private:
11+
int n=90;
12+
13+
public:
14+
voiddisplay()
15+
{
16+
cout<<"The result is:"<<n;
17+
}
18+
};
19+
};
20+
intmain()
21+
{
22+
A::B obj;
23+
obj.display();
24+
return0;
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp