Using friend function find the maximum number from given two numbers from two different classes. Write all necessary functions and constructors for the program.
#include <iostream.h> #include <conio.h> class Student; class Teacher { private: int salary; public: void setData(int y) { salary=y; } void getData() { cout<<"Salary "<<salary<<endl; } friend int maximum(Teacher , Student) }; class Student { private: int saving; public: void setData(int x ) { saving=x; } void getData() { cout<<"Savings "<<saving<<endl; } friend int maximum(Teacher t, Student s); }; int maximum(Teacher t, Student s) { if (t.salary > s.saving) { return t.salary; } else { return s.saving; } } void main() { clrscr(); Student s1; s1.setData(4000); s1.getData(); Teacher t1; t1.setData(5000); t1.getData(); int max =0; max=maximum(t1,s1); d cout<< "Maximum "<< max <<endl; getch(); }
Using friend function find the maximum number from given two numbers from two different classes CPP