Quản lý sinh viên C++

HuanBuiThanh

 



# include <iostream> 

# include <fstream>

# include <iomanip>

using namespace std;


class SINHVIEN

{

protected:


    char masv[10];

    char hoten[25];

    char khoa[10];

    char lop[5];

    float TRR, CTDLGT, LTHDT;

   


public:

    void NHAP();

};

class CNPM : public SINHVIEN

{

protected:

    float PTTKHT, KNPM;

    float trungbinh_CNPM;

public:

    void NHAP_CNPM();

    void INRA_CNPM();

    void SUA_CNPM();

    float DTB_CNPM();


};


class QTM : public SINHVIEN

{

protected:

    float mangCB, mangNC;

    float trungbinh_QTM;

public:

    void NHAP_QTM();

    void INRA_QTM();

    void SUA_QTM();

    float DTB_QTM();

private:


};

void SINHVIEN::NHAP()

{

    

    cout << "Ma Sinh Vien : "; cin.getline(masv, 10);

    cout << "Ho va Ten:   "; cin.getline(hoten, 25);

    cout << "Khoa : "; cin.getline(khoa, 10);

    cout << "Lop : "; cin.getline(lop, 5);

    cout << "Diem Toan RR, CTDLGT, LTHDT: ";

    cin >> TRR >> CTDLGT >> LTHDT; cin.ignore();

}

void CNPM::NHAP_CNPM()

{

    CNPM pm;

    fstream FW;

    char ok;

    FW.open("CNPM.DAT", ios::out);

    cout << "\n Nhap ds sinh vien lop CNPM \n";

    while (1)

    {

        pm.NHAP();

        //float PTTKHT, KNPM;

        //float trungbinh_CNPM;

        cout << " Diem PT-K-HT : "; cin >> pm.PTTKHT; cin.ignore();

        cout << " Diem KNPM : "; cin >> pm.KNPM; cin.ignore();

        FW.write((char*)&pm, sizeof(pm));

        cout << "\n Tiep tuc (C/K) ?"; cin >> ok; cin.ignore();

        if (ok == 'k' || ok == 'K') break;


    }

    FW.close();

}

float CNPM::DTB_CNPM()

{

    return (TRR * 3 + CTDLGT * 4 + LTHDT * 4 + PTTKHT * 3 + KNPM * 3) / 17.0;

}

void CNPM::INRA_CNPM()

{

    CNPM pm;

    fstream FR;

    FR.open("CNPM.DAT", ios::in);

    if (FR.fail()) { cout << "\n Loi mo tep tin"; return; }

    cout << "\n Danh sach sinh vien lop CNPM \n";

    int TT = 1;

    while (FR.read((char*)&pm, sizeof(pm)))

    {

        cout << "\n" << setw(3) << TT << " ";

        cout << setw(10) << pm.masv << setw(25) << pm.hoten << setw(8) << pm.khoa

            << setw(7) << pm.lop << setw(4) << pm.TRR << setw(4) << pm.CTDLGT << setw(4) << pm.LTHDT << setw(4) << pm.KNPM << setw(4) << pm.PTTKHT << DTB_CNPM() << endl;

            //cin >> TRR >> CTDLGT >> LTHDT;

        TT = TT + 1;

    }

    FR.close();

}

void CNPM::SUA_CNPM()

{

    CNPM pm;

    fstream FW;

    int n; char ok;

    cout << "\n Nhap ban ghi can sua:";

    cin >> n; cin.ignore();

    FW.open("CNPM.DAT", ios::in | ios::out);

    if (FW.fail()) { cout << " \n Loi mo tep "; return; }

    cout << "\n nhap du lieu sua lai:\n ";

    cout << "Ma sinh vien: "; cin.getline(pm.masv, 10);

    cout << "Ho va ten : "; cin.getline(pm.masv, 25);

    cout << "Khoa : "; cin.getline(pm.khoa, 10);

    cout << "Lop : "; cin.getline(pm.lop, 5);

    cout << "Diem Toan RR, CTDLGT, LTHDT: ";

    cin >> pm.TRR >> pm.CTDLGT >> pm.LTHDT; cin.ignore();

    cout << " Diem PT-K-HT : "; cin >> pm.PTTKHT; cin.ignore();

    cout << " Diem KNPM : "; cin >> pm.KNPM; cin.ignore();

    cout << "\nNhap nua khong (C/K) ? ";


    cin >> ok; cin.ignore();


    FW.seekp((n - 1) * sizeof(pm)); //chuyen con tron den ban ghi thu n


    if (ok == 'c' || ok == 'C') FW.write((char*)&pm, sizeof(pm)); //ghi lai ban ghi


    FW.close();



}

void QTM::NHAP_QTM()

{

    QTM qtm;

    fstream FW;

    char ok;

    FW.open("QTM.DAT", ios::out);

    cout << "\n Nhap ds sinh vien lop QTM \n";

    while (1)

    {

        qtm.NHAP();

        //float PTTKHT, KNqtm;

        //float trungbinh_QTM;

        cout << " Diem Mang CB : "; cin >> qtm.mangCB; cin.ignore();

        cout << " Diem Mang NC : "; cin >> qtm.mangNC; cin.ignore();

        FW.write((char*)&qtm, sizeof(qtm));

        cout << "\n Tiep tuc (C/K) ?"; cin >> ok; cin.ignore();

        if (ok == 'k' || ok == 'K') break;


    }

    FW.close();

}

float QTM::DTB_QTM()

{

    return (TRR * 3 + CTDLGT * 4 + LTHDT * 4 + mangCB * 3 + mangNC * 3) / 17.0;

}

void QTM::INRA_QTM()

    QTM qtm;

    fstream FR;

    FR.open("QTM.DAT", ios::in);

    if (FR.fail()) { cout << "\n Loi mo tep tin"; return; }

    cout << "\n Danh sach sinh vien lop QTM \n";

    int TT = 1;

    while (FR.read((char*)&qtm, sizeof(qtm)))

    {

        cout << "\n" << setw(3) << TT << " ";

        cout << setw(10) << qtm.masv << setw(25) << qtm.hoten << setw(8) << qtm.khoa

            << setw(7) << qtm.lop << setw(4) << qtm.TRR << setw(4) << qtm.CTDLGT << setw(4) << qtm.LTHDT << setw(4) << qtm.mangCB << setw(4) << qtm.mangNC << DTB_QTM() << endl;

        //cin >> TRR >> CTDLGT >> LTHDT;

        TT = TT + 1;

    }

    FR.close();

}

void QTM::SUA_QTM()

{

    QTM qtm;

    fstream FW;

    int n; char ok;

    cout << "\n Nhap ban ghi can sua:";

    cin >> n; cin.ignore();

    FW.open("QTM.DAT", ios::in | ios::out);

    if (FW.fail()) { cout << " \n Loi mo tep "; return; }

    cout << "\n nhap du lieu sua lai:\n ";

    cout << "Ma sinh vien: "; cin.getline(qtm.masv, 10);

    cout << "Ho va ten : "; cin.getline(qtm.masv, 25);

    cout << "Khoa : "; cin.getline(qtm.khoa, 10);

    cout << "Lop : "; cin.getline(qtm.lop, 5);

    cout << "Diem Toan RR, CTDLGT, LTHDT: ";

    cin >> qtm.TRR >> qtm.CTDLGT >> qtm.LTHDT; cin.ignore();

    cout << " Diem mang CB : "; cin >> qtm.mangCB; cin.ignore();

    cout << " Diem Mang NC : "; cin >> qtm.mangNC; cin.ignore();

    cout << "\nNhap nua khong (C/K) ? ";


    cin >> ok; cin.ignore();


    FW.seekp((n - 1) * sizeof(qtm)); //chuyen con tron den ban ghi thu n


    if (ok == 'c' || ok == 'C') FW.write((char*)&qtm, sizeof(qtm)); //ghi lai ban ghi


    FW.close();



}

int main()

{

    CNPM pm;

    pm.NHAP_CNPM();

    pm.INRA_CNPM();

    pm.SUA_CNPM();

    pm.INRA_CNPM();


    QTM qtm;

    qtm.NHAP_QTM();

    qtm.INRA_QTM();

    qtm.SUA_QTM();

    qtm.INRA_QTM();

    cin.ignore();

}

Getting Info...

Đăng nhận xét

Cảm ơn bạn đã quan tâm và gửi nhận xét tại
http://huanbuithanh.blogspot.com
hãy ghé thăm blog hàng ngày để được cập nhật những thủ thuật mới nhất nhé . thân ái !
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.