Professional Documents
Culture Documents
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
class Sir
{
char *s;
public:
Sir();
Sir(const char*);
Sir(const Sir&);
~Sir();
protected:
strcpy(s, X);
}
}
};
public:
Siruri()
{
s2 = NULL;
}
Siruri(const char* X)
{
s2 = NULL;
if (X)
{
s2 = new char[strlen(X) + 1];
if (!s2)
throw("BAD MEMORY ALLOCATION");
strcpy(s2, X);
}
~Siruri()
{
if (s2)
delete[] s2;
}
};
----
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstring>
#include "Sir.h"
using namespace std;
Sir::Sir()
{
s = NULL;
}
Sir::Sir(const char* X)
{
s = NULL;
if (X)
{
s = new char[strlen(X) + 1];
if (!s)
throw("BAD MEMORY ALLOCATION");
strcpy(s, X);
}
}
Sir::Sir(const Sir& X)
{
s = NULL;
if (X.s)
{
s = new char[strlen(X.s) + 1];
if (!s)
throw("BAD MEMORY ALLOCATION");
strcpy(s, X.s);
}
}
//s = NULL;
if (TD.s)
{
this->s = new char[strlen(TD.s) + 1];
if (!s)
throw("BAD MEMORY ALLOCATION");
strcpy(s, TD.s);
}
}
return *this;
}
//s = NULL;
if (td)
{
this->s = new char[strlen(td) + 1];
if (!s)
throw("BAD MEMORY ALLOCATION");
strcpy(s, td);
}
}
return *this;
}
if (s)
l1 = strlen(s);
if (TD.s)
l2 = strlen(TD.s);
if (l1 + l2)
{
rezultat = new char[l1 + l2 + 1];
if (!rezultat)
throw("BAD MEMORY ALLOCATION");
strcpy(rezultat, "");
if (s)
strcat(rezultat, s);
if (TD.s)
strcat(rezultat, TD.s);
}
return rezultat;
if (s)
l1 = strlen(s);
if (TD)
l2 = strlen(TD);
if (l1 + l2)
{
rezultat = new char[l1 + l2 + 1];
if (!rezultat)
throw("BAD MEMORY ALLOCATION");
strcpy(rezultat, "");
if (s)
strcat(rezultat, s);
if (TD)
strcat(rezultat, TD);
}
return rezultat;
}
Sir& Sir::operator+=(const Sir& TD)
{
char *rezultat = NULL;
int l1 = 0;
int l2 = 0;
if (s)
l1 = strlen(s);
if (TD.s)
l2 = strlen(TD.s);
if (l1 + l2)
{
rezultat = new char[l1 + l2 + 1];
if (!rezultat)
throw("BAD MEMORY ALLOCATION");
strcpy(rezultat, "");
if (s)
strcat(rezultat, s);
if (TD.s)
strcat(rezultat, TD.s);
}
s = rezultat;
return *this;
}
return os;
}
Sir::~Sir()
{
if (s)
delete[] s;
}
----
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include "Sir.h"
using namespace std;
int main()
{
Sir A("Azi "), B(A),C(" soare "),D;
A = A + "e minunat";
B = " si e";
B += C;
D = A + B;
cout << D;
Siruri AUX("iarba","apa");
AUX.Afisare();
cout << endl;
system("pause");
return 0;
}