Advertisement
sebasvp2005

Untitled

Jun 4th, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. struct empleado
  7. {
  8.     int horas;
  9.     char oficina;
  10.     int tardanza;
  11. };
  12.  
  13.  
  14. void GenerarArreglo(empleado temp[], int n){
  15.     char ofi[] = "CSL";// == {'C', 'S', 'L'}
  16.     for(int i=0;i<n; i++){
  17.         empleado cur = {rand()%31 + 20, ofi[rand()%3], rand()%181};
  18.         temp[i] = cur;
  19.     }
  20.  
  21. }
  22.  
  23. void imprimirArreglo(empleado * arr, int n){
  24.     cout << "Indice\tHoras\tOficina\tTardanza\n";
  25.     for(int i=0;i<n; i++){
  26.         cout << i << (i<10? " ": "") <<"\t\t\t" << arr[i].horas << "\t\t\t" << arr[i].oficina << "\t\t\t\t" << arr[i].tardanza << endl;
  27.     }
  28. }
  29.  
  30. void masTardones(empleado * arr, int n){
  31.     int mx =0;
  32.     for(int i=0;i<n; i++){
  33.         if(arr[i].tardanza>mx) mx = arr[i].tardanza;
  34.     }
  35.     for(int i=0;i<n; i++){
  36.         if(arr[i].tardanza == mx){
  37.             cout << "El empleado con indice " << i << " es el mas tardon\n";
  38.         }
  39.     }
  40. }
  41.  
  42. void promedio_de_horas(empleado * arr, int n){
  43.     char ofi[] = "CSL";
  44.     for(int i=0;i<3; i++){
  45.  
  46.         int sum=0;
  47.         int cont=0;
  48.         for(int j=0;j<n; j++){
  49.             if(arr[j].oficina==ofi[i]){
  50.                 sum+=arr[j].horas;
  51.                 cont++;
  52.             }
  53.         }
  54.         cout << "La oficina " << ofi[i] << " tiene un promedio " << 1.0*sum/cont << endl;
  55.     }
  56. }
  57.  
  58. void masPuntuales(empleado * arr, int n){
  59.     cout << "EMPLEADO PUNTUALES:\n";
  60.     for(int i=0;i<n; i++){
  61.         if(arr[i].tardanza==0){
  62.             cout << i << (i<10? " ": "") <<"\t\t\t" << arr[i].horas << "\t\t\t" << arr[i].oficina << "\t\t\t\t" << arr[i].tardanza << endl;
  63.         }
  64.     }
  65. }
  66.  
  67. void ordernar(empleado * arr, int n){
  68.     for(int i=0; i<n; i++){
  69.         for(int j=i+1; j<n; j++){
  70.             if((arr[i].oficina < arr[j].oficina) || (arr[i].oficina==arr[j].oficina && arr[i].tardanza > arr[j].tardanza)){
  71.                 empleado aux = arr[i];
  72.                 arr[i] = arr[j];
  73.                 arr[j] = aux;
  74.             }
  75.         }
  76.     }
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83. int main(){
  84.     srand(time(0));
  85.  
  86.     int n = 15;
  87.  
  88.     empleado arreglo[15];
  89.     GenerarArreglo(arreglo , n);
  90.  
  91.     imprimirArreglo(arreglo, n);
  92.     cout << endl;
  93.     masTardones(arreglo, n);
  94.     cout << endl;
  95.     promedio_de_horas(arreglo, n);
  96.     cout << endl;
  97.     masPuntuales(arreglo,n);
  98.     cout << endl;
  99.     ordernar(arreglo, n);
  100.     imprimirArreglo(arreglo, n);
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement