Bai Tap Quan Ly Nhan Vien

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

#include<iostream>

#include<string>
#include<vector>
#include<iomanip>
using std::cin;
using std::cout;
using std::getline;
using std::string;
using std::vector;
using std::endl;
using std::to_string;
using std::setprecision;
using std::fixed;
class MyDate{
private:
int ngay,thang,nam;
public:
int getngay();
void setngay(int ngay);
int getthang();
void setthang(int thang);
int getnam();
void setnam(int nam);
void nhap();
void xuat();
};
int MyDate::getngay(){
return this->ngay;
}
void MyDate::setngay(int ngay){
this->ngay=ngay;
}
int MyDate::getthang(){
return this->thang;
}
void MyDate::setthang(int thang){
this->thang=thang;
}
int MyDate::getnam(){
return this->nam;
}
void MyDate::setnam(int nam){
this->nam=nam;
}
void MyDate::nhap(){
bool f=true;
int k=0;
do{
if(k==0){
cout<<"Nhap ngay: ";
cin>>ngay;
cout<<"Nhap thang: ";
cin>>thang;
cout<<"Nhap nam: ";
cin>>nam;
cin.ignore();
}else{
cout<<"Co ve ban nhap loi. Xin moi nhap lai!"<<endl;
cout<<"Nhap lai ngay: ";
cin>>ngay;
cout<<"Nhap lai thang: ";
cin>>thang;
cout<<"Nhap lai nam: ";
cin>>nam;
cin.ignore();
}
bool namnhuan;
switch(thang){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(ngay>31 || ngay <1 || nam<0){
k++;
continue;
}
f=false;
break;
case 2:
if(nam<0){
continue;
}
namnhuan= nam%4==0 ? true:false;
if(namnhuan){
if(ngay>29|| ngay<1){
k++;
continue;
}
}else {
if(ngay>28|| ngay<1){
k++;
continue;
}
}
f=false;
break;
case 4:
case 6:
case 9:
case 11:
if(ngay>30 || ngay <1 || nam<0){
k++;
continue;
}
f=false;
break;
default:
k++;
break;
}
}while(f);
}
void MyDate::xuat(){
string Ngay=string(2-to_string(ngay).size(),'0')+to_string(ngay);
string Thang=string(2-to_string(thang).size(),'0')+to_string(thang);
string Nam=string(4-to_string(ngay).size(),'0')+to_string(nam);
cout<<Ngay<<"-"<<Thang<<"-"<<Nam;
}
class Person : public MyDate{
private:
string ten,diachi,sodienthoai;
public:
string getten();
void setten(string ten);
string getdiachi();
void setdiachi(string diachi);
string getsodienthoai();
void setsodienthoai(string sodienthoai);
void nhap();
void xuat();
};
string Person::getten(){
return this->ten;
}
void Person::setten(string ten){
this->ten=ten;
}
string Person::getdiachi(){
return this->diachi;
}
void Person::setdiachi(string diachi){
this->diachi=diachi;
}
string Person::getsodienthoai(){
return this->sodienthoai;
}
void Person::setsodienthoai(string sodienthoai){
this->sodienthoai=sodienthoai;
}
void Person::nhap(){
cout<<"Nhap ho va ten: ";
getline(cin,ten);
MyDate::nhap();
cout<<"Nhap dia chi: ";
getline(cin,diachi);
cout<<"Nhap so dien thoai: ";
getline(cin,sodienthoai);
}
void Person::xuat(){
cout<<ten<<" ";
MyDate::xuat();
cout<<" "<<diachi<<" "<<sodienthoai;
}
class Officer: public Person{
private:
double luong;
public:
double getluong();
void setluong(double luong);
void nhap();
void xuat();
};
double Officer::getluong(){
return this->luong;
}
void Officer::setluong(double luong){
this->luong=luong;
}
void Officer::nhap(){
Person::nhap();
cout<<"Nhap luong: ";
cin>>luong;
cin.ignore();
}
void Officer::xuat(){
Person::xuat();
cout<<" "<<setprecision(0)<<fixed<<luong<<endl;
}
int main(){
int n;
cin>>n;
cin.ignore();
vector<Officer> Danhsach(n);
for(int i=0;i<Danhsach.size();i++){
Danhsach[i].nhap();
}
for(int i=0;i<Danhsach.size();i++){
if(Danhsach[i].getluong()>10000000){
Danhsach[i].xuat();
}
}
return 0;
}

You might also like