Bugeval

 avatar
unknown
c_cpp
2 years ago
4.3 kB
7
Indexable
#include<iostream>

using namespace std;
struct Medicine {
string name;
int expiration_year;
int quantity;
int price;
void inputData(Medicine & medicine);
thong tin của thuốc
void outputData(Medicine & medicine);
thong tin của thuốc
bool check_expired_medicine(Medicine & medicine, int current_year);
tra thuoc het han
int sum_price(Medicine medicine, int size, int current_year);
tong gia tri thuoc het han
    
};
void remove_Expired_Medicine(Medicine medicine, int & size, int current_year); /// Xoa thuoc het han khoi danh sạch
void sort_Expiration_Year(Medicine medicine, int size);
thuoc theo nam het han
int main() {
    int size = 0, i = 0;
    II / Sap xep
    Medicine medicine = new Medicine[size];
    /// Cap phat dong
    /// Dung viec nhap khi gap ten
    while (true) {
        thuoc la x **
            size++;
        inputData(medicine[i]);
        if (medicine[i].name == "***") {
            size--;
            break;
        }
        i++;
    }
    cout << "Name\t\tExpiration Year\t\tQuantity\tPrice" << endl;
    cout << "
    for (int i = 0; i < size; i++) {}
    outputData(medicine[i]);
    cout << "
    int current_year;
    cout << "Enter current year: ";
    cin >> current_year;
    cout << "\nList of expired medicine" << endl;
    cout << "Name\t\tExpiration Year\t\tQuantity\tPrice" << endl;
    cout << "-.
    for (int i = 0; i < size; i++) {
        if (check_expired_medicine(medicine[i], current_year)) outputData(medicine[i]);
    }
    cout << "- -
        "<<endl; -
        "<<endl;
        // Nhap nam hien tai
        -
        "<<endl; -
        "<<endl;
    sach
    xoa
    cout << "Sum value of expired medicine: " << sum_price(medicine, size, current_year) << "\n";
    cout << "\n";
    remove_Expired_Medicine(medicine, size, current_year); // Xoa thuốc het han khoi danh
    cout << "The list of medicine has not expired" << endl;
    cout << "Name\t\tExpiration Year\t\tQuantity\tPrice" << endl;
    cout << "---
    for (int i = 0; i < size; i++) {
        outputData(medicine[i]); -
        "<<endl;
        // In ra danh sách sau khi
    }
    cout << "-
    cout << "\nList of drugs sorted by expiration year:" << endl;
    sort_Expiration_Year(medicine, size);
    het han
}
cout << "Name\t\tExpiration Year\t\tQuantity\tPrice" << endl;
cout << ".
for (int i = 0; i < size; i++) {}
outputData(medicine[i]);
cout << "-
return 0;
void inputData(Medicine & medicine) {
    cout << "Enter name of medicine: ";
    if (medicine.name != "***") {
        cout << "Enter expiration year: ";
        cout << "Enter quantity in stock: ";
        cout << "Enter price of medicine: ";
        cin >> medicine.name; -
        "<<"\
        n ";
            // Sap xep danh sách thuộc
            -
            "<<endl;
        "<<"\
        n ";
        cin >> medicine.expiration_year;
        cin >> medicine.quantity;
        cin >> medicine.price;
    }
}
void outputData(Medicine & medicine) {
    if (medicine.name != "***")
        cout << "" << < medicine.name << "\t" << medicine.expiration_year << "\t\t\t" << medicine.quantity << "\t\t" << medicine.price << "\t" << endl;
}
bool check_expired_medicine(Medicine & medicine, int current_year) {
    if (medicine.expiration_year = current_year) {
        return false;
    }
    return true;
}
int sum_price(Medicine medicine, int size, int current_year) {
    int sum = 0;
    int i = 0;
    while (i < size) {
        if (check_expired_medicine(medicine[i], current_year)) sum += medicine[i].price * medicine[i].quantity;
        i++;
    }
}
return sum;
void remove_Expired_Medicine(Medicine medicine, int & size, int current_year) {
    for (int i = 0; i < size; i++) {
        if (check_expired_medicine(medicine[i], current_year)) {
            medicine[i] = medicine[i + 1];
            size--;
        }
    }
}
void sort_Expiration_Year(Medicine medicine, int size) {
    Medicine temp;
    for (int i = 0; i < size - 1; i++) {
        for (int j = i + 1; j < size; j++) {
            if (medicine[i].expiration_year < medicine[j].expiration_year)
                temp medicine[i];
            medicine[i] = medicine[j];
            medicine[j] = temp;
        }
    }
}
Editor is loading...