Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<iostream>
- #include<string.h>
- using namespace std;
- class Carte
- {
- protected:
- char* nume;
- char *titlu;
- char* editura;
- int pagini;
- public:
- Carte()
- {
- this->nume = NULL;
- titlu = NULL;
- editura = NULL;
- pagini = 0;
- }
- Carte(char *nume, char *titlu, char *editura, int pagini)
- {
- this->nume = new char[strlen(nume) + 1];
- strcpy(this->nume, nume);
- this->titlu = new char[strlen(titlu) + 1];
- strcpy(this->titlu, titlu);
- this->editura = new char[strlen(editura) + 1];
- strcpy(this->editura, editura);
- this->pagini = pagini;
- }
- Carte(const Carte& copi)
- {
- nume = new char[strlen(copi.nume) + 1];
- nume = copi.nume;
- titlu = new char[strlen(copi.titlu) + 1];
- editura = new char[strlen(copi.editura) + 1];
- titlu = copi.titlu;
- editura = copi.editura;
- pagini = copi.pagini;
- }
- ~Carte()
- {
- delete[]nume;
- delete[] titlu;
- delete[] editura;
- }
- Carte operator=(const Carte& ion)
- {
- delete[] nume;
- delete[] editura;
- delete[] titlu;
- pagini = 0;
- nume = new char[strlen(ion.nume) + 1];
- nume = ion.nume;
- titlu = new char[strlen(ion.titlu) + 1];
- editura = new char[strlen(ion.editura) + 1];
- titlu = ion.titlu;
- editura = ion.editura;
- pagini = ion.pagini;
- return *this;
- }
- void afis()
- {
- cout << nume << " " << titlu << " " << editura << endl;
- cout << pagini << endl;
- }
- /* int operator==(const Carte& ion) const
- {
- if ((this->pagini != ion.pagini) || (strlen(this->nume) != strlen(ion.nume)) || ((strlen(this->titlu) != strlen(ion.titlu))) || (strlen(this->editura) != strlen(ion.editura)))
- return 0;
- if (strcmp(this->nume, ion.nume)==0)
- return 0;
- if (strcmp(this->editura, ion.editura) == 0)
- return 0;
- if (strcmp(this->titlu, ion.titlu) == 0)
- return 0;
- return 1;
- }
- */
- friend ostream& operator<<(ostream& out, Carte ion);
- };
- ostream& operator<<(ostream& out, Carte ion)
- {
- out << ion.nume << ion.editura << ion.titlu << ion.pagini << endl;
- return out;
- }
- int main() {
- Carte abd("abcd", "iaiad", "asasa", 1000);
- Carte x;
- x = abd;
- x.afis();
- // if (x == abd)
- // cout << "sunt egale";
- //else
- //cout << "nu sunt egale";
- /*char a[10],b[10];
- cin >> a >> b;
- if (strcmp(a, b) == 1)
- cout << "egL";
- */
- //cout << abd;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement