Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Friend function implementation
- */
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class Metre;
- class Centimetre{
- double length;
- public:
- inline Centimetre();
- inline Centimetre(double);
- inline ~Centimetre();
- inline void input();
- inline friend void compare(Centimetre&, Metre&);
- };
- class Metre{
- double length;
- public:
- inline Metre();
- inline Metre(double);
- inline ~Metre();
- inline void input();
- friend void compare(Centimetre&, Metre&);
- };
- void compare(Centimetre &c_obj, Metre & m_obj){
- if(c_obj.length > (m_obj.length * 100)){
- cout << c_obj.length << " cm is greater\n";
- }
- else {
- cout << m_obj.length << " m is greater\n";
- }
- }
- Metre::Metre(){
- length = 0.0;
- }
- Centimetre::Centimetre(){
- length = 0.0;
- }
- Centimetre::Centimetre(double length){
- Centimetre::length = length;
- }
- Centimetre::~Centimetre(){
- cout << "Centimetre object is destroyed!" << endl;
- }
- Metre::Metre(double length){
- Metre::length = length;
- }
- Metre::~Metre(){
- cout << "Metre object is destroyed!" << endl;
- }
- void Centimetre::input(){
- cout << "Enter the length in cm: ";
- cin >> length;
- }
- void Metre::input(){
- cout << "Enter the length in m: ";
- cin >> length;
- }
- int main() {
- system("cls");
- Centimetre c_obj;
- Metre m_obj;
- c_obj.input();
- m_obj.input();
- compare(c_obj, m_obj);
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment