Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <time.h>
- using namespace std;
- struct empleado
- {
- int horas;
- char oficina;
- int tardanza;
- };
- empleado * GenerarArreglo(int n){
- char ofi[] = "CSL";// == {'C', 'S', 'L'}
- empleado * temp = new empleado[n];
- for(int i=0;i<n; i++){
- empleado cur = {rand()%31 + 20, ofi[rand()%3], rand()%181};
- temp[i] = cur;
- }
- return temp;
- }
- void imprimirArreglo(empleado * arr, int n){
- cout << "Indice\tHoras\tOficina\tTardanza\n";
- for(int i=0;i<n; i++){
- cout << i << (i<10? " ": "") <<"\t\t\t" << arr[i].horas << "\t\t\t" << arr[i].oficina << "\t\t\t\t" << arr[i].tardanza << endl;
- }
- }
- void masTardones(empleado * arr, int n){
- int mx =0;
- for(int i=0;i<n; i++){
- if(arr[i].tardanza>mx) mx = arr[i].tardanza;
- }
- for(int i=0;i<n; i++){
- if(arr[i].tardanza == mx){
- cout << "El empleado con indice " << i << " es el mas tardon\n";
- }
- }
- }
- void promedio_de_horas(empleado * arr, int n){
- char ofi[] = "CSL";
- for(int i=0;i<3; i++){
- int sum=0;
- int cont=0;
- for(int j=0;j<n; j++){
- if(arr[j].oficina==ofi[i]){
- sum+=arr[j].horas;
- cont++;
- }
- }
- cout << "La oficina " << ofi[i] << " tiene un promedio " << 1.0*sum/cont << endl;
- }
- }
- void masPuntuales(empleado * arr, int n){
- cout << "EMPLEADO PUNTUALES:\n";
- for(int i=0;i<n; i++){
- if(arr[i].tardanza==0){
- cout << i << (i<10? " ": "") <<"\t\t\t" << arr[i].horas << "\t\t\t" << arr[i].oficina << "\t\t\t\t" << arr[i].tardanza << endl;
- }
- }
- }
- void ordernar(empleado * arr, int n){
- for(int i=0; i<n; i++){
- for(int j=i+1; j<n; j++){
- if((arr[i].oficina < arr[j].oficina) || (arr[i].oficina==arr[j].oficina && arr[i].tardanza > arr[j].tardanza)){
- empleado aux = arr[i];
- arr[i] = arr[j];
- arr[j] = aux;
- }
- }
- }
- }
- int main(){
- srand(time(0));
- int n = 15;
- empleado * arreglo = GenerarArreglo(n);
- imprimirArreglo(arreglo, n);
- cout << endl;
- masTardones(arreglo, n);
- cout << endl;
- promedio_de_horas(arreglo, n);
- cout << endl;
- masPuntuales(arreglo,n);
- cout << endl;
- ordernar(arreglo, n);
- imprimirArreglo(arreglo, n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement