Advertisement
sebasvp2005

Untitled

Jun 4th, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 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. empleado * GenerarArreglo(int n){
  15.     char ofi[] = "CSL";// == {'C', 'S', 'L'}
  16.     empleado * temp = new empleado[n];
  17.     for(int i=0;i<n; i++){
  18.         empleado cur = {rand()%31 + 20, ofi[rand()%3], rand()%181};
  19.         temp[i] = cur;
  20.     }
  21.     return temp;
  22. }
  23.  
  24. void imprimirArreglo(empleado * arr, int n){
  25.     cout << "Indice\tHoras\tOficina\tTardanza\n";
  26.     for(int i=0;i<n; i++){
  27.         cout << i << (i<10? " ": "") <<"\t\t\t" << arr[i].horas << "\t\t\t" << arr[i].oficina << "\t\t\t\t" << arr[i].tardanza << endl;
  28.     }
  29. }
  30.  
  31. void masTardones(empleado * arr, int n){
  32.     int mx =0;
  33.     for(int i=0;i<n; i++){
  34.         if(arr[i].tardanza>mx) mx = arr[i].tardanza;
  35.     }
  36.     for(int i=0;i<n; i++){
  37.         if(arr[i].tardanza == mx){
  38.             cout << "El empleado con indice " << i << " es el mas tardon\n";
  39.         }
  40.     }
  41. }
  42.  
  43. void promedio_de_horas(empleado * arr, int n){
  44.     char ofi[] = "CSL";
  45.     for(int i=0;i<3; i++){
  46.  
  47.         int sum=0;
  48.         int cont=0;
  49.         for(int j=0;j<n; j++){
  50.             if(arr[j].oficina==ofi[i]){
  51.                 sum+=arr[j].horas;
  52.                 cont++;
  53.             }
  54.         }
  55.         cout << "La oficina " << ofi[i] << " tiene un promedio " << 1.0*sum/cont << endl;
  56.     }
  57. }
  58.  
  59. void masPuntuales(empleado * arr, int n){
  60.     cout << "EMPLEADO PUNTUALES:\n";
  61.     for(int i=0;i<n; i++){
  62.         if(arr[i].tardanza==0){
  63.             cout << i << (i<10? " ": "") <<"\t\t\t" << arr[i].horas << "\t\t\t" << arr[i].oficina << "\t\t\t\t" << arr[i].tardanza << endl;
  64.         }
  65.     }
  66. }
  67.  
  68. void ordernar(empleado * arr, int n){
  69.     for(int i=0; i<n; i++){
  70.         for(int j=i+1; j<n; j++){
  71.             if((arr[i].oficina < arr[j].oficina) || (arr[i].oficina==arr[j].oficina && arr[i].tardanza > arr[j].tardanza)){
  72.                 empleado aux = arr[i];
  73.                 arr[i] = arr[j];
  74.                 arr[j] = aux;
  75.             }
  76.         }
  77.     }
  78.  
  79. }
  80.  
  81.  
  82.  
  83.  
  84. int main(){
  85.     srand(time(0));
  86.  
  87.     int n = 15;
  88.  
  89.     empleado * arreglo = GenerarArreglo(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