rijads

Untitled

Jun 19th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;   
  3. struct datum{
  4.     int dan,mjesec,godina;
  5.     void Unos(int d,int m,int g){
  6.     dan=d;
  7.     mjesec=m;
  8.     godina=g;
  9.  
  10.     }
  11.     void Ispis(){
  12.         cout<<dan<<"."<<mjesec<<"."<<godina<<endl;
  13.  
  14.     }
  15. };
  16. struct polozenipredmet
  17. {
  18.     char naziv[20];
  19.     datum dp;
  20.     int ocjena;
  21.     void unos(char *n,datum d, int o)
  22.     {
  23.         strcpy(naziv,n);
  24.         dp=d;
  25.         ocjena=o;
  26.     }
  27.  
  28.     void ispis()
  29.     {
  30.         cout<<"Naziv: "<<naziv<<endl<<"Ocjena: "<<ocjena<<endl;
  31.         dp.Ispis();
  32.     }
  33. };
  34. struct student
  35. {
  36.     int bri;
  37.     char imeprezime[20];
  38.     datum r;
  39.     polozenipredmet *pr;
  40.     int tpol;
  41.     int maxp;
  42.     void unos(int index,char *ip,datum dr)
  43.     {
  44.         bri=index;
  45.         strcpy(imeprezime,ip);
  46.         r=dr;
  47.     }
  48.     bool dodajpolozeni(char *n,datum d,int o)
  49.     {
  50.         if(tpol==0)
  51.         {
  52.             tpol++;
  53.             pr[0].unos(n,d,o);
  54.         }
  55.         else
  56.         {
  57.         for(int i=1;i<=tpol;i++)
  58.         {
  59.             if(strcmp(pr[i].naziv,n)!=0)
  60.                 return false;
  61.         }
  62.         pr[tpol+1].unos(n,d,o);
  63.         tpol++;
  64.         return true;
  65.         }
  66.     }
  67.     int uklonipredmet(datum d)
  68.     {
  69.         int uk=0;
  70.         bool ukl=false;
  71.         for(int i=0;i<tpol;i++)
  72.         {
  73.             if(pr[i].dp.dan==d.dan && pr[i].dp.mjesec==d.mjesec && pr[i].dp.godina==d.godina)
  74.             {
  75.                 strcpy(pr[i].naziv,pr[i+1].naziv);
  76.                 pr[i].dp=pr[i+1].dp;
  77.                 pr[i].ocjena=pr[i+1].ocjena;
  78.                 tpol--;
  79.                 uk++;
  80.                 ukl=true;
  81.             }
  82.             if (ukl)
  83.             {
  84.                 strcpy(pr[i].naziv,pr[i+1].naziv);
  85.                 pr[i].dp=pr[i+1].dp;
  86.                 pr[i].ocjena=pr[i+1].ocjena;
  87.             }
  88.         }
  89.         return uk;
  90.     }
  91.     void ispis()
  92.     {
  93.         cout<<"\nIme i prezime: "<<imeprezime<<endl<<"Broj indexa: "<<bri<<endl<<"Datum rodjenja: "<<r.dan<<"."<<r.mjesec<<"."<<r.godina<<endl;
  94.     }};
  95. void main()
  96. {
  97.     student s1;
  98.     s1.r.Unos(29,34,2345);
  99.     s1.tpol=0;
  100.     s1.maxp=40;
  101.     s1.unos(3245,"rijad spahic",s1.r);
  102.     s1.pr=new polozenipredmet[s1.maxp];
  103.     datum x,y,z;
  104.     x.dan=1;
  105.     x.mjesec=3;
  106.     x.godina=2012;
  107.     y.dan=5;
  108.     y.mjesec=2;
  109.     y.godina=2013;
  110.     z.dan=26;
  111.     z.mjesec=11;
  112.     z.godina=2010;
  113.  
  114.     if(s1.dodajpolozeni("programiranje",x,7)==true)
  115.         cout<<"Greska, predmet vec postoji!"<<endl;
  116.     else
  117.         cout<<"Uspjesno dodat"<<endl;
  118.     if(s1.dodajpolozeni("asp",y,9)==true)
  119.         cout<<"Greska, predmet vec postoji!"<<endl;
  120.     else
  121.         cout<<"Uspjesno dodat"<<endl;
  122.     if(s1.dodajpolozeni("aks",z,5)==true)
  123.         cout<<"Greska, predmet vec postoji!"<<endl;
  124.     else
  125.         cout<<"Uspjesno dodat"<<endl;
  126.     s1.ispis();
  127.     for(int i=0;i<s1.tpol;i++)
  128.     {
  129.         s1.pr[i].ispis();
  130.         cout<<endl;
  131.     }
  132.     cout<<s1.uklonipredmet(x);
  133.     system ("pause>0");
  134. }
Advertisement
Add Comment
Please, Sign In to add comment