Facebook
From Abrupt Bee, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 58
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. class Carte{
  6.   char *titlu;
  7.   char *autor;
  8.   public:
  9.       Carte(char *titlu=NULL, char *autor=NULL);// CONSTRUCTOR CU PARAMETRII
  10.       Carte(const Carte &);// CONSTRUCTOR DE COPIERE
  11.       virtual ~Carte();// DESTRUCTOR
  12.       class Carte& operator=(const Carte&);// OPERATOR SUPRAINCARCARE EGAL
  13.       friend istream & operator >> (istream &, Carte &);//FCT PRIETENA SUPRAINCARCARE OPERATOR CITIRE
  14.       friend ostream & operator << (ostream &, Carte &);//FCT PRIETENA SUPRAINCARCARE OPERATOR SCRIERE
  15.       char* getTitlu() const{// FUNCTIE PT A PRIMI TITLU CARE ESTE PRIVAT
  16.           return titlu;
  17.       };
  18. };
  19.  
  20. istream & operator >> (istream &, Carte &x){
  21.   x.titlu = new char[200];
  22.   x.autor = new char[200];
  23.   cin.getline(x.titlu,200);
  24.   cin.getline(x.autor,200);
  25. }
  26.  
  27. ostream & operator << (ostream &st, Carte &x){
  28.   st << x.titlu << x.autor;
  29.   return st;
  30. }
  31.  
  32. Carte& Carte ::operator=(const Carte&x){
  33.   if (&x == this) return *this;
  34.   this->titlu = x.titlu;
  35.   this->autor = x.autor;
  36.   return * this;
  37. }
  38.  
  39. Carte::Carte(char *titlu, char *autor){
  40.     if(titlu!=NULL){
  41.         this->titlu = new char[strlen(titlu)+1];
  42.         strcpy(this->titlu, titlu);
  43.     }
  44.     if(autor!=NULL){
  45.         this->autor = new char[strlen(autor)+1];
  46.         strcpy(this->autor, autor);
  47.     }  
  48. }
  49.                                
  50. Carte::Carte(const Carte &c){
  51.     if(c.titlu!=NULL){
  52.         this->titlu = new char[strlen(c.titlu)+1];
  53.         strcpy(this->titlu, c.titlu);
  54.     }
  55.     if(c.autor!=NULL){
  56.         this->autor = new char[strlen(c.autor)+1];
  57.         strcpy(this->autor, c.autor);
  58.     }  
  59. }
  60.  
  61. Carte::~Carte(){
  62.     if(titlu!=NULL)
  63.         delete [] this->titlu;
  64.     if(autor!=NULL)
  65.         delete [] this->autor;
  66. }
  67.  
  68. class Persoana{
  69.   char * nume;
  70. public:
  71.       Persoana(char *nume=NULL);
  72.       Persoana(const Persoana &);
  73.       virtual ~Persoana();
  74.       class Persoana& operator=(const Persoana&);
  75.       friend istream & operator >> (istream &, Persoana &);  
  76.       friend ostream & operator << (ostream &, Persoana &);
  77.       char* scrieReview(const Carte &c){
  78.           char* x =new char[200];
  79.           sprintf(x,"Reviewul pentru cartrea %s trebuie terminat in doua saptamani",c.getTitlu());
  80.           //SPRINTF FORMATARE IN C TREBUIE AFLAT DESPRE ASTA
  81.           return x;
  82.       };
  83. };
  84.  
  85. istream & operator >> (istream &, Persoana &x){
  86.   x.nume = new char[200];
  87.   cin.getline(x.nume,200);
  88. }
  89.  
  90. ostream & operator << (ostream &st, Persoana &x){
  91.   st << x.nume;
  92.   return st;
  93. }
  94.  
  95. Persoana& Persoana ::operator=(const Persoana&x){
  96.   if (&x == this) return *this;
  97.   this->nume = x.nume;
  98.   return * this;
  99. }
  100.  
  101. Persoana::Persoana(char *nume){
  102.     if(nume!=NULL){
  103.         this->nume = new char[strlen(nume)+1];
  104.         strcpy(this->nume, nume);
  105.     }
  106. }
  107.                                
  108. Persoana::Persoana(const Persoana &c){
  109.     if(c.nume!=NULL){
  110.         this->nume = new char[strlen(c.nume)+1];
  111.         strcpy(this->nume, c.nume);
  112.     }
  113. }
  114.  
  115. Persoana::~Persoana(){
  116.     if(nume!=NULL)
  117.         delete [] this->nume;
  118. }
  119.  
  120. int main(){
  121.     Carte c;
  122.     cin >> c;
  123.     Persoana p;
  124.     cin >> p;
  125.     cout << p.scrieReview(c);
  126. }
  127.