-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFriend function.cpp
More file actions
47 lines (45 loc) · 1.13 KB
/
Copy pathFriend function.cpp
File metadata and controls
47 lines (45 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
using namespace std;
class home{
private:
int choco;
int pastries;
int jelly;
public:
home() //default constructor
{
choco=0;
pastries=0;
jelly=0;
}
void setvalues(int c,int p,int j) //member function of a class
{
choco=c;
pastries=p;
jelly=j;
}
void show() //member function of a class
{
cout<<"Fridge quantities write now: "<<endl;
cout<<"Chocolates: "<<choco<<endl;
cout<<"Pastries: "<<pastries<<endl;
cout<<"Jellies: "<<jelly<<endl;
}
friend void eating(home); //eating function is now friend of class home i.e declaration
};
void eating(home o) //this function is not member function of class i.e defination
{
cout<<"B has came to eat chocolates, pastries and jellies:"<<endl;
cout<<"B eat:"<<endl;
cout<<"Chocolates: "<<o.choco<<endl;
cout<<"Pastries: "<<o.pastries<<endl;
cout<<"Jellies: "<<o.jelly<<endl;
}
int main()
{
home A; //creation of object
A.setvalues(5,10,20);
// A.show();
eating(A);
return 0;
}