doancode300dong

 avatar
user_1746670
c_cpp
a month ago
6.2 kB
1
Indexable
Never
#include <bits/stdc++.h>
using namespace std;

/*
Copy những dòng sau để run đoạn code này:

3
Nguyen Van A
1998
27
Nguyen Thi B
1999
31
Le Van C
1980
20
2
Bui Thi D
2000
1500
50
Luong Van E
1995
2500
35
*/

#define ll long long

typedef struct NhanVienVanPhong {
	char hoTen[200];
	int namSinh;
	int soNgayLamViec;

	int luongHT; //luong hang thang
} VP;

typedef struct NhanVienSanXuat {
	char hoTen[200];
	int namSinh;
	float luongCanBan;
	int soSanPham;

	int luongHT; //luong hang thang
} SX;

typedef struct CongTy {
	int soVP;
	VP* dsVP;
	VP* VP_max;
	
	int soSX;
	SX* dsSX; 
	SX* SX_max;
} CT;

typedef struct ToHopNhanVien {
	char KieuNV[20]; //Nhan vien van phong hay nhan vien san xuat
	char hoTen[200];
	int namSinh;
	int luongHT;

	//doi voi nhan vien van phong
	int soNgayLamViec;

	//doi voi nhan vien san xuat
	int luongCanBan;
	int soSanPham;
} TH;

//1. Nhap, tao nhan vien
void khoiTao(CT &ct) {
	//Nhan vien van phong
	cout << "Nhap so NVVP: ";
	cin >> ct.soVP;
	ct.dsVP = new VP[ct.soVP];

	for (int i = 0; i < ct.soVP; i++) {
		cin.ignore();
		gets(ct.dsVP[i].hoTen);

		cin >> ct.dsVP[i].namSinh;

		cin >> ct.dsVP[i].soNgayLamViec;
	}

	//Nhan vien san xuat
	cout << "Nhap so NVSX: ";
	cin >> ct.soSX;
	ct.dsSX = new SX[ct.soSX];

	for (int i = 0; i < ct.soSX; i++) {
		cin.ignore();
		gets(ct.dsSX[i].hoTen);

		cin >> ct.dsSX[i].namSinh;

		cin >> ct.dsSX[i].luongCanBan;

		cin >> ct.dsSX[i].soSanPham;
	}
}

//2. Xuat, in danh sach nhan vien
void printf(CT ct) {
	cout << "DANH SACH NHAN VIEN VAN PHONG: " << endl;

	for (int i = 0; i < ct.soVP; i++) {
		cout << i + 1 << ". Nhan vien van phong " << i + 1 << endl;

		cout << "Ho va ten: " << ct.dsVP[i].hoTen << endl;
		cout << "Nam sinh: " << ct.dsVP[i].namSinh << endl;
		cout << "So ngay lam viec: " << ct.dsVP[i].soNgayLamViec << endl; 
	}

	cout << "------------------------------" << endl;

	cout << "DANH SACH NHAN VIEN SAN XUAT: " << endl;

	for (int i = 0; i < ct.soSX; i++) {
		cout << i + 1 << ". Nhan vien san xuat " << i + 1 << endl;

		cout << "Ho va ten: " << ct.dsSX[i].hoTen << endl;
		cout << "Nam sinh: " << ct.dsSX[i].namSinh << endl;
		cout << "Luong can ban: " << ct.dsSX[i].luongCanBan << endl;
		cout << "So san pham: " << ct.dsSX[i].soSanPham << endl;
	}
}

/*
3. Tinh tong luong phai tra cho nhan vien 
Input: 
	+ CongTy ct
Output:
	+ Tong luong => return int
*/
ll tongLuongHT_ALL(CongTy ct) {
	ll sum = 0;

	for (int i = 0; i < ct.soVP; i++) {
		ct.dsVP[i].luongHT = ct.dsVP[i].soNgayLamViec * 100000;
		sum += ct.dsVP[i].luongHT;
	}

	for (int i = 0; i < ct.soSX; i++) {
		ct.dsSX[i].luongHT = ct.dsSX[i].luongCanBan + ct.dsSX[i].soSanPham * 5000;
		sum += ct.dsSX[i].luongHT;
	}

	return sum;
}

/*
4. Tim cac nhan vien co tien luong lon nhat
Input:
	+ CongTy ct;
Output:
	+ Mang cac nhan vien
	+ Neu chi co 1 nhan vien có tien luong lon nhat => DS 1 phan tu
	+ Neu tu 2 nhan vien co tien luong lon nhat bang nhau => DS nhieu phan tu
*/
vector<VP> max_vp;
int mx_vp = 0;

vector<SX> max_sx;
int mx_sx = 0;
void Tim_TL_Max(CongTy ct) {
	for (int i = 0; i < ct.soVP; i++) {
		mx_vp = max(mx_vp, ct.dsVP[i].luongHT);
	}

	for (int i = 0; i < ct.soSX; i++) {
		mx_sx = max(mx_sx, ct.dsSX[i].luongHT);
	}

	for (int i = 0; i < ct.soVP; i++) {
		if (ct.dsVP[i].luongHT == mx_vp) {
			max_vp.push_back(ct.dsVP[i]);
		}
	}

	for (int i = 0; i < ct.soSX; i++) {
		if (ct.dsSX[i].luongHT == mx_sx) {
			max_sx.push_back(ct.dsSX[i]);
		}
	}
}


/*
5. Tim cac nhan vien tre nhat va tien luong lon nhat
Input:
	+ Danh sach nhan vien cong ty: CongTy ct
Output:
	+ Danh sach nhan vien tre nhat co tien luong lon nhat
*/
vector<TH> max_nv(20);
void Tim_TL_Max_uutientuoi (CongTy ct) {
	for (int i = 0; i < ct.soVP; i++) {
		strcpy(max_nv[i].KieuNV, "NVVP");
		strcpy(max_nv[i].hoTen, ct.dsVP[i].hoTen);
		max_nv[i].namSinh = ct.dsVP[i].namSinh;
		max_nv[i].soNgayLamViec = ct.dsVP[i].soNgayLamViec;
		max_nv[i].luongHT = ct.dsVP[i].luongHT;
	}

	for (int i = ct.soVP; i < ct.soVP + ct.soSX; i++) {
		strcpy(max_nv[i].KieuNV, "NVSX");
		strcpy(max_nv[i].hoTen, ct.dsSX[i - ct.soVP].hoTen);
		max_nv[i].namSinh = ct.dsSX[i - ct.soVP].namSinh;
		max_nv[i].luongCanBan = ct.dsSX[i - ct.soVP].luongCanBan;
		max_nv[i].soSanPham = ct.dsSX[i - ct.soVP].soSanPham;
		max_nv[i].luongHT = ct.dsSX[i - ct.soVP].luongHT;
	}

	for (int i = 0; i < (int)max_nv.size(); i++) {
		for (int j = i + 1; j < (int)max_nv.size(); j++) {
			if (max_nv[i].namSinh < max_nv[j].namSinh) {
				swap(max_nv[i], max_nv[j]);
			}
		}
	}
}


int main() {
	CongTy ct;

	//test 1: Nhap, khoi tao nhan vien
	cout << "TEST 1: " << endl;
	khoiTao(ct);
	cout << endl;

	//test 2: Xuat, in ds
	cout << "TEST 2: " << endl;
	printf(ct);
	cout << endl;

	//test 3: Tinh tong luong phai tra cho nhan vien 
	cout << "TEST 3: " << endl;
	ll sum = tongLuongHT_ALL(ct);
	cout << "Tong luong phai tra cua tat ca cac nhan vien: " << sum << endl;
	cout << endl;

	//test 4: Tim cac nhan vien co tien luong lon nhat
	cout << "TEST 4: " << endl;
	Tim_TL_Max(ct);
	cout << "Danh sach nhan vien co tien luong lon nhat: " << endl;
	int cnt = 1;

	if (mx_vp > mx_sx) {
		for (int i = 0; i < (int)max_vp.size(); i++) {
			cout << cnt << ". " << max_vp[i].hoTen << endl;
			cnt++;
		}
	}
	else if (mx_vp < mx_sx) {
		for (int i = 0; i < (int)max_sx.size(); i++) {
			cout << cnt << ". " << max_sx[i].hoTen << endl;
			cnt++;
		}
	}
	else {
		for (int i = 0; i < (int)max_vp.size(); i++) {
			cout << cnt << ". " << max_vp[i].hoTen << endl;
			cnt++;
		}
		for (int i = 0; i < (int)max_sx.size(); i++) {
			cout << cnt << ". " << max_sx[i].hoTen << endl;
			cnt++;
		}
	}
	cout << endl;

	//test 5: Tim cac nhan vien tre nhat (uu tien) va tien luong lon nhat
	cout << "TEST 5: " << endl;
	int min_namSinh = max_nv[0].namSinh;
	int cnt_2 = 1;

	for (int i = 0; i < (int)max_nv.size(); i++) {
		cout << max_nv[i].hoTen << endl;
	}
	cout << endl;

	return 0;
}

Leave a Comment