bai6_sinhvien
#include"stdio.h"
#include"conio.h"
#include"iostream.h"
#include"iomanip.h"
#include"math.h"
class sinhvien
{
private:
char masv[5];
char hoten[35];
char noisinh[35];
char lop[10];
public:
void nhap();
void xuat();
};
void sinhvien::nhap()
{
cout<<"
Nhap ma sinh vien:"; gets(masv);
cout<<"
Nhap ho ten:"; gets(hoten);
cout<<"
Nhap noi sinh:"; gets(noisinh);
cout<<"
Nhap lop:"; gets(lop);
}
void sinhvien::xuat()
{
cout<<"
"<<setw(5)<<masv<<setw(10)<<hoten<<setw(10)<<noisinh<<setw(8)<<lop;
}
class xahoi:public sinhvien
{
private:
float mon1;
float mon2;
float dtb;
public:
void nhapxh();
void xuatxh();
friend void sapxep(xahoi *sv,int n);
friend void hocbong(xahoi *sv,int n);
};
void xahoi::nhapxh()
{
nhap();
cout<<"
Nhap diem mon 1:"; cin>>mon1;
cout<<"
Nhap diem mon 2:"; cin>>mon2;
dtb=(mon1+mon2)/2;
}
void xahoi::xuatxh()
{
xuat();
cout<<setw(3)<<mon1<<setw(10)<<mon2<<setw(10)<<dtb;
}
void sapxep(xahoi *sv,int n)
{
int i,j;
xahoi tg;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
if(sv[i].dtb>sv[j].dtb)
{
tg=sv[i];
sv[i]=sv[j];
sv[j]=tg;
}
}
void hocbong(xahoi *sv,int n)
{
int i,t;
t=n*10/100;
sapxep(sv,n);
cout<<"
Danh sach sinh vien dat hoc bong khoa xa hoi la:";
cout<<"
Masv hoten noisinh lop diemtoan diemly DTB";
for(i=1;i<=t;i++)
if(sv[i].dtb>=7)
sv[i].xuatxh();
}
class tunhien:public sinhvien
{
private:
float diemtoan;
float diemly;
float dtb;
public:
void nhaptn();
void xuattn();
friend void sapxep(tunhien *sv,int n);
friend void hocbong(tunhien *sv,int n);
};
void tunhien::nhaptn()
{
nhap();
cout<<"
Nhap diem toan:"; cin>>diemtoan;
cout<<"
Nhap diem ly:"; cin>>diemly;
dtb=(diemtoan+diemly)/2;
}
void tunhien::xuattn()
{
xuat();
cout<<setw(3)<<diemtoan<<setw(10)<<diemly<<setw(10)<<dtb;
}
void sapxep(tunhien *sv,int n)
{
int i,j;
tunhien tg;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
if(sv[i].dtb>sv[j].dtb)
{
tg=sv[i];
sv[i]=sv[j];
sv[j]=tg;
}
}
void hocbong(tunhien *sv,int n)
{
int i,t;
t=n*10/100;
sapxep(sv,n);
cout<<"
Danh sach sinh vien dat hoc bong khoa tu nhien la:";
cout<<"
Masv hoten noisinh lop diemtoan diemly DTB";
for(i=1;i<=t;i++)
if(sv[i].dtb>=7)
sv[i].xuattn();
}
void main()
{
xahoi svxh[50];
tunhien svtn[50];
int i,n,m;
clrscr();
cout<<"
Nhap so sinh vien khoa xa hoi n="; cin>>n;
for(i=1;i<=n;i++)
svxh[i].nhapxh();
cout<<"
Danh sach sinh vien khoa xa hoi sau khi nhap la:";
cout<<"
Masv hoten noisinh lop diemtoan diemly DTB";
for(i=1;i<=n;i++)
svxh[i].xuatxh();
hocbong(svxh,n);
cout<<"
Nhap so sinh vien khoa tu nhien m="; cin>>m;
for(i=1;i<=m;i++)
svtn[i].nhaptn();
cout<<"
Danh sach sinh vien khoa tu nhien sau khi nhap la:";
cout<<"
Masv hoten noisinh lop diemtoan diemly DTB";
for(i=1;i<=m;i++)
svtn[i].xuattn();
hocbong(svtn,m);
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top