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

Henry's law constant for CO 2 ​ in water is 1.67×10 ∘ Pa at 298 K . Calculate the quantity of CO 2 ​ in 500 mL , of soda water when packed under 2.5 atm CO 2 ​ pressure at 298 K .

  Explanation To calculate the amount of CO 2 ​ dissolved, we use Henry's Law: P = k H ​ × x _ C O 2 ​ where:\ P = partial pressure of...