#include<iostream>
#include<string>
using namespace std;
class hocsinh{
private:
string ten;
string lop;
float toan, ly,hoa,dtb;
public:
hocsinh(string ht=" ", string lh=" ",float t=0, float l=0, float h=0);
void nhap();
void xuat();
void dtbhon5();
};
hocsinh::hocsinh(string ht, string lh, float t, float l, float h){
this->ten=ht;
this->lop=lh;
this->toan=t;
this->ly=l;
this->hoa=h;
}
void hocsinh::nhap(){
cout<<"Nhap ho ten: "; getline(cin,ten);
cout<<"Nhap ten lop: ";getline(cin,lop);
cout<<"Nhap diem toan: ",cin>>toan;
cout<<"Nhap diem ly: ";cin>>ly;
cout<<"Nhap diem hoa: ";cin>>hoa;
dtb=(toan+ly+hoa)/3;
}
void hocsinh::xuat(){
cout<<"Hoc sinh: "<<ten<<" Lop: "<<lop<<" ";
cout<<"Diem toan: "<<toan<<" Diem ly: "<<ly;
cout<<" Diem hoa: "<<hoa<<" DTB: "<<dtb<<endl;
}
void hocsinh::dtbhon5(){
if(dtb>=5){
cout<<"Hoc sinh: "<<ten<<" Lop: "<<lop<<" ";
cout<<"Diem toan: "<<toan<<" Diem ly: "<<ly;
cout<<" Diem hoa: "<<hoa<<" DTB: "<<dtb<<endl;
}
}
int main(){
int n;
hocsinh *hs;
cout<<"Nhap danh sach hoc sinh: ";cin>>n;
hs=new hocsinh[n];
for(int i=0;i<n;i++)
hs[i].nhap();
cout<<endl<<"Danh sach hoc sinh :"<<endl;
for(int i=0;i<n;i++)
hs[i].xuat();
cout<<endl<<"Danh sach hoc sinh co diem trung binh >=5:"<<endl;
for(int i=0;i<n;i++)
hs[i].dtbhon5();
delete[] hs;
return0;
}
» Tin mới nhất:
» Các tin khác: