Sofe1204

Untitled

Mar 17th, 2022 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. enum typeE {employee = 0, manager = 1, owner = 2};
  6. class Employee{
  7. private:
  8.       char name[50];
  9.       float salary;
  10.       typeE wp;
  11.       void copy(const Employee &e){
  12.          strcpy(this->name,e.name);
  13.          this->salary=e.salary;
  14.          this->wp=e.wp;
  15.       }
  16.     public:
  17.     Employee(char *name = "",float salary = 0,typeE wp = employee){
  18.          strcpy(this->name,name);
  19.          this->salary=salary;
  20.          this->wp=wp;
  21.      }
  22.  
  23.      Employee(const Employee &e){
  24.          copy(e);
  25.      }
  26.  
  27.       typeE getWp(){
  28.          return wp;
  29.      }
  30.  
  31.      float getSalary(){
  32.          return salary;
  33.      }
  34.  
  35.       char getName(){
  36.           return *name;
  37.      }
  38.  
  39.      bool operator >(Employee &e){
  40.      if(this->getSalary() > e.getSalary()){
  41.         return true;
  42.      }
  43. }
  44.  
  45. friend ostream& operator<<(ostream &out,const Employee &e)
  46.     {
  47.         out<<e.name<<" "<<e.salary<<" ";
  48.         if(e.wp == employee) out<<"Employee"<<endl;
  49.         if(e.wp == manager) out<<"Manager"<<endl;
  50.         if(e.wp == owner) out <<"Owner"<<endl;
  51.         return out;
  52.     }
  53.  
  54.  
  55.  
  56. };
  57.  
  58.  void sort(Employee emp[],int n){
  59.  
  60.    for(int i=0;i<n;i++)
  61.     {
  62.         for(int j=i+1;j<n;j++)
  63.         {
  64.             if(emp[i]>emp[j])
  65.             {
  66.                 Employee temp=emp[i];
  67.                 emp[i]=emp[j];
  68.                 emp[j]=temp;
  69.             }
  70.         }
  71.     }
  72.  }
  73.  
  74. int main(){
  75.     int n;
  76.     std::cout<<"Vnesi broj na vraboteni"<<std::endl;
  77.     std::cin >> n;
  78.     Employee emp[n];
  79.     for(int i=0; i<n; i++) {
  80.         char *name;
  81.         float salary;
  82.         int wp;
  83.         typeE type;
  84.          std::cin >> name;
  85.           std::cin >> salary;
  86.            std::cin >> wp;
  87.             emp[i]= Employee (name,salary,type);
  88.     }
  89.     sort(emp,n);
  90.     for(int i=0;i<n;i++){
  91.         cout<<emp[i]<<endl;
  92.     }
  93.     return 0;
  94. }
Add Comment
Please, Sign In to add comment