Bai toan nhan vien C++
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <string.h>
class nguoi
{
private:
char ht[15];
int ns;
public:
void nhap();
void hien();
char *traveten()
{
return ht;
}
};
void nguoi::nhap()
{
cout<<"
nhap ho ten:";
cin.ignore(1);
cin.get(ht,15);
cout<<"
Nam sinh";
cin>>ns;
}
void nguoi::hien()
{
cout<<setw(15)<<ht<<setw(6)<<ns;
}
class tienluong
{
private:
float nc,tc,lg;
public:
void nhap();
void hien();
float traveluong()
{
return lg;
}
};
void tienluong::nhap()
{
cout<<"
Nhap NC,TC:";
cin>>nc>>tc;
lg=nc*tc;
}
void tienluong::hien()
{
cout<<setw(6)<<nc<<setw(6)<<tc<<setw(6)<<lg;
}
class nhanvien:public nguoi,public tienluong
{
private:
char cv[10];
public:
void nhap();
void hien();
friend float timluongmax(nhanvien *nv,int n);
};
void nhanvien::nhap()
{
nguoi::nhap();
tienluong::nhap();
cout<<"
Nhap chuc vu";
cin.ignore (1);
cin.get(cv,10);
}
void nhanvien::hien()
{
nguoi::hien();
tienluong::hien();
cout<<setw(10)<<cv;
}
float timluongmax(nhanvien *nv,int n)
{
float max;
int i;
max=nv[0].traveluong();
for(i=0;i<n;i++);
if (nv[i].traveluong()>max)
max=nv[i].traveluong();
return max;
}
void hiends(nhanvien nv[],int n,char tb[])
{
int i;
cout<<"
danh sach nhan vien vua "<<tb<<"
";
for (i=0;i<n;i++)
{
cout<<"
"<<setw(4)<<i+1;
nv[i].hien();
}
}
void main()
{
nhanvien nv[100];
int n,i;
char tt[15];
float lmax;
cout<<"
nhap so luong nhan vien";
cin>>n;
cout<<"
nhap danh sach nhan vien";
for(i=0;i<n;i++)
{
cout<<"
nhap nhan vien thu"<<i+1;
nv[i].nhap();
}
hiends(nv,n,"vua nhap");
lmax=timluongmax(nv,n);
cout<<"
Danh sach nhan vien co luong cao nhat
";
for (i=0;i<n;i++);
if (nv[i].traveluong()==lmax)
{
cout<<"
";
nv[i].hien();
}
cout<<"
nhap ten nhan vien can tim:";
cin.ignore(1);
cin.get(tt,15);
cout<<"
danh sach nhan vien co ten"<<tt<<"
";
for (i=0;i<n;i++)
if(strcmp(tt,nv[i].traveten())==0)
{
cout<<"
";
nv[i].hien();
}
cout<<"
";
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top