Sunday, February 25, 2018

C++ : Private Properties

#include <iostream>
using namespace std;
class M {
protected:
    int m;
public:
   void set_m(int x) { m = x; };
};
class N {
protected:
    int n;
public:
    void set_n(int y) { n = y; };
};
class P : public M, public N {
public:
    void display() { cout << m * n << endl; };
};

int main(){
    int a, b;
    cin >> a >> b;
    P p;



p.M::set_m(a);
p.N::set_n(b);
p.display ();
    return 0;
}  // End of main()

Thanks
Happy Computing !

No comments:

Post a Comment

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows