Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class cOne {
- public:
- cOne() : d(0) {}
- cOne(double d, string s) : d(d), s(s) {}
- cOne(cOne const &a) : d(a.d), s(a.s) {}
- cOne &operator=(cOne const &a) {
- d = a.d;
- s = a.s;
- return *this;
- }
- void print() {
- cout<<"class cOne\n";
- cout << "d = " << d << '\n';
- cout << "s = " << s << '\n';
- cout << "-----------------------\n";
- }
- double getD() const {
- return d;
- }
- void setD(double _d) {
- d = _d;
- }
- const string &getS() const {
- return s;
- }
- void setS(const string &_s) {
- s = _s;
- }
- ~cOne() {}
- private:
- double d;
- string s;
- };
- class cTwo {
- public:
- cTwo() : l(0), obj(cOne()) {}
- cTwo(long l, const cOne &obj) : l(l), obj(obj) {}
- cTwo(cTwo const &a) : l(a.l), obj(a.obj) {}
- long getL() const {
- return l;
- }
- void setL(long _l) {
- l = _l;
- }
- const cOne &getObj() const {
- return obj;
- }
- void setObj(const cOne &_obj) {
- obj = _obj;
- }
- cTwo &operator=(cTwo const &a) {
- l = a.l;
- obj = a.obj;
- return *this;
- }
- void print() {
- cout<<"class cTwo\n";
- cout << "l = " << l << '\n';
- cout << "-----------------------\n";
- obj.print();
- }
- ~cTwo(){}
- private:
- long l;
- cOne obj;
- };
- int main() {
- cOne a(3.14, "PI");
- a.print();
- cOne b(2.71, "E");
- b.print();
- a=b;
- a.print();
- cout<<"\nСоздаем класс cTwo\n";
- cTwo c(123, a);
- c.print();
- cout<<"\nПроверяем методы доступа\n";
- c.setL(-666);
- c.setObj(b);
- c.print();
- cTwo d(88888, b);
- c=d;
- c.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement