SlideShare a Scribd company logo
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

DOC
Pads lab manual final
PPTX
New presentation oop
PDF
C++ manual Report Full
PPTX
Data types
PDF
Friend Function Computer Programming.pdf
PPTX
More on Classes and Objects
DOCX
Pratik Bakane C++
DOCX
A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA
Pads lab manual final
New presentation oop
C++ manual Report Full
Data types
Friend Function Computer Programming.pdf
More on Classes and Objects
Pratik Bakane C++
A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA

Similar to Friend function by sathya.docx (20)

PDF
Friend function Getting Larget value using Friend function ----.pdf
PDF
Ch 4
PPTX
cse l 5.pptx
DOC
Cs2312 OOPS LAB MANUAL
PPTX
2.6 Friend Function which helps to learn how the friend function works
PPTX
L9_Friend Function.pptxyeyeyeyeyyeyeyeye
PPT
Datatypes
PPT
Lecture5
PPTX
class and objects
PPTX
Study of Friend Function in C++ with examples
PDF
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
PDF
C++ prgms 3rd unit
PPTX
424570636-friend-function-1-pptx.hiipptx
PPTX
Friend function
PDF
Friend function in c++
PDF
Implementation of oop concept in c++
PPTX
friend_derivedclasspresentation1234.pptx
PPT
OBJECTS IN Object Oriented Programming .ppt
PPTX
Friend Function
Friend function Getting Larget value using Friend function ----.pdf
Ch 4
cse l 5.pptx
Cs2312 OOPS LAB MANUAL
2.6 Friend Function which helps to learn how the friend function works
L9_Friend Function.pptxyeyeyeyeyyeyeyeye
Datatypes
Lecture5
class and objects
Study of Friend Function in C++ with examples
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
C++ prgms 3rd unit
424570636-friend-function-1-pptx.hiipptx
Friend function
Friend function in c++
Implementation of oop concept in c++
friend_derivedclasspresentation1234.pptx
OBJECTS IN Object Oriented Programming .ppt
Friend Function
Ad

More from SATHYAKALAKSKPRCASBS (8)

DOCX
java completed units.docx
DOCX
java full 1 (Recovered).docx
DOCX
java full.docx
DOCX
java full 1.docx
DOCX
Personal Information.docx
PDF
Presentation1.pdf
DOCX
DOCX
Contact Information.docx
java completed units.docx
java full 1 (Recovered).docx
java full.docx
java full 1.docx
Personal Information.docx
Presentation1.pdf
Contact Information.docx
Ad

Recently uploaded (20)

PDF
THE COMPLETE GUIDE TO BUILDING PASSIVE INCOME ONLINE
PDF
Building a Smart Pet Ecosystem: A Full Introduction to Zhejiang Beijing Techn...
PPTX
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
PPTX
svnfcksanfskjcsnvvjknsnvsdscnsncxasxa saccacxsax
PDF
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
PPT
Lecture 3344;;,,(,(((((((((((((((((((((((
PDF
Nante Industrial Plug Factory: Engineering Quality for Modern Power Applications
PDF
Digital Marketing & E-commerce Certificate Glossary.pdf.................
PDF
ANALYZING THE OPPORTUNITIES OF DIGITAL MARKETING IN BANGLADESH TO PROVIDE AN ...
PPTX
Slide gioi thieu VietinBank Quy 2 - 2025
PDF
Tata consultancy services case study shri Sharda college, basrur
PPTX
2025 Product Deck V1.0.pptxCATALOGTCLCIA
PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
PPTX
3. HISTORICAL PERSPECTIVE UNIIT 3^..pptx
PDF
How to Get Business Funding for Small Business Fast
PDF
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
PDF
Charisse Litchman: A Maverick Making Neurological Care More Accessible
PPTX
Principles of Marketing, Industrial, Consumers,
PPTX
Astra-Investor- business Presentation (1).pptx
PDF
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi
THE COMPLETE GUIDE TO BUILDING PASSIVE INCOME ONLINE
Building a Smart Pet Ecosystem: A Full Introduction to Zhejiang Beijing Techn...
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
svnfcksanfskjcsnvvjknsnvsdscnsncxasxa saccacxsax
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
Lecture 3344;;,,(,(((((((((((((((((((((((
Nante Industrial Plug Factory: Engineering Quality for Modern Power Applications
Digital Marketing & E-commerce Certificate Glossary.pdf.................
ANALYZING THE OPPORTUNITIES OF DIGITAL MARKETING IN BANGLADESH TO PROVIDE AN ...
Slide gioi thieu VietinBank Quy 2 - 2025
Tata consultancy services case study shri Sharda college, basrur
2025 Product Deck V1.0.pptxCATALOGTCLCIA
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
3. HISTORICAL PERSPECTIVE UNIIT 3^..pptx
How to Get Business Funding for Small Business Fast
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
Charisse Litchman: A Maverick Making Neurological Care More Accessible
Principles of Marketing, Industrial, Consumers,
Astra-Investor- business Presentation (1).pptx
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi

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