Crazy

Студент

May 18th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. using namespace std;
  4.  
  5. class BadInputException{};
  6.  
  7. class StudentKurs{
  8.    protected:
  9.        char ime[30];
  10.        int ocenka;
  11.        bool daliUsno;
  12.     static int MAX;
  13.     static const int MINOCENKA=6;
  14.  
  15.    public:
  16.    
  17.     StudentKurs(char* ime,int finalenIspit){
  18.        strcpy(this->ime,ime);
  19.        this->ocenka=finalenIspit;
  20.        this->daliUsno=false;
  21.      }
  22.      //дополни ја класата
  23.     bool getDaliUsno(){return daliUsno;}
  24.     char *getIme(){return ime;}
  25.    
  26.     static void setMAX(int m){MAX=m;}
  27.    
  28.    
  29.    
  30.     //polym
  31.    
  32.     virtual int Focenka(){return ocenka;}
  33.    
  34.     friend ostream &operator<<(ostream &out, StudentKurs &sk)
  35.     {
  36.         return out<<sk.ime<<" --- "<<sk.Focenka()<<endl;
  37.        
  38.        
  39.    
  40.    
  41.     }
  42.    
  43.    
  44.    
  45. };
  46.  
  47. int StudentKurs::MAX=10;
  48.  
  49. //вметни го кодот за StudentKursUsno
  50.  
  51. class StudentKursUsno: public StudentKurs {
  52.     private:
  53.    
  54.     char *opisnaocenka;
  55.    
  56.     public:
  57.     StudentKursUsno(char* ime,int finalenIspit):StudentKurs(ime, finalenIspit){
  58.         opisnaocenka = new char [0];
  59.         daliUsno=true;
  60.  
  61.     }
  62.    
  63.    
  64.    
  65.      int Focenka(){
  66.    
  67.         int ocenka=StudentKurs::ocenka;
  68.        
  69.         if(strcmp(opisnaocenka,"odlicen")==0)
  70.             ocenka+=2;
  71.         else if (strcmp(opisnaocenka,"do7br4o")==0)
  72.             ocenka++;
  73.             else if (strcmp(opisnaocenka,"losho")==0)
  74.            ocenka--;
  75.            
  76.             return ocenka;
  77.    
  78.    
  79.     }
  80.    
  81.     StudentKursUsno &operator+=(char *o){
  82.        
  83.         opisnaocenka=new char[strlen(o)+1];
  84.         strcpy(opisnaocenka,o);
  85.            
  86.             return *this;
  87.    
  88.    
  89.    
  90.     }
  91.    
  92.  
  93.  
  94. };
  95.  
  96.  
  97. class KursFakultet{
  98. private:
  99.     char naziv[30];
  100.     StudentKurs *studenti[20];
  101.     int broj;
  102.    
  103. public:
  104.     KursFakultet(char *naziv, StudentKurs** studenti,int broj ){
  105.       strcpy(this->naziv,naziv);
  106.       for (int i=0;i<broj;i++){
  107.         //ako studentot ima usno isprashuvanje
  108.         if (studenti[i]->getDaliUsno()){
  109.             this->studenti[i]=new StudentKursUsno(*dynamic_cast<StudentKursUsno*>(studenti[i]));
  110.         }
  111.         else this->studenti[i]=new StudentKurs(*studenti[i]);
  112.       }
  113.       this->broj=broj;
  114.     }
  115.     ~KursFakultet(){
  116.     for (int i=0;i<broj;i++) delete studenti[i];
  117.     }
  118.  
  119.     //дополни ја класата
  120.    
  121.     void pecatiStudenti(){
  122.         cout<<"Kursot "<<naziv<<" go polozile:"<<endl;
  123.        
  124.         for(int i=0;i<broj;i++)
  125.         if(studenti[i]->Focenka()>5)
  126.             cout<<*studenti[i];
  127.        
  128.    
  129.    
  130.     }
  131.    
  132.    
  133.     void postaviOpisnaOcenka(char * ime, char* opisnaOcenka) {
  134.        
  135.         for(int i=0;i<broj;i++){
  136.             if(strcmp(studenti[i]->getIme(),ime)==0 && studenti[i]->getDaliUsno())
  137.         {
  138.                 StudentKursUsno *usno =dynamic_cast<StudentKursUsno *> (studenti[i]);
  139.                
  140.                 *usno+=opisnaOcenka;
  141.        
  142.        
  143.         }
  144.            
  145.         }
  146.        
  147.        
  148.    
  149.    
  150.     }
  151.    
  152. };
  153.  
  154. int main(){
  155.  
  156. StudentKurs **niza;
  157. int n,m,ocenka;
  158. char ime[30],opisna[10];
  159. bool daliUsno;
  160. cin>>n;
  161. niza=new StudentKurs*[n];
  162. for (int i=0;i<n;i++){
  163.    cin>>ime;
  164.    cin>>ocenka;
  165.    cin>>daliUsno;
  166.    if (!daliUsno)
  167.     niza[i]=new StudentKurs(ime,ocenka);
  168.    else
  169.     niza[i]=new StudentKursUsno(ime,ocenka);
  170. }
  171.  
  172. KursFakultet programiranje("OOP",niza,n);
  173. for (int i=0;i<n;i++) delete niza[i];
  174. delete [] niza;
  175. cin>>m;
  176.    
  177. for (int i=0;i<m;i++){
  178.    cin>>ime>>opisna;
  179.    
  180.     try {
  181.         for(int i=0;i<strlen(opisna);i++)
  182.             if(!isalpha(opisna[i]))
  183.             throw BadInputException();
  184.    
  185.     }
  186.    
  187.     catch (BadInputException){
  188.         cout<<"Greshna opisna ocenka"<<endl;
  189.    
  190.    
  191.     }
  192.    
  193.    
  194.    programiranje.postaviOpisnaOcenka(ime,opisna);
  195. }
  196.    
  197.    
  198.  
  199. StudentKurs::setMAX(9);
  200.  
  201. programiranje.pecatiStudenti();
  202.    
  203.    
  204.  
  205. }
Advertisement
Add Comment
Please, Sign In to add comment