Advertisement
metalni

OOP Labs 3 Fabrika

May 30th, 2020
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Rabotnik{
  7.     private:
  8.         char name[30];
  9.         char surname[30];
  10.         int salary;
  11.     public:
  12.         Rabotnik(){}
  13.         Rabotnik(const char * ime, const char * prezime, int plata);
  14.         int getPlata();
  15.         void pecati();
  16. };
  17.  
  18. Rabotnik::Rabotnik(const char * ime, const char * prezime, int plata){
  19.     strcpy(this->name, ime);
  20.     strcpy(this->surname, prezime);
  21.     this->salary=plata;
  22. }
  23.  
  24. int Rabotnik::getPlata(){
  25.     return this->salary;
  26. }
  27.  
  28. void Rabotnik::pecati(){
  29.     cout << this->name << " " << this->surname << " " << this->getPlata() << endl;
  30. }
  31.  
  32. //class Fabrika
  33. class Fabrika {
  34.     private:
  35.         Rabotnik array[100];
  36.         int brojVraboteni;
  37.     public:
  38.         Fabrika(){}
  39.         Fabrika(const Rabotnik * r, int n);
  40.         void pecatiVraboteni();
  41.         void pecatiSoPlata(int plata);
  42. };
  43. Fabrika::Fabrika(const Rabotnik * r, int n){
  44.     for(int i=0; i<n; i++){
  45.         this->array[i] = *(r+i);
  46.     }
  47.     this->brojVraboteni=n;
  48. }
  49. void Fabrika::pecatiVraboteni(){
  50.     cout << "Site vraboteni:" << endl;
  51.     for(int i=0; i<this->brojVraboteni; i++){
  52.         this->array[i].pecati();
  53.     }
  54. }
  55.  
  56. void Fabrika::pecatiSoPlata(int plata){
  57.     cout << "Vraboteni so plata povisoka od " << plata << " :" << endl;
  58.     for(int i=0; i<this->brojVraboteni; i++){
  59.         if((this->array[i].getPlata()) > plata){
  60.             this->array[i].pecati();
  61.         }
  62.            
  63.     }
  64. }
  65.  
  66. int main(void){
  67.     char name[30], surname[30];
  68.     int salary, minSalary;
  69.     Rabotnik r[100];
  70.     int n;
  71.     cin>>n;
  72.     for(int i=0; i<n; i++){
  73.         cin >> name;
  74.         cin >> surname;
  75.         cin >> salary;
  76.         r[i] = Rabotnik(name,surname,salary);
  77.     }
  78.  
  79.     Fabrika f(r,n);
  80.     cin >> minSalary;
  81.     f.pecatiVraboteni();
  82.     f.pecatiSoPlata(minSalary);
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement