Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Teatime Snack
//g++ 7.4.0 //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> #include <string> using namespace std; class Snack;//Snack will declare a friend class so this solitary line is needed. class Teatime{ int price, plate; public: int cost() { return (price *plate); } void get(Snack a); }; class Snack{ friend class Teatime;//class Teatime is declared a friend to class Snack; so Teatime members have access to Snack class members; not the other way as Teatime did not treat class Snack as friend. private: int price, qty; public: Snack (int p, int q) : price (p), qty(q) {} }; void Teatime::get(Snack a) { price = a.price; plate= a.qty; } int main() { Teatime tt; Snack s(5,4); tt.get(s); cout <<"Tea time snack costs Tk "<<tt.cost()<<endl; return 0; }
run
|
edit
|
history
|
help
0
Exempel 2
break.cpp
CPP - Pointers - Ex.3
map sort
Good pairs
ExtremeValues
2
subset sum=k(Recursion)
code
D. Traveling Graph