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;
- };
- int main() {
- char *a = "Pidorass";
- COne s(89,a);
- CTwo f(69, s);
- f.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement