Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //cho n nhan vien. Nhap, xuat, sap xep theo he so luong
- #include <iostream>
- using namespace std;
- struct Date {
- int dd, mm, yyyy;
- };
- struct Employee {
- char* name;
- Date d;
- float hsLuong;
- };
- void inputDate(Date& d)
- {
- cout << "Enter date : ";
- cin >> d.dd >> d.mm >> d.yyyy;
- }
- void displayDate(Date d) {
- (d.dd < 10) ? cout << 0 << d.dd << "/" : cout << d.dd << "/";
- (d.mm < 10) ? cout << 0 << d.mm << "/" << d.yyyy : cout << d.mm << "/" << d.yyyy;
- }
- Employee inputEmployee(Employee *p){
- p->name = new char[31];
- cout << "\nEnter name: ";
- cin.ignore();
- cin.getline(p->name, 31);
- inputDate(p->d);
- cout << "Enter Hsl: ";
- cin >> p->hsLuong;
- return *p;
- }
- void inputListEmployee(Employee **&e, int numOfEmployee)
- {
- e = new Employee*[numOfEmployee];
- cout << "Enter List Employee: ";
- for (int i = 0; i < numOfEmployee; i++)
- {
- e[i] = new Employee();
- inputEmployee(e[i]);
- }
- }
- void swap(Employee *A, Employee *B){
- Employee temp = *A;
- *A = *B;
- *B = temp;
- }
- void sortIncreasingBySalary(Employee **&e, int numOfEmployee)
- {
- for (int i = 0; i < numOfEmployee-1; i++)
- for (int j = i+1; j < numOfEmployee; j++)
- {
- if (e[i]->hsLuong > e[j]->hsLuong)
- swap(e[i], e[j]);
- }
- }
- void displayListEmployee(Employee **e, int numOfEmployee)
- {
- cout << "Info Employee: \n";
- cout << "--------------------\n";
- for (int i = 0; i < numOfEmployee; i++)
- {
- cout << e[i]->name << endl;
- displayDate(e[i]->d);
- cout << endl << e[i]->hsLuong << endl;
- }
- }
- int main()
- {
- int numOfEmployee;
- cout << "Enter number of Employee: "; cin >> numOfEmployee;
- Employee **s;
- inputListEmployee(s,numOfEmployee);
- sortIncreasingBySalary(s,numOfEmployee);
- displayListEmployee(s,numOfEmployee);
- delete[] s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement