SlideShare a Scribd company logo
Friend Function

#include<iostream.h>
class Square;
class Rectangle{
private:
     int width, height;
public:
     Rectangle(int x, int y){
          width=x;
          height=y;
     };
     friend void equal(Rectangle a, Square b);
};
class Square{
private:
     int r;
public:
     Square(int x){
          r=x;
     };
     friend void equal(Rectangle a, Square b);
};
void equal(Rectangle a, Square b){
     if (a.width*a.height==b.r*b.r)
          cout << "Equal" << endl;
     else
          cout << "Unequal" << endl;
}
void main(void){
     Rectangle a1(20,5);
     Square b1(10);
     equal(a1, b1);
     Rectangle a2(20,10);
     Square b2(9);
     equal(a2, b2);
}

More Related Content

PDF
Bcsl 033 data and file structures lab s4-2
PDF
201801 CSE240 Lecture 09
PDF
Bcsl 033 data and file structures lab s2-3
PDF
Bcsl 033 data and file structures lab s3-1
PDF
Bcsl 033 data and file structures lab s3-3
PPTX
LAB PROGRAMS SARASWATHI RAMALINGAM
PDF
Bcsl 033 data and file structures lab s2-1
PDF
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s4-2
201801 CSE240 Lecture 09
Bcsl 033 data and file structures lab s2-3
Bcsl 033 data and file structures lab s3-1
Bcsl 033 data and file structures lab s3-3
LAB PROGRAMS SARASWATHI RAMALINGAM
Bcsl 033 data and file structures lab s2-1
Bcsl 033 data and file structures lab s2-2

What's hot (20)

PDF
SATySFiのこれからの課題たち
PDF
Program in ‘C’ language to implement linear search using pointers
PPTX
Hybrid Inheritance in C++
DOCX
Spiral array
PPTX
PDF
Bcsl 033 data and file structures lab s5-3
PDF
Bcsl 033 data and file structures lab s3-2
PPTX
Graph and tree
PPT
Clojure lang
PDF
Implement a queue using two stacks.
PDF
Day 3 examples
PDF
11 library
PPTX
An introduction to matlab
DOCX
Maple Code for Steepest Descent
PDF
201801 CSE240 Lecture 14
PDF
Lec14-CS110 Computational Engineering
PDF
Let us c chapter 4 solution
SATySFiのこれからの課題たち
Program in ‘C’ language to implement linear search using pointers
Hybrid Inheritance in C++
Spiral array
Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s3-2
Graph and tree
Clojure lang
Implement a queue using two stacks.
Day 3 examples
11 library
An introduction to matlab
Maple Code for Steepest Descent
201801 CSE240 Lecture 14
Lec14-CS110 Computational Engineering
Let us c chapter 4 solution
Ad

Viewers also liked (18)

PPT
19442165 teoria-das-cores
PPTX
Apresentação ceramica
DOCX
12 anvisa-considerações e definições para pesquisa clínica
PPT
Tipos de datos en c++
PDF
Magnesita apresentacao confcall_2_t11_pt
PPT
Estrutura Atómica
PPTX
Guia de importaçao na healthdesigns definitivo
PDF
Atelier: o que é? [versão curta]
PDF
A exuberância da estampa étnica
PPTX
E28LL06
PDF
Social media IOR: las relaciones como moneda de rentabilidad
ODP
Hot wheels
PDF
NOVA reports
PPS
Notasde portugal
DOC
Sistemas fundamentales del ser humano
PPT
Yusveivi tumbaco l.
PDF
Recruitment brochure-FINAL PDF
PPTX
PRESENTACION 3
19442165 teoria-das-cores
Apresentação ceramica
12 anvisa-considerações e definições para pesquisa clínica
Tipos de datos en c++
Magnesita apresentacao confcall_2_t11_pt
Estrutura Atómica
Guia de importaçao na healthdesigns definitivo
Atelier: o que é? [versão curta]
A exuberância da estampa étnica
E28LL06
Social media IOR: las relaciones como moneda de rentabilidad
Hot wheels
NOVA reports
Notasde portugal
Sistemas fundamentales del ser humano
Yusveivi tumbaco l.
Recruitment brochure-FINAL PDF
PRESENTACION 3
Ad

More from Hui-Shih Leng (11)

DOCX
00555 0 ccet0001020
DOCX
Imresize
DOCX
DOCX
Wire shark http報告
DOCX
質數的判斷
DOC
如何備份物件導向專題
DOCX
[程式設計]標準差
DOCX
[程式設計]Blackfriday
DOCX
如何建立Blog中的程式教學檔案
DOCX
[程式設計]判斷閏年
DOC
物件導向程式設計課程講義(98 ges hi版)
00555 0 ccet0001020
Imresize
Wire shark http報告
質數的判斷
如何備份物件導向專題
[程式設計]標準差
[程式設計]Blackfriday
如何建立Blog中的程式教學檔案
[程式設計]判斷閏年
物件導向程式設計課程講義(98 ges hi版)

Recently uploaded (20)

PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Updated Idioms and Phrasal Verbs in English subject
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Structure & Organelles in detailed.
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Lesson notes of climatology university.
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Cell Types and Its function , kingdom of life
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
Trump Administration's workforce development strategy
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
What if we spent less time fighting change, and more time building what’s rig...
Orientation - ARALprogram of Deped to the Parents.pptx
Weekly quiz Compilation Jan -July 25.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Practical Manual AGRO-233 Principles and Practices of Natural Farming
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Updated Idioms and Phrasal Verbs in English subject
Computing-Curriculum for Schools in Ghana
Cell Structure & Organelles in detailed.
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Lesson notes of climatology university.
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Cell Types and Its function , kingdom of life
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Trump Administration's workforce development strategy
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
What if we spent less time fighting change, and more time building what’s rig...

Friend function

  • 1. Friend Function #include<iostream.h> class Square; class Rectangle{ private: int width, height; public: Rectangle(int x, int y){ width=x; height=y; }; friend void equal(Rectangle a, Square b); }; class Square{ private: int r; public: Square(int x){ r=x; }; friend void equal(Rectangle a, Square b); }; void equal(Rectangle a, Square b){ if (a.width*a.height==b.r*b.r) cout << "Equal" << endl; else cout << "Unequal" << endl; } void main(void){ Rectangle a1(20,5); Square b1(10); equal(a1, b1); Rectangle a2(20,10); Square b2(9); equal(a2, b2);
  • 2. }