#include using namespace std; struct MedicalEquipment { string type; string ngaythang; string ten; int soluong; int dongia; }; MedicalEquipment ThietBi[100]; int so_luong = 0; //===================================== void clr() { system("cls"); } //===================================== void spau() { system("pause"); } //===================================== void readdata() { ifstream file; file.open("data.txt", ios::app); int i = 0; while (!file.eof()) { file >> ThietBi[i].type >> ThietBi[i].ngaythang >> ThietBi[i].ten >> ThietBi[i].soluong >> ThietBi[i].dongia; i++; } so_luong = i; file.close(); } //===================================== void writedata(int i) { // i la vi tri thiet bi ofstream file; file.open("data.txt", ios::app); file << ThietBi[i].type << '\n' << ThietBi[i].ngaythang << '\n' << ThietBi[i].ten << '\n' << ThietBi[i].soluong << '\n' << ThietBi[i].dongia << '\n'; file.close(); so_luong++; } //===================================== string get_current_date() { // lấy thời gian hiện tại time_t now = time(nullptr); tm *local_time = localtime(&now); // truy xuất ngày tháng năm int day = local_time->tm_mday; int month = local_time->tm_mon + 1; // tm_mon: 0-11 int year = local_time->tm_year + 1900; // tm_year: số năm kể từ 1900 // chuyển đổi sang định dạng string string date_str = to_string(day) + "/" + to_string(month) + "/" + to_string(year); return date_str; } //===================================== void nhaphang() { int soloaithietbi, i; cout << "\nSo loai thiet bi nhap vao: "; cin >> soloaithietbi; for (i = 0; i < soloaithietbi; i++) { ThietBi[i + so_luong].type = "nhap"; ThietBi[i + so_luong].ngaythang = get_current_date(); cout << "\nTen thiet bi: "; cin >> ThietBi[i + so_luong].ten; cout << "So luong: "; cin >> ThietBi[i + so_luong].soluong; cout << "Don gia: "; cin >> ThietBi[i + so_luong].dongia; writedata(i + so_luong); } // readdata(); // so_luong+=soloaithietbi; } //===================================== void xuathang() { int soloaithietbi, i; cout << "\nSo loai thiet bi xuat ra: "; cin >> soloaithietbi; for (i = 0; i < soloaithietbi; i++) { ThietBi[i + so_luong].type = "xuat"; ThietBi[i + so_luong].ngaythang = get_current_date(); cout << "Ten thiet bi: "; cin >> ThietBi[i + so_luong].ten; cout << "So luong: "; cin >> ThietBi[i + so_luong].soluong; cout << "Don gia: "; cin >> ThietBi[i + so_luong].dongia; writedata(i + so_luong); } // so_luong+=soloaithietbi; } void timkiem_lsnhap() { int n, dem = 0; cout << "Ban muon tim kiem bang gi:\n"; cout << "1.Ngay nhap hang:\n"; cout << "2.Ten thiet bi:\n"; cout << "Vui long chon: "; cin >> n; switch (n) { case 1: { cout << "Nhap ngay: "; string date; fflush(stdin); cin >> date; for (int i = 0; i < so_luong; i++) { if (date == ThietBi[i].ngaythang && ThietBi[i].type == "nhap") { cout << "\nNgay: " << ThietBi[i].ngaythang << "Ten: " << ThietBi[i].ten << "\nSo luong: " << ThietBi[i].soluong << "\nDon gia:" << ThietBi[i].dongia << "\n"; dem++; } } if (dem == 0) { cout << "Khong co lich su\n"; } spau(); } break; case 2: { cout << "Nhap ten thiet bi: "; string ten_thietbi; fflush(stdin); cin >> ten_thietbi; for (int i = 0; i < so_luong; i++) { if (ten_thietbi == ThietBi[i].ten && ThietBi[i].type == "nhap") { cout << "ngay: " << ThietBi[i].ngaythang << "\nSo luong: " << ThietBi[i].soluong << "\nDon gia:" << ThietBi[i].dongia << "\n\n"; dem++; } } if (dem == 0) { cout << "Khong co lich su\n"; } spau(); } break; default: break; } } //===================================== void timkiem_lsxuat() { int n, dem = 0; cout << "Ban muon tim kiem bang gi:\n"; cout << "1.Ngay nhap hang:\n"; cout << "2.Ten thiet bi:\n"; cout << "Vui long chon: "; cin >> n; switch (n) { case 1: { cout << "Nhap ngay: "; string date; fflush(stdin); cin >> date; for (int i = 0; i < so_luong; i++) { if (date == ThietBi[i].ngaythang && ThietBi[i].type == "xuat") { cout << "Ten: " << ThietBi[i].ten << "\nSo luong: " << ThietBi[i].soluong << "\nDon gia:" << ThietBi[i].dongia << "\n\n"; dem++; } } if (dem == 0) { cout << "Khong co lich su\n"; } spau(); } break; case 2: { cout << "Nhap ten thiet bi: "; string ten_thietbi; fflush(stdin); cin >> ten_thietbi; for (int i = 0; i < so_luong; i++) { if (ten_thietbi == ThietBi[i].ten && ThietBi[i].type == "xuat") { cout << "Ngay: " << ThietBi[i].ngaythang << "\nSo luong: " << ThietBi[i].soluong << "\nDon gia:" << ThietBi[i].dongia << "\n\n"; dem++; } } if (dem == 0) { cout << "Khong co lich su\n"; } spau(); } break; default: break; } } //===================================== void timkiem_soluong() { int t = 0; string tenthietbi; cout << "Ten thiet bi ban can tim la: "; // fflush(stdin); cin >> tenthietbi; for (int i = 0; i < so_luong; i++) { if (ThietBi[i].ten == tenthietbi) { if (ThietBi[i].type == "nhap") { t += ThietBi[i].soluong; } else { t -= ThietBi[i].soluong; } } } if (t != 0) { cout << "So " << tenthietbi << " con lai: " << t << "\n\n"; } else { cout << "Khong co thiet bi"; } spau(); } //===================================== void timkiem() { int n; cout << "Ban muon tim kiem gi:\n"; cout << "1, Lich su nhap hang.\n"; cout << "2, Lich su xuat hang.\n"; cout << "3, So luong hang con cua thiet bi.\n"; cout << "Vui long chon: "; cin >> n; switch (n) { case 1: timkiem_lsnhap(); break; case 2: timkiem_lsxuat(); break; case 3: timkiem_soluong(); break; default: break; } } //===================================== void menu() { int luachon; cout << " QUAN LI KHO THIET BI Y TE \n"; cout << "1. Nhap hang vao kho.\n"; cout << "2. Xuat hang ra kho.\n"; cout << "3. Tim kiem.\n"; cout << "4. Thoat.\n"; cout << "Vui long chon: "; cin >> luachon; switch (luachon) { case 1: nhaphang(); break; case 2: xuathang(); break; case 3: timkiem(); break; case 4: exit(0); break; default: cout << "Error\n"; spau(); break; } } int main() { readdata(); while (1) { clr(); menu(); }; return 0; }