Bài tập Class trong C++

HuanBuiThanh

 




#include <iostream>

#include <iomanip>

#include <conio.h> 

using namespace std;


class SINHVIEN

{

protected:

char masv[10], hoten[25], khoa[10];

float T_Anh, Tin_CS;

public:

void NHAP();

void INRA();

};


class SV_TOAN : public SINHVIEN

{

protected:

float Giai_tich, Dai_so;

public:

void NHAP_SV_TOAN();

void INRA_SV_TOAN();

double DTB_SV_TOAN();

};


class SV_TIN : public SINHVIEN

{

protected:

float NN_C, CT_DL;

public:

void NHAP_SV_TIN();

void INRA_SV_TIN();

double DTB_SV_TIN();

};


void SINHVIEN::NHAP()

{

cout << "So bao danh: "; cin.getline(masv, 10);

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

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

cout << "Diem : T_Anh, Tin_CS; ";

cin >> T_Anh >> Tin_CS; cin.ignore();

}


void SINHVIEN::INRA()

{

cout << setw(10) << masv << setw(25) << hoten

<< setw(10) << khoa << setw(10)

<< setw(5) << T_Anh << setw(5) << Tin_CS;

}


void SV_TOAN::NHAP_SV_TOAN()

{

NHAP();

cout << " Giai Tich: ";

cin >> Giai_tich; cin.ignore();

cout << "Dai so: ";

cin >> Dai_so; cin.ignore();

}


void SV_TOAN::INRA_SV_TOAN()

{

INRA();

cout << setw(5) << Giai_tich << setw(5) << Dai_so

<< setw(10) << DTB_SV_TOAN() << "\n";

}


double SV_TOAN::DTB_SV_TOAN()

{

return (T_Anh + Tin_CS + Giai_tich + Dai_so ) / 4.0;

}


void SV_TIN::NHAP_SV_TIN()

{

NHAP();

cout << "Diem Ngon ngu C : ";

cin >> NN_C; cin.ignore();

cout << " Cau Truc Du Lieu: ";

cin >> CT_DL;

}


void SV_TIN::INRA_SV_TIN()

{

INRA();

cout << setw(5) << NN_C << setw(5) << CT_DL

<< setw(10) << DTB_SV_TIN() << "\n";

}


double SV_TIN::DTB_SV_TIN()

{

return (T_Anh + Tin_CS + NN_C + CT_DL) / 4.0;

}


class DS_SV_TOAN

{

SV_TOAN P[100];

int i = 0;


public:

void NHAP_DANHSACH()

{

char ok;

while (i < 100)

{

P[i].NHAP_SV_TOAN();

i++;


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

cin >> ok; cin.ignore();

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

}

}


void IN_DANHSACH()

{

cout << "\n\t\tDANH SACH SINH VIEN LOP TOAN\n";

for (int j = 0; j < i; j++)

P[j].INRA_SV_TOAN();

}


int SOSV_TOAN7()

{

int s = 0;

for (int j = 0; j < i; j++)

if (P[j].DTB_SV_TOAN() >= 7) s++;

return s;

}

};


class DS_SV_TIN

{

SV_TIN P[100];

int i = 0;


public:

void NHAP_DANHSACH()

{

char ok;

while (i < 100)

{

P[i].NHAP_SV_TIN();

i++;


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

cin >> ok; cin.ignore();

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

}

}


void IN_DANHSACH()

{

cout << "\n\t\tDANH SACH SINH VIEN LOP TIN\n";

for (int j = 0; j < i; j++)

P[j].INRA_SV_TIN();

}


int SOSV_TIN7()

{

int s = 0;

for (int j = 0; j < i; j++)

if (P[j].DTB_SV_TIN() >= 7) s++;

return s;

}

};


int main()

{

cout << "\nNhap thong tin sinh vien mon Toan: "<<endl;

DS_SV_TOAN svtoan;

svtoan.NHAP_DANHSACH();

svtoan.IN_DANHSACH();

cout << "\nSo SV Toan co diem trung binh lon hon 7 la: " << svtoan.SOSV_TOAN7();


cout << "\nNhap thong tin sinh vien mon Tin: "<<endl;

DS_SV_TIN svtin;

svtin.NHAP_DANHSACH();

svtin.IN_DANHSACH();

cout << "\nSo SV Toan co diem trung binh lon hon 7 la: " << svtin.SOSV_TIN7();


}


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.