Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class COne {
- public:
- COne()
- : f(0), ps(0) {
- }
- COne(float _f, char *_ps)
- : f(_f) {
- ps = new char[strlen(_ps)];
- strcpy(ps, _ps);
- }
- COne(const COne &Q)
- : f(Q.f) {
- ps = new char[strlen(Q.ps)];
- strcpy(ps, Q.ps);
- }
- float getF() const { //getter setter
- return f;
- }
- void setF(float f) {
- COne::f = f;
- }
- char *getPs() const {
- return ps;
- }
- void setPs(char *_ps) {
- ps = new char[strlen(_ps)];
- strcpy(ps, _ps);
- }
- // возвращает ссылку на СОne
- // принимает константную ссылку на Q
- COne &operator=(COne const &Q) { //перегрузка
- delete ps;
- ps = new char[strlen(Q.ps)];
- strcpy(ps, Q.ps);
- f = Q.f;
- }
- void print() {
- cout << "----------------\n";
- cout << "Class COne\n";
- cout << "f = " << f << endl;
- printf("ps = %s\n", ps);
- }
- ~COne() { //деструктор
- delete ps;
- }
- private:
- float f;
- char *ps;
- };
- class CTwo {
- public:
- CTwo()
- : l(-2), obj(COne()) {
- }
- CTwo(long _l, COne f)
- : l(_l), obj(f) {
- }
- CTwo(const CTwo &m)
- : l(m.l), obj(m.obj) {
- }
- long getL() const {
- return l;
- }
- void setL(long l) {
- CTwo::l = l;
- }
- const COne &getObj() const {
- return obj;
- }
- void setObj(const COne &obj) {
- CTwo::obj = obj;
- }
- CTwo &operator=(CTwo const &ctwo) {
- l = ctwo.l;
- obj = ctwo.obj;
- }
- void print() {
- cout << "----------------\n";
- cout << "Class CTwo\n";
- cout << "l = " << l << endl;
- obj.print();
- }
- ~CTwo() {}
- private:
- long l;
- COne obj;
- };
- class CThree : CTwo {
- public:
- CThree()
- : ad(69) {
- }
- CThree(int _ad, CTwo & cTwo)
- : ad(_ad), CTwo(cTwo) {
- }
- CThree(const CThree & cthree)
- :ad(cthree.ad), CTwo(cthree)
- {
- }
- int getAd() const {
- return ad;
- }
- void setAd(int ad) {
- CThree::ad = ad;
- }
- void print(){
- cout << "----------------\n";
- cout << "Class CThree\n";
- cout << "ad = " << ad << endl;
- CTwo::print();
- }
- ~CThree(){}
- private:
- int ad;
- };
- int main() {
- char *a = "Pidorass";
- COne s(89, a);
- CTwo f(69, s);
- CThree v(228, f);
- v.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement