BÀI TẬP LỚN - ĐỀ SỐ 01 - IT05 - EHOU - năm học 2024 … #include #include #include #include using namespace std; struct MyPham { int id; string ten; double gia; }; struct HoaDon { int id; string ten_khach_hang; vector ds_my_pham; }; class QuanLyMyPham {
Trang 1BÀI TẬP LỚN - ĐỀ SỐ 01 - IT05 - EHOU - năm học 2024 …
Trang 2cout << "Nhap gia my pham: ";
Trang 3void suaMyPham(int id) {
for (size_t i = 0; i < ds_my_pham.size(); ++i) {
void xoaMyPham(int id) {
for (size_t i = 0; i < ds_my_pham.size(); ++i) {
if (ds_my_pham[i].id == id) {
Trang 4void timKiemMyPham(int id) {
for (size_t i = 0; i < ds_my_pham.size(); ++i) {
static bool soSanhTheoGia(MyPham a, MyPham b) {
return a.gia < b.gia;
}
void sapXepMyPhamTheoGia() {
sort(ds_my_pham.begin(), ds_my_pham.end(), soSanhTheoGia);
cout << "Danh sach my pham sau khi sap xep theo gia:" << endl;
Trang 7cout << "Nhap ID my pham can xoa: "; cin >> id_xoa;
}
} while (chon != 0);
return 0;
}
Trang 8class QuanLyMyPham {
private:
vector<MyPham> ds_my_pham; vector<HoaDon> ds_hoa_don;
Trang 9cout << "Nhap gia my pham: ";
Trang 10void suaMyPham(int id) {
for (size_t i = 0; i < ds_my_pham.size(); ++i) {
void xoaMyPham(int id) {
for (size_t i = 0; i < ds_my_pham.size(); ++i) {
if (ds_my_pham[i].id == id) {
Trang 11void timKiemMyPham(int id) {
for (size_t i = 0; i < ds_my_pham.size(); ++i) {
static bool soSanhTheoGia(MyPham a, MyPham b) {
return a.gia < b.gia;
}
void sapXepMyPhamTheoGia() {
sort(ds_my_pham.begin(), ds_my_pham.end(), soSanhTheoGia);
cout << "Danh sach my pham sau khi sap xep theo gia:" << endl;
Trang 14cout << "Nhap ID my pham can xoa: "; cin >> id_xoa;
}
} while (chon != 0);
return 0;
}
Trang 15BÀI TẬP LỚN ĐỀ SỐ 03 - IT05 - EHOU
class QuanLyDienThoai {
private:
vector<DienThoai> ds_dien_thoai; vector<HoaDon> ds_hoa_don;
Trang 17cout << "Nhap hang dien thoai: ";
void suaDienThoai(int id) {
for (size_t i = 0; i < ds_dien_thoai.size(); ++i) {
Trang 18}
cout << "Khong tim thay dien thoai voi ID nay!" << endl;
}
void xoaDienThoai(int id) {
for (size_t i = 0; i < ds_dien_thoai.size(); ++i) {
void timKiemDienThoai(int id) {
for (size_t i = 0; i < ds_dien_thoai.size(); ++i) {
static bool soSanhTheoGia(DienThoai a, DienThoai b) {
return a.gia < b.gia;
}
void sapXepDienThoaiTheoGia() {
sort(ds_dien_thoai.begin(), ds_dien_thoai.end(), soSanhTheoGia);
Trang 19cout << "Danh sach dien thoai sau khi sap xep theo gia:" << endl;
Trang 22cin >> gia;
ql.thongKeDienThoaiTheoGia(gia); break;
Trang 23cout << "ID: " << sv.id << ", Ten: " << sv.ten << endl;
for (size_t j = 0; j < sv.ds_mon_hoc.size(); ++j) {
Trang 24}
void themMonHoc(int id_sinh_vien) {
for (size_t i = 0; i < ds_sinh_vien.size(); ++i) {
void suaDiemMonHoc(int id_sinh_vien, int id_mon_hoc) {
for (size_t i = 0; i < ds_sinh_vien.size(); ++i) {
if (ds_sinh_vien[i].id == id_sinh_vien) {
for (size_t j = 0; j < ds_sinh_vien[i].ds_mon_hoc.size(); ++j) {
if (ds_sinh_vien[i].ds_mon_hoc[j].id == id_mon_hoc) { cout << "Nhap diem moi: ";
Trang 25cout << "Khong tim thay sinh vien hoac mon hoc voi ID nay!" << endl;
}
void xoaMonHoc(int id_sinh_vien, int id_mon_hoc) {
for (size_t i = 0; i < ds_sinh_vien.size(); ++i) {
void timKiemSinhVien(int id) {
for (size_t i = 0; i < ds_sinh_vien.size(); ++i) {
if (ds_sinh_vien[i].id == id) {
SinhVien sv = ds_sinh_vien[i];
cout << "ID: " << sv.id << ", Ten: " << sv.ten << endl;
for (size_t j = 0; j < sv.ds_mon_hoc.size(); ++j) {
Trang 26static bool soSanhTheoDiem(MonHoc a, MonHoc b) {
return a.diem < b.diem;
}
void sapXepMonHocTheoDiem(int id_sinh_vien) {
for (size_t i = 0; i < ds_sinh_vien.size(); ++i) {
if (ds_sinh_vien[i].id == id_sinh_vien) {
sort(ds_sinh_vien[i].ds_mon_hoc.begin(), ds_sinh_vien[i].ds_mon_hoc.end(),
soSanhTheoDiem);
cout << "Danh sach mon hoc sau khi sap xep theo diem:" << endl;
for (size_t j = 0; j < ds_sinh_vien[i].ds_mon_hoc.size(); ++j) {
Trang 27cout << "Khong tim thay sinh vien voi ID nay!" << endl;
void demSoLuongMonHoc(int id_sinh_vien) {
for (size_t i = 0; i < ds_sinh_vien.size(); ++i) {
Trang 29cout << "Nhap ID sinh vien: ";
cin >> id_sv;
ql.themMonHoc(id_sv);
break;
case 4:
int id_sv_sua, id_mh_sua;
cout << "Nhap ID sinh vien: ";
cin >> id_sv_sua;
cout << "Nhap ID mon hoc: ";
cin >> id_mh_sua;
ql.suaDiemMonHoc(id_sv_sua, id_mh_sua); break;
case 5:
int id_sv_xoa, id_mh_xoa;
cout << "Nhap ID sinh vien: ";
cin >> id_sv_xoa;
cout << "Nhap ID mon hoc: ";
cin >> id_mh_xoa;
ql.xoaMonHoc(id_sv_xoa, id_mh_xoa); break;
Trang 33cout << "Nhap ID sach: ";
void suaSach(int id) {
for (size_t i = 0; i < ds_sach.size(); ++i) {
if (ds_sach[i].id == id) {
cout << "Nhap ten moi: ";
cin.ignore();
getline(cin, ds_sach[i].ten);
Trang 34cout << "Nhap ten tac gia moi: ";
void xoaSach(int id) {
for (size_t i = 0; i < ds_sach.size(); ++i) {
void timKiemSach(int id) {
for (size_t i = 0; i < ds_sach.size(); ++i) {
Trang 35static bool soSanhTheoNamXuatBan(Sach a, Sach b) {
return a.nam_xuat_ban < b.nam_xuat_ban;
}
void sapXepSachTheoNamXuatBan() {
sort(ds_sach.begin(), ds_sach.end(), soSanhTheoNamXuatBan);
cout << "Danh sach sach sau khi sap xep theo nam xuat ban:" << endl;
Trang 36for (size_t i = 0; i < ds_sach.size(); ++i) {
Trang 38cout << "Nhap nam xuat ban de thong ke: "; cin >> nam;
ql.thongKeSachTheoNamXuatBan(nam); break;
Trang 39cout << "ID: " << kh.id << ", Ten: " << kh.ten << endl;
for (size_t j = 0; j < kh.ds_don_hang.size(); ++j) {
void themDonHang(int id_khach_hang) {
for (size_t i = 0; i < ds_khach_hang.size(); ++i) {
Trang 40void suaDonHang(int id_khach_hang, int id_don_hang) {
for (size_t i = 0; i < ds_khach_hang.size(); ++i) {
if (ds_khach_hang[i].id == id_khach_hang) {
for (size_t j = 0; j < ds_khach_hang[i].ds_don_hang.size(); ++j) {
if (ds_khach_hang[i].ds_don_hang[j].id == id_don_hang) { cout << "Nhap ten san pham moi: ";
cin.ignore();
getline(cin, ds_khach_hang[i].ds_don_hang[j].ten_san_pham); cout << "Nhap so luong moi: ";
void xoaDonHang(int id_khach_hang, int id_don_hang) {
for (size_t i = 0; i < ds_khach_hang.size(); ++i) {
Trang 41if (ds_khach_hang[i].id == id_khach_hang) {
for (size_t j = 0; j < ds_khach_hang[i].ds_don_hang.size(); ++j) {
if (ds_khach_hang[i].ds_don_hang[j].id == id_don_hang) {
ds_khach_hang[i].ds_don_hang.erase(ds_khach_hang[i].ds_don_hang.begin() + j); cout << "Xoa thanh cong!" << endl;
void timKiemKhachHang(int id) {
for (size_t i = 0; i < ds_khach_hang.size(); ++i) {
if (ds_khach_hang[i].id == id) {
KhachHang kh = ds_khach_hang[i];
cout << "ID: " << kh.id << ", Ten: " << kh.ten << endl;
for (size_t j = 0; j < kh.ds_don_hang.size(); ++j) {
static bool soSanhTheoGia(DonHang a, DonHang b) {
return a.gia < b.gia;
}
Trang 42void sapXepDonHangTheoGia(int id_khach_hang) {
for (size_t i = 0; i < ds_khach_hang.size(); ++i) {
if (ds_khach_hang[i].id == id_khach_hang) {
sort(ds_khach_hang[i].ds_don_hang.begin(), ds_khach_hang[i].ds_don_hang.end(), soSanhTheoGia);
cout << "Danh sach don hang sau khi sap xep theo gia:" << endl;
for (size_t j = 0; j < ds_khach_hang[i].ds_don_hang.size(); ++j) {
Trang 43void demSoLuongDonHang(int id_khach_hang) {
for (size_t i = 0; i < ds_khach_hang.size(); ++i) {
Trang 45break;
case 4:
int id_kh_sua, id_dh_sua;
cout << "Nhap ID khach hang: "; cin >> id_kh_sua;
cout << "Nhap ID don hang: ";
cin >> id_dh_sua;
ql.suaDonHang(id_kh_sua, id_dh_sua); break;
case 5:
int id_kh_xoa, id_dh_xoa;
cout << "Nhap ID khach hang: "; cin >> id_kh_xoa;
cout << "Nhap ID don hang: ";
cin >> id_dh_xoa;
ql.xoaDonHang(id_kh_xoa, id_dh_xoa); break;
case 8:
int id_kh_tong;
cout << "Nhap ID khach hang: ";
Trang 48cout << "ID: " << nv.id << ", Ten: " << nv.ten << ", Chuc vu: " << nv.chuc_vu << ", Luong: "
<< nv.luong << endl;
}
}
void suaNhanVien(int id) {
for (size_t i = 0; i < ds_nhan_vien.size(); ++i) {
void xoaNhanVien(int id) {
for (size_t i = 0; i < ds_nhan_vien.size(); ++i) {
Trang 49for (size_t i = 0; i < ds_nhan_vien.size(); ++i) {
static bool soSanhTheoLuong(NhanVien a, NhanVien b) {
return a.luong < b.luong;
}
void sapXepNhanVienTheoLuong() {
sort(ds_nhan_vien.begin(), ds_nhan_vien.end(), soSanhTheoLuong);
cout << "Danh sach nhan vien sau khi sap xep theo luong:" << endl;
Trang 51case 7:
ql.tongLuongNhanVien();
break;
case 8:
Trang 53void suaHocSinh(int id) {
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
if (ds_hoc_sinh[i].id == id) {
cout << "Nhap ten moi: ";
cin.ignore();
getline(cin, ds_hoc_sinh[i].ten);
Trang 54cout << "Nhap diem toan moi: ";
void xoaHocSinh(int id) {
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
void timKiemHocSinh(int id) {
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
Trang 55}
static bool soSanhTheoDiemTrungBinh(HocSinh a, HocSinh b) {
double dtb_a = (a.diem_toan + a.diem_van + a.diem_anh) / 3;
double dtb_b = (b.diem_toan + b.diem_van + b.diem_anh) / 3;
}
void tongDiemHocSinh() {
double tong_toan = 0, tong_van = 0, tong_anh = 0;
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
tong_toan += ds_hoc_sinh[i].diem_toan;
tong_van += ds_hoc_sinh[i].diem_van;
tong_anh += ds_hoc_sinh[i].diem_anh;
}
cout << "Tong diem Toan cua cac hoc sinh: " << tong_toan << endl;
cout << "Tong diem Van cua cac hoc sinh: " << tong_van << endl;
cout << "Tong diem Anh cua cac hoc sinh: " << tong_anh << endl;
Trang 56for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
double dtb = (ds_hoc_sinh[i].diem_toan + ds_hoc_sinh[i].diem_van +
Trang 57cout << "1 Nhap hoc sinh\n2 In danh sach hoc sinh\n3 Sua hoc sinh\n4 Xoa hoc sinh\n5 Tim kiem hoc sinh\n";
cout << "6 Sap xep hoc sinh theo diem trung binh\n7 Tong diem hoc sinh\n8 Diem trung binh cua hoc sinh\n9 Dem so luong hoc sinh\n";
cout << "10 Thong ke hoc sinh theo diem\n0 Thoat\nChon: ";
Trang 60for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
void xoaHocSinh(int id) {
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
if (ds_hoc_sinh[i].id == id) {
ds_hoc_sinh.erase(ds_hoc_sinh.begin() + i); cout << "Xoa thanh cong!" << endl;
void timKiemHocSinh(int id) {
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
if (ds_hoc_sinh[i].id == id) {
HocSinh hs = ds_hoc_sinh[i];
Trang 61cout << "ID: " << hs.id << ", Ten: " << hs.ten << ", Diem Toan: " << hs.diem_toan << ", Diem Van: " << hs.diem_van << ", Diem Anh: " << hs.diem_anh << endl;
static bool soSanhTheoDiemTrungBinh(HocSinh a, HocSinh b) {
double dtb_a = (a.diem_toan + a.diem_van + a.diem_anh) / 3;
double dtb_b = (b.diem_toan + b.diem_van + b.diem_anh) / 3;
return dtb_a < dtb_b;
}
void sapXepHocSinhTheoDiemTrungBinh() {
sort(ds_hoc_sinh.begin(), ds_hoc_sinh.end(), soSanhTheoDiemTrungBinh);
cout << "Danh sach hoc sinh sau khi sap xep theo diem trung binh:" << endl;
inDanhSachHocSinh();
}
void tongDiemHocSinh() {
double tong_toan = 0, tong_van = 0, tong_anh = 0;
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
tong_toan += ds_hoc_sinh[i].diem_toan;
tong_van += ds_hoc_sinh[i].diem_van;
tong_anh += ds_hoc_sinh[i].diem_anh;
}
cout << "Tong diem Toan cua cac hoc sinh: " << tong_toan << endl;
cout << "Tong diem Van cua cac hoc sinh: " << tong_van << endl;
cout << "Tong diem Anh cua cac hoc sinh: " << tong_anh << endl;
}
void trungBinhDiemHocSinh() {
Trang 62if (ds_hoc_sinh.empty()) {
cout << "Khong co hoc sinh nao trong danh sach!" << endl;
return;
}
double tong_toan = 0, tong_van = 0, tong_anh = 0;
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
for (size_t i = 0; i < ds_hoc_sinh.size(); ++i) {
double dtb = (ds_hoc_sinh[i].diem_toan + ds_hoc_sinh[i].diem_van +
Trang 64ql.timKiemHocSinh(id_tim);
break;
case 6:
ql.sapXepHocSinhTheoDiemTrungBinh(); break;
Trang 66}
}
void suaDoDienTu(int id) {
for (size_t i = 0; i < ds_do_dien_tu.size(); ++i) {
void xoaDoDienTu(int id) {
for (size_t i = 0; i < ds_do_dien_tu.size(); ++i) {
if (ds_do_dien_tu[i].id == id) {
ds_do_dien_tu.erase(ds_do_dien_tu.begin() + i); cout << "Xoa thanh cong!" << endl;
Trang 67void timKiemDoDienTu(int id) {
for (size_t i = 0; i < ds_do_dien_tu.size(); ++i) {
static bool soSanhTheoGia(DoDienTu a, DoDienTu b) {
return a.gia < b.gia;
}
void sapXepDoDienTuTheoGia() {
sort(ds_do_dien_tu.begin(), ds_do_dien_tu.end(), soSanhTheoGia);
cout << "Danh sach do dien tu sau khi sap xep theo gia:" << endl;
inDanhSachDoDienTu();
}
void tongGiaTriDoDienTu() {
double tong = 0;
for (size_t i = 0; i < ds_do_dien_tu.size(); ++i) {
tong += ds_do_dien_tu[i].gia * ds_do_dien_tu[i].so_luong;
Trang 68return;
}
double tong = 0;
int so_luong_tong = 0;
for (size_t i = 0; i < ds_do_dien_tu.size(); ++i) {
tong += ds_do_dien_tu[i].gia * ds_do_dien_tu[i].so_luong;
Trang 69cout << "6 Sap xep do dien tu theo gia\n7 Tong gia tri do dien tu\n8 Gia tri trung binh cua do dien tu\n9 Dem so luong do dien tu\n";
cout << "10 Thong ke do dien tu theo gia\n0 Thoat\nChon: ";