.debai22
Bai 22
//Tinh diem cua sinh vien
#include <iostream>
#include <string.h>
using namespace std;
//Khai bao lop sinh vien
class SinhVien
{
private:
char hoten[40],ns[12],lop[11];
float dccan,dktra,dthi,dmhoc;
public:
void nhap();
const char* getHoten();
const char* getTen();
const char* getNS();
const char* getLop();
float getDiemMH();
};
//========CHUONG TRINH CHINH===========
int main()
{
SinhVien ds[100];
SinhVien tg;
int n,i,j;
cout<<"So sinh vien can nhap? ";cin>>n;cin.ignore();
cout<<"Nhap du lieu cho cac sinh vien:
";
for(i=0;i<n;i++)
{
cout<<"Sinh vien thu "<<(i+1)<<":
"; ds[i].nhap();
}
//Sap xep danh sach sinh vien
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(strcmp(ds[j].getTen(),ds[i].getTen())<0)
{
tg=ds[i];ds[i]=ds[j];ds[j]=tg;
}
//Dua ra man hinh cac sinh vien co diem < 5
cout<<"\t\tDANH SACH SINH VIEN CO DIEM <5
";
cout.setf(ios::left);cout.precision(2);
cout.width(5);cout<<"STT";
cout.width(25);cout<<"Ho va ten";
cout.width(12);cout<<"Ngay sinh";
cout.width(10);cout<<"Lop";
cout.width(8);cout<<"DiemMH";
cout<<endl;
for(i=0;i<n;i++)
if(ds[i].getDiemMH()<5)
{
cout.width(5);cout<<(i+1);
cout.width(25);cout<<ds[i].getHoten();
cout.width(12);cout<<ds[i].getNS();
cout.width(10);cout<<ds[i].getLop();
cout.width(8);cout<<ds[i].getDiemMH();
cout<<endl;
}
cout.precision(0);
return 0;
//cout<<"\t}
//=====Dinh nghia cac ham======
void SinhVien::nhap()
{
cout<<"\tHo ten: ";cin.get(hoten,sizeof(hoten));cin.ignore();
cout<<"\tNgay sinh: ";cin.get(ns,sizeof(ns));cin.ignore();
cout<<"\tLop: ";cin.get(lop,sizeof(lop));cin.ignore();
cout<<"\tDiem CCan: ";cin>>dccan;cin.ignore();
cout<<"\tDiem KTra: ";cin>>dktra;cin.ignore();
cout<<"\tDiem Thi: ";cin>>dthi;cin.ignore();
dmhoc=0.1*dccan+0.3*dktra+0.6*dthi;
}
//----------------------
const char* SinhVien::getHoten()
{
return hoten;
}
//----------------------
const char* SinhVien::getTen()
{
char* p;
p=hoten; //Cho p tro vao dau xau ky tu
p=p+strlen(hoten)-1; //Cho p tro vao cuoi xau ky tu
while(*p!=' ') p--; //Tim ky tu cach
p++; //cho p tro vao ky tu dau tien cua ten
return p; //Tra ve ten
}
//-----------------------
const char* SinhVien::getNS()
{
return ns;
}
//-----------------------
const char* SinhVien::getLop()
{
return lop;
}
//-----------------------
float SinhVien::getDiemMH()
{
return dmhoc;
}
Bạn đang đọc truyện trên: Truyen247.Pro