Advertisement
Mihnea03

Proiect info

Mar 8th, 2021
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.37 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <cstring>
  5. using namespace std;
  6. ifstream fin("fisier.in");
  7. ofstream fout("fisier.out");
  8.  
  9. class Articol {
  10.   protected:
  11.  
  12.     int cota;
  13.     char *titlul;
  14.  
  15.   public:
  16.     Articol() {
  17.         cota=0;
  18.         titlul=new char[30];
  19.     }
  20.     Articol(int cota, char *titlul) {
  21.         this->cota=cota;
  22.         this->titlul=new char[30];
  23.         strcpy(this->titlul,titlul);
  24.         ///this->titlul=titlul;
  25.     }
  26.     Articol(Articol &art) {
  27.         *this=art;
  28.     }
  29.     int getCota() {
  30.         return cota;
  31.     }
  32.     void setCota(int cota) {
  33.         this->cota=cota;
  34.     }
  35.     char *getTitlul() {
  36.         return titlul;
  37.     }
  38.     void setTitlul(char *title) {
  39.         strcpy(titlul, title);
  40.     }
  41.     ~Articol() {
  42.         delete titlul;
  43.     }
  44.     void display() {
  45.         cout<<cota<<"\n";
  46.         cout<<titlul<<"\n";
  47.     }
  48.     void read() {
  49.         fin>>cota;
  50.         fin>>titlul;
  51.     }
  52. };
  53.  
  54. class Revista : public Articol {
  55. protected:
  56.     int nr;//Numarul revistei
  57.     int tiraj;
  58.     int frecv;// Numarul de aparitii pe luna
  59.  
  60.   public:
  61.  
  62.     Revista(int nr,int tiraj,int frecv) : Articol(cota, titlul) {
  63.         this->nr=nr;
  64.         this->tiraj=tiraj;
  65.         this->frecv=frecv;
  66.     }
  67.     Revista(Revista &rev) {
  68.         *this=rev;
  69.     }
  70.     void display() {
  71.         fout<<cota<<"\n";
  72.         fout<<titlul<<"\n";
  73.         fout<<nr<<"\n";
  74.         fout<<tiraj<<"\n";
  75.         fout<<frecv<<"\n";
  76.     }
  77.     void read() {
  78.         fin>>cota;
  79.         fin>>titlul;
  80.         fin>>nr;
  81.         fin>>tiraj;
  82.         fin>>frecv;
  83.     }
  84. };
  85. class Carte : public Articol {
  86. protected:
  87.     char *autor;
  88.     char *editura;
  89.     int an;//anul aparitiei
  90.  
  91.   public:
  92.  
  93.     Carte(char *autor,char *editura, int an) : Articol(cota, titlul) {
  94.         this->autor=autor;
  95.         this->editura=editura;
  96.         this->an=an;
  97.     }
  98.     Carte(Carte &car) {
  99.         *this=car;
  100.     }
  101.     void display() {
  102.         fout<<cota<<"\n";
  103.         fout<<titlul<<"\n";
  104.         fout<<autor<<"\n";
  105.         fout<<editura<<"\n";
  106.         fout<<an<<"\n";
  107.     }
  108.     void read() {
  109.         fin>>cota;
  110.         fin>>titlul;
  111.         fin>>autor;
  112.         fin>>editura;
  113.         fin>>an;
  114.     }
  115.  
  116. };
  117. int main() {
  118.     Articol a[200];
  119.     int n;
  120.     fin>>n;
  121.     for (int i=1;i<=n;i++) {
  122.         a[i].read();
  123.     }
  124.     while (true) {
  125.         cout<<"Alege optiunea dorita:"<<"\n";
  126.         cout<<"1. Afisare lista"<<"\n";
  127.         cout<<"2. Cautare articol"<<"\n";
  128.         cout<<"3. Stergerea unui articol"<<"\n";
  129.         cout<<"4. Incheiere program"<<"\n";
  130.         int x;
  131.         cin>>x;
  132.         char z[30];
  133.         int ok=1;
  134.         int poz=0;
  135.         switch(x) {
  136.             case 1:
  137.                 system("cls");
  138.                 for (int i=1;i<=n;i++) {
  139.                     a[i].display();
  140.                 }
  141.             break;
  142.             case 2:
  143.                 system("cls");
  144.                 cout<<"Care este numele articolului cautat?"<<"\n";
  145.                 cin>>z;
  146.                 for (int i=1;i<=n;i++) {
  147.                     if (strcmp(a[i].getTitlul(),z)==0) {
  148.                         cout<<"Articolul cautat se afla pe pozitia "<<a[i].getCota()<<"\n";
  149.                         ok=0;
  150.                         break;
  151.                     }
  152.                 }
  153.                 if (ok) {
  154.                     cout<<"Articolul nu a fost gasit"<<"\n";
  155.                 }
  156.                 ok=1;
  157.             break;
  158.             case 3:
  159.                 system("cls");
  160.                 cout<<"Care este numele articolului pe care doriti sa il stergeti?"<<"\n";
  161.                 cin>>z;
  162.                 poz=n+1;
  163.                 for (int i=1;i<=n;i++) {
  164.                     if (strcmp(a[i].getTitlul(),z)==0) {
  165.                         poz=i;
  166.                         ok=0;
  167.                         break;
  168.                     }
  169.                 }
  170.                 if (ok) {
  171.                     cout<<"Articolul nu a fost gasit"<<"\n";
  172.                 }
  173.                 else {
  174.                     for (int i=poz;i<=n;i++) {
  175.                         a[i].setCota(a[i+1].getCota());
  176.                         a[i].setTitlul(a[i+1].getTitlul());
  177.                     }
  178.                     n--;
  179.                     cout<<"Articolul a fost sters!"<<"\n";
  180.                 }
  181.                 ok=1;
  182.             break;
  183.             case 4:
  184.                 system("cls");
  185.                 return 0;
  186.             break;
  187.         }
  188.         cout<<"Doresti alta operatie?(D/N): ";
  189.         char y;
  190.         cin>>y;
  191.         if (y=='D') system("cls");
  192.         if (y=='N') return 0;
  193.     }
  194. }
  195.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement