Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by quy3t ( 5 years ago )
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct NgaySinh {
string d, m, y;
};
istream& operator >> (istream& iss, NgaySinh& ngaysinh) {
cout << "\n\t\tNhap Ngay: ";
getline(iss, ngaysinh.d);
cout << "\n\t\tNhap Thang: ";
getline(iss, ngaysinh.m);
cout << "\n\t\tNhap Nam: ";
getline(iss, ngaysinh.y);
return iss;
}
ostream& operator << (ostream& oss, NgaySinh& ngaysinh) {
oss << setw(0) << ngaysinh.d << "/"
<< setw(0) << ngaysinh.m << "/"
<< setw(0) << ngaysinh.y;
return oss;
}
struct Employee {
string ten = "";
NgaySinh ngaysinh;
string chucvu = "";
double luong = 0;
};
void nhap(Employee*& x) {
cout << "\n\tNhap Ten: ";
getline(cin, x->ten);
cout << "\n\tNhap Chuc Vu: ";
getline(cin, x->chucvu);
cout << "\n\tNhap Ngay Sinh (dd//mm//yy): ";
cin >> x->ngaysinh;
cout << "\n\tNhap Luong: ";
cin >> x->luong;
}
void title() {
cout << endl
<< setw(30) << "Ten"
<< setw(20) << "Chuc Vu"
<< setw(25) << "Luong"
<< setw(2) << "Ngay Sinh"
<< endl;
}
void xuat(Employee* x) {
cout << endl
<< setw(30) << x->ten
<< setw(20) << x->chucvu
<< setw(25) << x->luong
<< setw(25) << x->ngaysinh
<< endl;
}
int main()
{
cout << left;
Employee* nv = new Employee;
nhap(nv);
fstream fileX;
fileX.open("file.dat", ios_base::out | ios_base::binary);
fileX.write((char*)nv, sizeof(nv));
cout << "\n\tGhi File Thanh Cong.\n";
fileX.close();
fileX.open("file.dat", ios_base::in | ios_base::binary);
fileX.read((char*)nv, sizeof(nv));
cout << "\n\tDoc File Thanh Cong. Thong Tin:\n";
title();
xuat(nv);
fileX.close();
return 0;
}
Revise this Paste
Parent: 117392