//Class Nhan Vien
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
class NhanVien
{
	private:
		char tennv[30];
		char msnv[30];
		char gioitinh[20];
		double luong;
	public:
		void setTennv(char*);
		char* getTennv();
		void setMsnv(char*);
		char* getMsnv();
		void setGioitinh(char*);
		char* getGioitinh();
		void setLuong(double);
		double getLuong();
		void Input();
		void show();		
};
void NhanVien::setTennv(char* ten)
    {
      strcpy(tennv,ten);
    }
char* NhanVien::getTennv() 
    {
    	return tennv;
	}
void NhanVien::setMsnv(char* ms)
    {
       strcpy(msnv,ms);	
	}	     
char* NhanVien::getMsnv()
	{
		return msnv;
	}
void NhanVien::setGioitinh(char* gt)
    {	
	     strcpy(gioitinh,gt);
	}	
char* NhanVien::getGioitinh()
    {
        return gioitinh;	
	}	
void NhanVien::setLuong(double luog)
    {
    	luong=luog;
	}	
double NhanVien::getLuong()
    {
        return luong;	
	}	
void NhanVien::Input(){
	char ten[30];
	char gt[20];
	char ms[30];
	double luog;
	cout<<"Ten nhan vien: "; cin.ignore(); cin.getline(ten,30); setTennv(ten);
	cout<<"Ma so nhan vien: "; cin.getline(ms,30); setMsnv(ms);
	cout<<"Gioi tinh: ";  cin.getline(gt,20); setGioitinh(gt); 
	cout<<"Luong: "; cin>>luog; setLuong(luog);
}
void NhanVien::show(){

	cout<<"Ten nhan vien: " << getTennv() << endl; 
	cout<<"Ma so nhan vien: "<< getMsnv() << endl; 
	cout<<"Gioi tinh: "<< getGioitinh() << endl;
	cout<<"Luong: "<< getLuong() << endl;
}
void menu(){
	cout<< "THONG TIN NHAN VIEN " << endl;
	cout<< "1. Nhap thong tin nhan vien"<<endl;
	cout<< "2. Hien thi thong tin nhan vien"<<endl;
	cout<< "3. Nhan '0' de thoat. "<<endl;
}
int choice(){
	int c;
	cout<<" Moi nhap lua chon: ";
	cin>>c;
	return c;
}
void option(){
	NhanVien *nv = new NhanVien[100];
	//NhanVien nv[100];
	int choose,i;
	do{
		menu();
		choose=choice();
		switch(choose){
			case 1:{
				fstream fileOut("cuong123.txt",ios::out | ios::app | ios::binary);
					if (!fileOut){   
				     cout << "Khong the tao duoc tep tin " << endl;
				       exit(1);
			    }
				int n;
				cout << "Nhap so luong nhan vien: ";
				cin >> n;
				//fileOut.write(reinterpret_cast<char *>(nv),sizeof(NhanVien));
				for(int i=1;i<=n;i++){
				    cout << "Moi nhap thong tin nhan vien " << i <<endl;
					nv[i].Input();	
			    fileOut.write(reinterpret_cast<char *>(&nv[i]),sizeof(NhanVien)); 
			    }
				fileOut.close();
				break;
				} 
			case 2:{
				fstream fileIn("cuong123.txt",ios::in | ios::binary);
				if(!fileIn){
					cout << "Khong the mo duoc tep tin "<<endl;
					exit(1);
				}
				
				//fileIn.read(reinterpret_cast<char*>(&nv[i]),sizeof(NhanVien));
				
				cout << "Hien thi nhan vien thu: ";
				cin >> i;
				fileIn.read(reinterpret_cast<char*>(&nv[i]),sizeof(NhanVien));
				nv[i].show();
				fileIn.close(); 
				break; 
			}
		}
	}
	while(choose!=0);
}
int main()
{
	option();
	return 0;
}
