Professional Documents
Culture Documents
BÁO CÁO
MÔN LẬP TRÌNH HƯỚNG ĐỐI
TƯỢNG
Đề tài: QUẢN LÝ BÁC SỸ
II.1 CODE:
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
class NV
{
private:
string id;
string name;
string money;
string position;
public:
NV(){}
NV(string mnv, string ten, string tienluong, string chucvu) : id(mnv), name(ten),
money(tienluong), position(chucvu){}
void addPerson();
void delPerson(string mnv);
void editPerson(string mnv);
void showInfoPerson();
void showFile();
void setName(string ten)
{
name = ten;
}
switch (input)
{
case 1:
cout << "Ban da chon them thong tin BAC SY!\n";
st.addPerson();
break;
case 2:
cin.ignore(); // ignore roi xuong duoi khong ignore nua
cout << "Ban da chon sua thong tin BAC SY!\n";
cout << "Nhap id BAC SY : "; getline(cin, id);
st.editPerson(id);
break;
case 3:
cout << "Ban da chon xoa thong tin BAC SY!\n";
cout << "Nhap id BAC SY : "; cin >> id;
st.delPerson(id);
break;
case 4:
cout << "Ban da chon xuat thong tin BAC SY!\n";
st.showInfoPerson();
case 5:
cout << "Ban da chon xuat File!\n";
st.showFile();
break;
case 0:
return 0;
}
}
}
void NV::addPerson()
{
string mnv, hoTen, tienluong, chucvu;
cin.ignore(32767, '\n');
cout << "Nhap ma ID BAC SY: " ; getline(cin, mnv);
cout << "Nhap ten BAC SY: "; getline(cin, hoTen);
cout << "Nhap tien luong : "; getline(cin,tienluong);
cout << "Nhap chuc vu: ";getline(cin, chucvu);
listNV.push_back(NV(mnv,hoTen,tienluong,chucvu));
}
void NV::showInfoPerson()
{
for (int i=0; i<listNV.size(); i++)
{
cout << "ID : " << listNV[i].id << " ";
cout << "Ten : " << listNV[i].name << " ";
cout << "Tien Luong : " << listNV[i].money << " ";
cout << "Chuc Vu : " <<listNV[i].position<< endl;
}
}
void NV::delPerson(string mnv)
{
for (int i=0; i<listNV.size() ; i++)
{
if (listNV[i].id == mnv)
{
listNV.erase(listNV.begin() + i);
}
}
}
void NV::editPerson(string mnv)
{
for (int i=0; i<listNV.size(); i++)
{
if (listNV[i].id==mnv)
{
string ten, tienluong,chucvu;
//cin.ignore();
cout << "Nhap lai ten BAC SY: "; getline(cin, ten);
cout << "Nhap lai tien luong: "; getline(cin, tienluong);
cout << "Nhap chuc vu moi: "; getline(cin, chucvu);
listNV[i].setName(ten);
listNV[i].setMoney(tienluong);
listNV[i].setPosition(chucvu);
}
else
cout << "Khong co BAC SY ID nhu nay!" << endl;
}
}
void NV::showFile()
{
ofstream fo("danhsachnv.txt");
for (int i=0; i<listNV.size(); i++)
{
fo << "ID : " << listNV[i].id << endl;
fo << "Ten : " << listNV[i].name << endl;
fo << "Tien Luong : " << listNV[i].money <<"$"<<endl;
fo << "Chuc Vu : " <<listNV[i].position<< endl;
fo << "------------------------------------\n";
}
fo.close();
string myfile;
ifstream fi("danhsachnv.txt");
for(int i=0; i<listNV.size(); i++);
{
while (getline (fi, myfile))
{
cout<< myfile;
}
}
fi.close();
II.2 CHẠY.
HÌNH 1
HÌNH 2
HÌNH 3: XUẤT FILE