G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 10th, 2020 191 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdlib.h> ///permite executia functiei system(...)
  3. #include <cstdlib>
  4. #include <vector>
  5. using namespace std;
  6. class Persoana
  7. {
  8. protected: ///membri protected pentru ca facem mostenire
  9.     int id;
  10.     string nume;
  11.     static int n; ///Variabila statica folosita pentru a numara cate persoane avem declarate.
  12. public:
  13.     Persoana (int id, string nume);
  14.     Persoana(Persoana &p);
  15.  
  16.     virtual ~Persoana(); ///destructor virtual
  17.     virtual void citire(istream &in);
  18.     virtual void afisare(ostream &out);
  19.     friend istream& operator>>(istream&, Persoana&);
  20.     friend ostream& operator<<(ostream&, Persoana&);
  21.     static void numarObiecte()  /// metoda statica de afisare a numarului de obiecte
  22.     {
  23.         cout<<n;
  24.     }
  25.     string get_nume()
  26.     {
  27.         return nume;
  28.     }
  29.     int get_id()
  30.     {
  31.         return id;
  32.     }
  33. };
  34.  
  35.  
  36. Persoana::Persoana(int x,string z="")
  37. {
  38.     id=x;
  39.     nume=z;
  40. }
  41. Persoana::Persoana(Persoana &p)
  42. {
  43.     this->id = p.id;
  44.     this->nume = p.nume;
  45. }
  46. Persoana::~Persoana()
  47. {
  48.  
  49. }
  50. void Persoana::citire(istream &in)
  51. {
  52.     int x;
  53.     cout<<"ID:";
  54.     in>>x;
  55.     id=x;
  56.     cout<<"Nume:";
  57.     in.get();
  58.     string z;
  59.     getline(in,z); ///citire string pana la enter (permite sa avem spatii)
  60.     nume=z;
  61. }
  62. void Persoana::afisare(ostream &out)
  63. {
  64.     out<<"ID: "<<id<<"\n";
  65.     out<<"Nume: "<<nume<<"\n";
  66. }
  67. istream& operator>>(istream& in,Persoana& p)
  68. {
  69.     p.citire(in);
  70.     return in;
  71. }
  72.  
  73. ostream& operator<<(ostream& out, Persoana& p)
  74. {
  75.     p.afisare(out);
  76.     return out;
  77. }
  78. ///----------------------------------------------------------------------------
  79. class Abonat:public Persoana
  80. {
  81. protected: ///protected pentru ca mai derivam o data
  82.     string nr_telefon;
  83. public:
  84.     Abonat(int, string, string);
  85.     ~Abonat(); ///dupa cate observati nu este nevoie sa avem virtual in derivata (doar daca e cazul)
  86.  
  87.     virtual void citire(istream &in);
  88.     virtual void afisare(ostream &out);
  89.  
  90.     friend istream& operator>>(istream&, Abonat&);
  91.     friend ostream& operator<<(ostream&, Abonat&);
  92.  
  93. };
  94. Abonat::Abonat(int x,string z = " ", string nr=""):Persoana(x,z)   ///apelam constructorul din baza
  95. {
  96.     nr_telefon=nr; ///adaugam ce e de adaugat
  97. }
  98. Abonat::~Abonat()
  99. {
  100. }
  101. void Abonat::citire(istream &in)
  102. {
  103.     Persoana::citire(in);
  104.     cout<<"Dati nr de telefon: ";
  105.     in>>nr_telefon;
  106. }
  107. void Abonat::afisare(ostream &out)
  108. {
  109.     Persoana::afisare(out);
  110.     out<<"Numar telefon: ";
  111.     out<<nr_telefon<<"\n";
  112. }
  113. istream& operator>>(istream& in,Abonat& p)
  114. {
  115.     p.citire(in);
  116.     return in;
  117. }
  118.  
  119. ostream& operator<<(ostream& out, Abonat& p)
  120. {
  121.     p.afisare(out);
  122.     return out;
  123. }
  124.  
  125. ///-----------------------------------------------------------------------
  126. class Abonat_Skype:public Abonat
  127. {
  128.     ///aici avem membri privati
  129.     string id_skype;
  130. public:
  131.     Abonat_Skype(int, string, string, string);
  132.     ~Abonat_Skype();
  133.  
  134.     void citire(istream &in);
  135.     void afisare(ostream &out);
  136.  
  137.     friend istream& operator>>(istream&, Abonat_Skype&);
  138.     friend ostream& operator<<(ostream&, Abonat_Skype&);
  139. };
  140. Abonat_Skype::Abonat_Skype(int x,string z="",string nr="",string id=""):Abonat(x,z,nr)
  141. {
  142.     id_skype=id;
  143.  
  144. }
  145. Abonat_Skype::~Abonat_Skype()
  146. {
  147. }
  148. void Abonat_Skype::citire(istream &in)
  149. {
  150.     Abonat::citire(in);
  151.     cout<<"Dati id Skype: ";
  152.     in>>id_skype;
  153.  
  154. }
  155. void Abonat_Skype::afisare(ostream &out)
  156. {
  157.     Abonat::afisare(out);
  158.     out<<"Id Skype: ";
  159.     out<<id_skype<<"\n";
  160. }
  161. istream& operator>>(istream& in,Abonat_Skype& p)
  162. {
  163.     p.citire(in);
  164.     return in;
  165. }
  166. ostream& operator<<(ostream& out, Abonat_Skype& p)
  167. {
  168.     p.afisare(out);
  169.     return out;
  170. }
  171.  
  172. ///---------------------------------------------------------------
  173.  
  174. class Abonat_Skype_Romania:public Abonat_Skype
  175. {
  176.     ///aici avem membrii privati
  177.     string adresa_mail;
  178. public:
  179.     Abonat_Skype_Romania(int, string, string, string,string);
  180.     ~Abonat_Skype_Romania();
  181.     void citire(istream &in);
  182.     void afisare(ostream &out);
  183.     friend istream& operator>>(istream&, Abonat_Skype_Romania&);
  184.     friend ostream& operator<<(ostream&, Abonat_Skype_Romania&);
  185. };
  186. Abonat_Skype_Romania::Abonat_Skype_Romania(int  x,string z="",string nr="",string id="",string adresa=""):Abonat_Skype(x,z,nr,id)
  187. {
  188.     adresa_mail=adresa;
  189.  
  190. }
  191. Abonat_Skype_Romania::~Abonat_Skype_Romania()
  192. {
  193.  
  194. }
  195. void Abonat_Skype_Romania::citire(istream &in)
  196. {
  197.     Abonat::citire(in);
  198.     cout<<"Adresa mail ";
  199.     in>>adresa_mail;
  200. }
  201. void Abonat_Skype_Romania::afisare(ostream &out)
  202. {
  203.     Abonat::afisare(out);
  204.     out<<"Adresa mail: ";
  205.     out<<adresa_mail<<"\n";
  206. }
  207. istream& operator>>(istream& in,Abonat_Skype_Romania& p)
  208. {
  209.     p.citire(in);
  210.     return in;
  211. }
  212. ostream& operator<<(ostream& out, Abonat_Skype_Romania& p)
  213. {
  214.     p.afisare(out);
  215.     return out;
  216. }
  217.  
  218. ///---------------------------------------------------------------------
  219.  
  220. class Abonat_Skype_Extern:public Abonat_Skype
  221. {
  222.     ///aici avem membrii privati
  223.     string tara;
  224. public:
  225.     Abonat_Skype_Extern(int, string, string, string,string);
  226.     ~Abonat_Skype_Extern();
  227.     void citire(istream &in);
  228.     void afisare(ostream &out);
  229.     friend istream& operator>>(istream&, Abonat_Skype_Extern&);
  230.     friend ostream& operator<<(ostream&, Abonat_Skype_Extern&);
  231. };
  232. Abonat_Skype_Extern::Abonat_Skype_Extern(int  x,string z="",string nr="",string id="",string t=""):Abonat_Skype(x,z,nr,id)
  233. {
  234.     tara=t;
  235.  
  236. }
  237. Abonat_Skype_Extern::~Abonat_Skype_Extern()
  238. {
  239.  
  240. }
  241.  
  242. istream& operator>>(istream& in,Abonat_Skype_Extern& p)
  243. {
  244.     p.citire(in);
  245.     return in;
  246. }
  247. ostream& operator<<(ostream& out, Abonat_Skype_Extern& p)
  248. {
  249.     p.afisare(out);
  250.     return out;
  251. }
  252. void Abonat_Skype_Extern::citire(istream &in)
  253. {
  254.     Abonat::citire(in);
  255.     cout<<"Tara ";
  256.     in>>tara;
  257. }
  258. void Abonat_Skype_Extern::afisare(ostream &out)
  259. {
  260.     Abonat::afisare(out);
  261.     out<<"Tara: ";
  262.     out<<tara<<"\n";
  263. }
  264. ///---------------------------------------------------------------
  265.  
  266. class Agenda
  267. {
  268. private:
  269.     vector <Abonat*> p;
  270.     int space;
  271. public:
  272.     Agenda ();
  273.     Agenda(int s_space){ space = s_space;
  274.     }
  275.     ~Agenda();
  276.     void citire(istream &in);
  277.     void afisare(ostream &out);
  278.     friend istream& operator>>(istream&, Agenda&);
  279.     friend ostream& operator<<(ostream&, Agenda&);
  280.     Abonat& operator[](string);
  281.  
  282. };
  283.  
  284. Agenda::Agenda()
  285. {
  286.  
  287. }
  288. //Agenda(Agenda&);
  289.  
  290. Agenda::~Agenda()
  291. {
  292.  
  293. }
  294. istream& operator>>(istream& in,Agenda& p)
  295. {
  296.     p.citire(in);
  297.     return in;
  298. }
  299. ostream& operator<<(ostream& out, Agenda& p)
  300. {
  301.    p.afisare(out);
  302.     return out;
  303. }
  304. void Agenda::citire(istream &in)
  305. {
  306.    for(int i=0; i<space; i++){
  307.       Abonat* x = new Abonat(i);
  308.       in>>(*x);
  309.       p.push_back(x);
  310.    }
  311.  
  312. }
  313. void Agenda::afisare(ostream &out)
  314. {
  315.     int i=0;
  316.     for(i=0; i<sizeof(p)/sizeof(Abonat); i++)
  317.         cout<<p[i];
  318. }
  319.  
  320.  Abonat &Agenda:: operator[](string s)
  321. {
  322.     int i=0;
  323.     for(i=0; i<sizeof(p)/sizeof(Abonat); i++)
  324.         if(s == p[i]->get_nume() )
  325.    {
  326.            return *p[i];
  327.    }
  328.  
  329. }
  330.  
  331.  
  332.  
  333.  
  334. void menu()
  335. {
  336.     int choice;
  337.  
  338.     bool MenuAbonati  = true;
  339.     int numar_abonati = 0;
  340.     Agenda *lista_abonati;
  341.     while (MenuAbonati != false)
  342.     {
  343.         cout<< "Guita Bianca Oana 211 - Proiect - Nume proiect: Tema 4"<<endl;
  344.         cout<<" "<<"MENIU:"<<endl;
  345.         cout<< "****************************\n";
  346.         cout<<" 1. Adaugati abonati \n";
  347.         cout<<" 2. Iesiti din meniu \n";
  348.  
  349.         cin>>choice;
  350.         switch(choice)
  351.         {
  352.             while(choice>=1 && choice<3)
  353.  
  354.                 if(numar_abonati != 0)
  355.                 {cout<<"ID               NUME                NR. TELEFON              \n";
  356.  
  357.                 }
  358.                 else
  359.  
  360.                      cout<<"Nu avem ce abonati sa afisam"<<endl;
  361.  
  362.  case 1:
  363.  
  364.             cout<<" Alegeti numarul de abonati pe care doriti sa ii adaugati?\n";
  365.             int i;
  366.             cin>>numar_abonati;
  367.             lista_abonati = new Agenda(numar_abonati);
  368.             cin>>(*lista_abonati);
  369.  
  370.  
  371.             break;
  372.  
  373.     case 2:
  374.            if (choice == 2)
  375.             {
  376.                 cout<<"EXIT! ";
  377.             }
  378.             if (choice<1||choice>3)
  379.             {
  380.                 cout<<"Selectie invalida";
  381.             }
  382.             cout<<endl;
  383.             exit(0);
  384. break;
  385.  
  386.  
  387.  
  388.  
  389.  
  390.         }
  391.     }
  392. }
  393.  
  394. int main()
  395.     {
  396.  
  397.         menu();
  398.  
  399.     }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top