0% found this document useful (0 votes)
112 views10 pages

Friend Function in C++ ?

Friend functions allow non-member functions to access private and protected members of a class. Inline functions request the compiler to treat functions without multiple instructions as inline to reduce function call overhead. Function overloading allows using the same function name with different parameters. Constructors are special functions that are called automatically when an object is created. Destructors are called automatically when an object is destroyed to deallocate memory. Templates allow writing generic functions and classes that can work with multiple data types. Operator overloading allows user-defined types to use operators like built-in types. Inheritance allows classes to access properties of other classes. There are different types of inheritance like single, multiple, hierarchical, multi-level and hybrid inheritance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views10 pages

Friend Function in C++ ?

Friend functions allow non-member functions to access private and protected members of a class. Inline functions request the compiler to treat functions without multiple instructions as inline to reduce function call overhead. Function overloading allows using the same function name with different parameters. Constructors are special functions that are called automatically when an object is created. Destructors are called automatically when an object is destroyed to deallocate memory. Templates allow writing generic functions and classes that can work with multiple data types. Operator overloading allows user-defined types to use operators like built-in types. Inheritance allows classes to access properties of other classes. There are different types of inheritance like single, multiple, hierarchical, multi-level and hybrid inheritance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

QUESTION

Kalpesh Singh Rao | [email protected]

1. Friend Function in C++ ?


 Definition :- Friend Function Ek Esa Function Hai Joh Class Ka Member Na Hote Hue Bhi
Us Class Ke private aur Protected Data Member Aur Function Ko Access Karata Hai.
 Syntax :-
o Friend return-type Function Name ( Class Object) { body }
 Friend Function Ko Ham Class Ke Andar Declare Karenge Friend Keyword Ke Sath Me.
 Freind Function Joh Hai Voh Ek Ya Ek Se Jayada Class Ka Friend Ban Skata Hai.
 With Example Code :-
o #include< iostream>
o Using Namespace std;
o Class A
o {
o Int A,B;
o Public:
o Void Input ()
o {
o Count << “ Enter Value: “ ;
o Cin >> a >> b;
o }
o Friend void add(a ob);
o };
o Void add( A ob)
o {
o Int c;
o C= ob.a + ob.b;
o Count << “SUM=” <<C;
o }
o Int Main ()
o {
o A kk;
o Kk.input();
o Add(kk);
o Return 0;
o }

Street Address, City, ST ZIP Code

Office: Telephone | Website


2. Inline Function :-
 Inline Function Request Karta Hai Compiler Se Ki Hamare Function Ko Inline
Treat Kare.
 Yeh Reduce Karata Hai Overhead Function ke Calling ke andar.
 Agar Compiler Kisi Function Ko As a Inline Function Treat Karata Hai toh
Voh Function Hota Hai Voh Ek Hi Line Me Separate Kar Deta Hai.
 Agar Inline Function Me Ek Se Jayada Instruction De dete Hai toh Yeh
Inline Function Treat Nhi Kiya Jaata Hai.
 Syntax :-
 Inline return-type function name()
 {
 ---------------- // Single Instruction
 }
 Program :-
 #Include <iostream.h>
 #Include<conio.h>
 Inline Void fun()
 {
 Count<<” Hello C++ ” ;
 }
 Void Main() {
 Clrscr();
 Fun();
 Getch();
 }

Street Address, City, ST ZIP Code

Office: Telephone | Website


3. Function Overloading ?
 C++ Me ek se jayada ek jaisi name ke function ko Use Kiya Jaata Hai
 Leking C Ke Andar Iska Use Nhi Ho Sakta.
 Ek Program Me Ek Se Jayada Ek Hi Name Ke Function Istemal Karna
Function Overloading Kahete Hai.
 Ek Function Ko Dusri Baar Pahele Jaisa Use Nhi Kiya Jaa Sakta

#include <iostream.h>
using namespace std;
void func();
void func(int);
void func(float);
void func(int, float);
void func(int, float, int);
int main()
{
int x = 10;
float y = 3.14;
int z = 20;
func();
func(x);
func(y);
func(x, y);
func(x, y, z);
return 0;
}
void func(){
cout<<"Hello World!"<<<"value="" of="" a="" :="" "<<a<<<c<<="" pre=""
style="box-sizing: border-box; font-family: "Noto Sans";">

Street Address, City, ST ZIP Code

Office: Telephone | Website


4. What Is Constructure and Destructure ? Explain with
Example.
 Constructure Point
 Joh Hamara Class Ka Name Rahega Vahi Hamare Constructure ka Name
Rahega Constructure ek special type of function hai.
 Isme Jab Class Ka Object Declare Karenge toh Constructure
Automatically call Ho Jayega.
 Class Ka Joh Return Type Hoga Vahi Hamara Constructure ka Return Type
Hoga.
 Destructure Point
 Destructure ek special member function hai.
 Yeh bhi automatically excute hota hai.
 Yani ki Yeh Constructure Jab Object Create Karata Hai. Toh
Usko Destroy Karata hai destructure.
 Destructure Memory Ko De-allocated Karata Hai. Yeh
constructure ke object ke dwara jo hamane memory Create
Kiya tha. Use De-allocate Karata Hai Distructure. Isliye Isko
Destructure kahete hai.
 Jab Ham Distructure Banayenge tab ham tilde (~) ka use
karenge.
 Yeh ~ Memory Ko De-allocate karata hai.

Street Address, City, ST ZIP Code

Office: Telephone | Website


Ex: Constructor And Destructure :-
#include <iostream.h>
#include <conio.h>
Class test
{
Public:
Test()
{
N=10;
Count<<n;

}
~test ()
{
Count<<” object destroy “ ;
}
};
Void main()
{
Test ob;
Getch();
}

There are Three Types Of Constructure :-


1. Default Constructure.
2. Parameterized Constructure.
3. Copy Constructure

Street Address, City, ST ZIP Code

Office: Telephone | Website


5. What Is Templete ? Explain with Types.
 Ism eek Hi Frame Ke Andar Sare Concept Ko Add Kiya Gya Hai C++ Ke
Programming Language Ke Andar.
 Ham Templete se Kisi bhi program ko easily kar sakate hai.
 Ham Templete ka Use C++ Ke andar 2 Type Se Karate Hai. Ek Hota Hai
Function Templete aur Dusra Hota Hai Class Templete.
 Function Templete ko Ham Generic Function bhi Bolte Hai.
 Class Templete ko Ham Generic Class Bhi Bolte Hai.

Template

Generic Function Generic Class

Syntax :-
(1). Function Template :-
Template< Class Type >
Return Type Functionname( parametered list)
{
Body
}
Syntax 2 :-
(2). Class Template:-
Template< Class Type >
Class Classname( parametered list)
{
Public:
Type var;
Type functioname (type arg)
}

Street Address, City, ST ZIP Code

Office: Telephone | Website


6. What Is Operator overloading ? Define is Type.
 Operator Overloading C++ Ke Andar ek mahtavpurn taknik hai.
 Joh C++ Ki Karyshamata Ko Badhata Hai.
 C++ Me Ham User Define Data Type Bana Skaate Hai.
 Joh Built In Type Ki Tarah Kary Karate Hai.
 Isko Hi Ham Operator Overloading Kahete Hai.
# include < iostram.h>
# include < conio.h>
class integer
{
int x ;
public :
void set_x ( int ) ;
void disp ( ) ;
void operator -- ( );
};
void integer : : set_ s ( int a)
{
x = a.j
}
void integer : : disp ( )
{
cout << " the value of x = "<< x ;
}
void integer : : operator --( )
{
x = -x ;
}
void main ( )
{
integer I ;
I.set_x ( 10);
I.disp ( );
--I;
I.disp ( );
getch ( ); }

Street Address, City, ST ZIP Code

Office: Telephone | Website


7. What Is Inheritance And Type ?
 Yaani Agar Koi Ek Class Dusre Class Ke Propertie ko Access Kar Leta
Hai Toh Usko Ham Inheritance Kahete Hai.
 Inheritance Ke 4 Types Hai.
o Single Inheritance
o Multiple Inheritance
o Hierachical Inheritance
o Multi Level Inheritance
o Hybrid Inheritance
1. Single Inheritance

Base

Derive

2. Multiple Level Inheritance

Base

Derive 1

Derive 2

3. Multiple Inhertance

Base 1 Base 2

Derive

Street Address, City, ST ZIP Code

Office: Telephone | Website


4. Hierarical Inheritance :-

Base

Derive 1 Derive 2

5. Hybrid Inheritance

Student

Exam Project Multiple Inh..


Multi Level Inherit.

Result

Street Address, City, ST ZIP Code

Office: Telephone | Website


Sincerely,

Kalpesh Singh Rao

Street Address, City, ST ZIP Code

Office: Telephone | Website

You might also like