ke thua public
Ke thua public
#include"stdio.h"
#include"conio.h"
#include"string.h"
#include"iostream.h"
#include"iomanip.h"
class sinhvien
{ private:
char sbd[5];
char ten[35];
public:
void nhap();
void xuat();
};
void sinhvien::nhap()
{ cout<<"
Nhap so bao danh: "; gets(sbd);
cout<<"
Nhap ho ten: ";gets(ten);
}
void sinhvien::xuat()
{cout<<setw(5)<<sbd<<setw(40)<<ten;}
class diemthi:public sinhvien
{ private:
float m1,m2,m3;
public:
void nhapd();
void xuatd();
float tinhtong()
{return(m1+m2+m3);}
};
void diemthi::nhapd()
{ cout<<"
Nhap diem mon 1: ";cin>>m1;
cout<<"
Nhap diem mon 2: ";cin>>m2;
cout<<"\ Nhap diem mon 3: ";cin>>m3;
}
void diemthi::xuatd()
{cout<<setw(5)<<m1<<setw(5)<<m2<<setw(5)<<m3;}
class ketqua:public diemthi
{ private:
float tong;
public:
void kq()
{tong=tinhtong();
cout<<setw(5)<<tong;}
friend void maxtong(ketqua *sv, int n);
};
void maxtong(ketqua *sv,int n)
{ int i;
float max;
max=sv[1].tinhtong();
for(i=2;i<=n;i++)
if(max<=sv[i].tinhtong())
max=sv[i].tinhtong();
cout<<"
nguoi co tong diem lon nhat la;"<<"
";
cout<<"
sbd hoten mon1 mon2 mon3 tong";
for(i=1;i<=n;i++)
if(sv[i].tinhtong()==max)
{sv[i].xuat();
sv[i].xuatd();
sv[i].kq();
} }
void main()
{int i,n;
ketqua sv[50];
cout<<"
nhap n=";cin>>n;
cout<<"nhap ds
";
for(i=1;i<=n;i++)
{cout<<"nhap ban ghi thu"<<i<<"
";
sv[i].nhap();
sv[i].nhapd();
}
cout<<"
danh sach vua nhap la:"<<"
";
cout<<"
sbd hoten mon1 mon2 mon3 tong";
for(i=1;i<=n;i++)
{ sv[i].xuat();sv[i].xuatd();sv[i].kq();}
maxtong(sv,n);
getch();
}
Bạn đang đọc truyện trên: Truyen247.Pro