Answer to Question #274614 in C++ for Amit

Question #274614

Write a program using friend function to swap the private data of two classes assuming each class to contain one private integer data member and associated member functions for inputting and displaying the data.

 



1
Expert's answer
2021-12-02T14:15:51-0500
#include <iostream>
using namespace std;

class Swap {

    int temp, a, b;

public:
    Swap(int a, int b)
    {
        this->a = a;
        this->b = b;
    }

    friend void swap(Swap&);
};


void swap(Swap& s1)
{
    s1.temp = s1.a;
    s1.a = s1.b;
    s1.b = s1.temp;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment