Código
/* Leer 3 estructuras del arreglo "empleado" que contiene la siguiente info: nombre dirección ( calle, numero, localidad) edad sexo ( M = masculino, F = femenino) a) Listar los empleados menores de 25 anos b) Ordenar el vector por nombre y listarlo */ /*---- LIBRARIES ----*/ #include <iostream> #include <string> #define LEN 3 using std::cout; using std::cin; using std::endl; using std::string; /*---- FUNTIONS ----*/ void Read_Data(struct Employees people[],int); //Read input data void Less_25years(struct Employees people[],int); //Show the employees under 25 years old //--------------------------------------------------// //void Sorted_Data(); //sorted alphabetically <<<<----| Funtion //--------------------------------------------------// void Show_Data(struct Employees people[],int); //Show the employees names /*---- STRUCTS -----*/ struct Direction { char street[15]; char Number[15]; string local; }; struct Employees { string Naame; unsigned int age; char sex; struct Direction home; }; /*---- Main Funtion -----*/ int main() { cout << "********* STRUCT, INFO - EMPLOYEES **********\n\n"; struct Employees Data[LEN]; int i; Read_Data(Data,i); cout << "-------EMPLOYEES UNDER 25 YEARS OLD-------- \n\n"; Less_25years(Data,i); cout << "-------EMPLOYEES SORTED ALPHABETICALLY----- \n\n"; //---------------------------------------------------------// // funtion //sorted alphabetically (BUBBLE SORT) <<<----Here Funtion //--------------------------------------------------------// Show_Data(Data,i); //Show the employees names return 0; } /// READ_DATA FUNTION /// void Read_Data(struct Employees people[], int i) { for(i=0 ; i<LEN ; i++) { cout << "Employee Name: "; getline(cin,people[i].Naame); cout << "Age: "; cin >> people[i].age; cin.ignore(); cout << "Sex (M)-(F): "; cin >> people[i].sex; cin.ignore(); cout << "\nDIRECTION \n"; cout << "Street: "; cin.getline (people[i].home.street, 15); cout << "Number: "; cin.getline(people[i].home.Number, 15); cout << "Location: "; getline(cin,people[i].home.local); cout << endl; } } /// LESS_25years FUNTION /// void Less_25years(struct Employees people[],int i) { for(i=0 ; i<LEN ; i++) { if(people[i].age < 25) { cout << "Name: " << people[i].Naame << endl; cout << "Age: " << people[i].age<< endl; cout << "Sex: " << people[i].sex << endl; cout << "Street: " << people[i].home.street << endl; cout << "Number: " << people[i].home.Number << endl; cout << "Location: " << people[i].home.local << endl; } } cout << endl; } /// Sorted_Data FUNTION /// //Show the employees names sorted alphabetically /// SHOW_DATA FUNTION /// void Show_Data(struct Employees people[],int i) { for(i=0 ; i<LEN ; i++) { cout << "Name: " << people[i].Naame << endl; cout << "Age: " << people[i].age<< endl; cout << "Sex: " << people[i].sex << endl; cout << "Street: " << people[i].home.street << endl; cout << "Number: " << people[i].home.Number << endl; cout << "Location: " << people[i].home.local << endl; } }
Sugerencias sobre el programa, como mejorarlo o simplificarlo si es posible.....
PD: Que no sea con vectores ya que todavia no he visto el tema....jejeje estoy de autodidacta y no he llegado alli...