SlideShare a Scribd company logo
1 of 4
INTEGER AND FLOAT ADDITION USING FRIEND FUNCTION
AIM :
To create a c++ program for addition of Integer and Float using friend function.
ALGORITHM :
STEP 1 : Start the program.
STEP 2 : Declare the class friend 2.
STEP 3 : Define the class friend 1 as follows:
STEP 3.1 : Declare the data member int x and float y in private access specifier.
STEP 3.2 : Define the get() in public as follows:
STEP 3.3 : Get the values for integer x and float y.
STEP 3.4 : Declare the friend function as friend void calc (friend1 f1,friend2).
STEP 4 : Declare the class friend2 as follows:
STEP 4.1 : Declare the data member int x and float y in Private access specifier.
STEP 4.2 : Define the get() in public as follows:
STEP 4.3 : Get the values for integer x and float y.
STEP 4.4 : Declare the friend function as friend void calc(friend1 f1 , friend2 f2).
STEP 5 : Define the friend function calc(friend1 f1 , friend2 f2) as follows:
STEP 5.1 : Calculate and display the Integer Addition.
STEP 5.2 : Calculate and display the Float Addition.
STEP 6 : Define the main() as follows:
STEP 6.1 : Declare the object ‘a’ for friend1 class and object ‘b’ for friend2 class.
STEP 6.2 : Call the get() using object ‘a’ and object ‘b’.
STEP 6.3 : Call the calc (a , b) function.
STEP 7 : End the program.
PROGRAM :
//Integer And Float Addition using Friend Function.
#include<iostream>
#include<conio.h>
using namespace std;
class friend2;
class friend1
{
private:
int x;
float y;
public:
void get()
{
cout<<"Enter the value for Friend 1 :"<<"n";
cout<<"Enter the Integer value :";
cin>>x;
cout<<"Enter the Float value :";
cin>>y;
}
friend void calc(friend1 f1,friend2 f2);
};
class friend2
{
private:
int x;
float y;
public:
void get()
{
cout<<"Enter the value for Friend 2 :"<<"n";
cout<<"Enter the Integer value :";
cin>>x;
cout<<"Enter the Float value :";
cin>>y;
}
friend void calc(friend1 f1,friend2 f2);
};
void calc(friend1 f1,friend2 f2)
{
cout<<"The Addition of Friend 1 and Friend 2 :"<<"n";
cout<<"The Integer Addition is :"<<f1.x+f2.x<<"n";
cout<<"The Float Addition is :"<<f1.y+f2.y<<"n";
}
int main()
{
friend1 a;
friend2 b;
a.get();
b.get();
calc(a,b);
}
OUTPUT :
Enter the value for Friend 1 :
Enter the Integer value :25
Enter the Float value :68.2
Enter the value for Friend 2 :
Enter the Integer value :78
Enter the Float value :90.5
The Addition of Friend 1 and Friend 2 :
The Integer Addition is :103
The Float Addition is :158.7

More Related Content

Similar to Friend function by sathya.docx

Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objectsRai University
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfstudy material
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classesasadsardar
 
Introduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutletIntroduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutletOldingz
 
Friend function
Friend functionFriend function
Friend functionzindadili
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsRup Chowdhury
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 QuizzesSteven Luo
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSESujata Regoti
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual finalAhalyaR
 

Similar to Friend function by sathya.docx (20)

Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdf
 
Xiicsmonth
XiicsmonthXiicsmonth
Xiicsmonth
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classes
 
DS Unit 6.ppt
DS Unit 6.pptDS Unit 6.ppt
DS Unit 6.ppt
 
Introduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutletIntroduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutlet
 
Pointers
PointersPointers
Pointers
 
Inheritance
InheritanceInheritance
Inheritance
 
Friend function
Friend functionFriend function
Friend function
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
 
Lecture07
Lecture07Lecture07
Lecture07
 
OOPS 22-23 (1).pptx
OOPS 22-23 (1).pptxOOPS 22-23 (1).pptx
OOPS 22-23 (1).pptx
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer Graphics
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 Quizzes
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSE
 
cse l 5.pptx
cse l 5.pptxcse l 5.pptx
cse l 5.pptx
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 

More from SATHYAKALAKSKPRCASBS (8)

java completed units.docx
java completed units.docxjava completed units.docx
java completed units.docx
 
java full 1 (Recovered).docx
java full 1 (Recovered).docxjava full 1 (Recovered).docx
java full 1 (Recovered).docx
 
java full.docx
java full.docxjava full.docx
java full.docx
 
java full 1.docx
java full 1.docxjava full 1.docx
java full 1.docx
 
Personal Information.docx
Personal Information.docxPersonal Information.docx
Personal Information.docx
 
Presentation1.pdf
Presentation1.pdfPresentation1.pdf
Presentation1.pdf
 
hjdh.docx
hjdh.docxhjdh.docx
hjdh.docx
 
Contact Information.docx
Contact Information.docxContact Information.docx
Contact Information.docx
 

Recently uploaded

CROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NSCROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NSpanmisemningshen123
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1kcpayne
 
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...pujan9679
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwaitdaisycvs
 
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTSDurg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTSkajalroy875762
 
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTSJAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTSkajalroy875762
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfAdmir Softic
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Falcon Invoice Discounting
 
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...pujan9679
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...daisycvs
 
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGParadip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting
 
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book nowGUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book nowkapoorjyoti4444
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentationuneakwhite
 
New 2024 Cannabis Edibles Investor Pitch Deck Template
New 2024 Cannabis Edibles Investor Pitch Deck TemplateNew 2024 Cannabis Edibles Investor Pitch Deck Template
New 2024 Cannabis Edibles Investor Pitch Deck TemplateCannaBusinessPlans
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecJual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecZurliaSoop
 

Recently uploaded (20)

CROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NSCROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NS
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
Buy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail AccountsBuy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail Accounts
 
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTSDurg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
 
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTSJAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
 
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGParadip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book nowGUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
New 2024 Cannabis Edibles Investor Pitch Deck Template
New 2024 Cannabis Edibles Investor Pitch Deck TemplateNew 2024 Cannabis Edibles Investor Pitch Deck Template
New 2024 Cannabis Edibles Investor Pitch Deck Template
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecJual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
 

Friend function by sathya.docx

  • 1. INTEGER AND FLOAT ADDITION USING FRIEND FUNCTION AIM : To create a c++ program for addition of Integer and Float using friend function. ALGORITHM : STEP 1 : Start the program. STEP 2 : Declare the class friend 2. STEP 3 : Define the class friend 1 as follows: STEP 3.1 : Declare the data member int x and float y in private access specifier. STEP 3.2 : Define the get() in public as follows: STEP 3.3 : Get the values for integer x and float y. STEP 3.4 : Declare the friend function as friend void calc (friend1 f1,friend2). STEP 4 : Declare the class friend2 as follows: STEP 4.1 : Declare the data member int x and float y in Private access specifier. STEP 4.2 : Define the get() in public as follows: STEP 4.3 : Get the values for integer x and float y. STEP 4.4 : Declare the friend function as friend void calc(friend1 f1 , friend2 f2). STEP 5 : Define the friend function calc(friend1 f1 , friend2 f2) as follows: STEP 5.1 : Calculate and display the Integer Addition. STEP 5.2 : Calculate and display the Float Addition. STEP 6 : Define the main() as follows: STEP 6.1 : Declare the object ‘a’ for friend1 class and object ‘b’ for friend2 class. STEP 6.2 : Call the get() using object ‘a’ and object ‘b’. STEP 6.3 : Call the calc (a , b) function. STEP 7 : End the program.
  • 2. PROGRAM : //Integer And Float Addition using Friend Function. #include<iostream> #include<conio.h> using namespace std; class friend2; class friend1 { private: int x; float y; public: void get() { cout<<"Enter the value for Friend 1 :"<<"n"; cout<<"Enter the Integer value :"; cin>>x; cout<<"Enter the Float value :"; cin>>y; } friend void calc(friend1 f1,friend2 f2); }; class friend2 {
  • 3. private: int x; float y; public: void get() { cout<<"Enter the value for Friend 2 :"<<"n"; cout<<"Enter the Integer value :"; cin>>x; cout<<"Enter the Float value :"; cin>>y; } friend void calc(friend1 f1,friend2 f2); }; void calc(friend1 f1,friend2 f2) { cout<<"The Addition of Friend 1 and Friend 2 :"<<"n"; cout<<"The Integer Addition is :"<<f1.x+f2.x<<"n"; cout<<"The Float Addition is :"<<f1.y+f2.y<<"n"; } int main() { friend1 a; friend2 b;
  • 4. a.get(); b.get(); calc(a,b); } OUTPUT : Enter the value for Friend 1 : Enter the Integer value :25 Enter the Float value :68.2 Enter the value for Friend 2 : Enter the Integer value :78 Enter the Float value :90.5 The Addition of Friend 1 and Friend 2 : The Integer Addition is :103 The Float Addition is :158.7