Advertisement
lastephanieee

fncadnfcjcaf

Mar 29th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Fotografija{
  7.  
  8. private:
  9.     char *opis;
  10.     int rezolucija;
  11.     int moment;
  12.  
  13. public:
  14.     Fotografija(char *opis="", int rezolucija=0, int moment=0)
  15.     {
  16.         this->opis=new char[strlen(opis)+1];
  17.         strcpy(this->opis, opis);
  18.         this->rezolucija=rezolucija;
  19.         this->moment=moment;
  20.     }
  21.  
  22.     Fotografija &operator=(Fotografija &ph)
  23.     {
  24.         if(this!=&ph)
  25.         {
  26.             delete [] this->opis;
  27.             this->opis=new char[strlen(ph.opis)+1];
  28.             strcpy(this->opis, ph.opis);
  29.             this->rezolucija=ph.rezolucija;
  30.             this->moment=ph.moment;
  31.         }
  32.         return *this;
  33.     }
  34.     void pecati()
  35.     {
  36.         cout<<getopis()<<endl;
  37.         cout<<getrezolucija()<<endl;
  38.         cout<<getmoment()<<endl;
  39.     }
  40.     int getrezolucija()
  41.     {
  42.         return this->rezolucija;
  43.     }
  44.     int getmoment()
  45.     {
  46.         return this->moment;
  47.     }
  48.     char *getopis()
  49.     {
  50.         return this->opis;
  51.     }
  52.     ~Fotografija()
  53.     {
  54.         delete [] this->opis;
  55.     }
  56. };
  57.  
  58. class Album{
  59.  
  60. private:
  61.     Fotografija *f;
  62.     int vkupen;
  63.     char ime[50];
  64. public:
  65.     Album(Fotografija *f=0, int vkupen=0, char *ime="")
  66.     {
  67.         this->vkupen=vkupen;
  68.         this->f=new Fotografija[this->vkupen];
  69.         for(int i=0; i<this->vkupen; i++)
  70.         {
  71.             f[i]=f[i];
  72.         }
  73.         strcpy(this->ime, ime);
  74.     }
  75.     Album(const Album& a)
  76.     {
  77.         this->vkupen=a.vkupen;
  78.         this->f=new Fotografija[a.vkupen];
  79.         for(int i=0; i<a.vkupen; i++)
  80.         {
  81.             this->f[i]=a.f[i];
  82.         }
  83.         strcpy(this->ime, a.ime);
  84.     }
  85.     Album &operator=(Album &al)
  86.     {
  87.         if(this!=&al)
  88.         {
  89.             this->vkupen=al.vkupen;
  90.             delete [] this->f;
  91.             this->f=new Fotografija[al.vkupen];
  92.             for(int i=0; i<al.vkupen; i++)
  93.             {
  94.                 f[i]=al.f[i];
  95.             }
  96.             strcpy(this->ime, al.ime);
  97.         }
  98.     }
  99.     void dodadifotografija(Fotografija o)
  100.     {
  101.         Fotografija *tmp= new Fotografija[this->vkupen];
  102.         for(int i=0; i<this->vkupen; i++)
  103.         {
  104.             tmp[i]=this->f[i];
  105.         }
  106.         delete [] this->f;
  107.         this->f=new Fotografija[this->vkupen+1];
  108.         for(int i=0; i<this->vkupen; i++)
  109.         {
  110.             this->f[i]=tmp[i];
  111.         }
  112.         delete [] tmp;
  113.         this->f[this->vkupen]=o;
  114.         this->vkupen++;
  115.     }
  116.  
  117.     void najgolemaFotografija()
  118.     {
  119.         int i;
  120.         int naj=0;
  121.         for (i=1;i<this->vkupen;i++)
  122.         if ((f[i].getrezolucija())>(f[naj].getrezolucija()))
  123.         naj=i;
  124.  
  125.        f[naj].pecati();
  126.     }
  127.     void fotografiiSlikani(int moment)
  128.     {
  129.         for(int i=0; i<this->vkupen; i++)
  130.         {
  131.             int n;
  132.             n=f[i].getmoment();
  133.             if(n>moment)
  134.             {
  135.                 f[i].pecati();
  136.             }
  137.         }
  138.     }
  139.     int getvkupen()
  140.     {
  141.         return this->vkupen;
  142.     }
  143.     char *getime()
  144.     {
  145.         return this->ime;
  146.     }
  147.  
  148.     ~Album()
  149.     {
  150.         delete [] this->f;
  151.     }
  152. };
  153. int main()
  154. {
  155.     int n;
  156.     cout<<"Vnesete broj na sliki"<<endl;
  157.     cin>>n;
  158.     Fotografija f[n];
  159.     char opis[100];
  160.     int rezolucija;
  161.     int moment;
  162.     for(int i=0; i<n; i++)
  163.     {
  164.         cout<<"Vnesete opis"<<endl;
  165.         cin>>opis;
  166.         cout<<"Vnesete rezolucija"<<endl;
  167.         cin>>rezolucija;
  168.         cout<<"Vnesete moment"<<endl;
  169.         cin>>moment;
  170.         Fotografija t(opis, rezolucija, moment);
  171.         f[i]=t;
  172.     }
  173.     char ime[30];
  174.     cout<<"Vnesete ime na albumot"<<endl;
  175.     cin>>ime;
  176.     Album a(f, n, ime);
  177.     a.najgolemaFotografija();
  178.  
  179.     return 0;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement