Lập trình hướng đối tượng - 29


}

friend fstream &operator>>(fstream &fs,phong &t)

{

fs.getline(t.pid,5); fs.getline(t.pname,30); fs.getline(t.add,30); fs.getline(t.phone,11); return fs;

}

char *getid();

};

char *phong::getid()

{

Có thể bạn quan tâm!

Xem toàn bộ 256 trang tài liệu này.

return pid;

}

Lập trình hướng đối tượng - 29

//lớp mặt hàng

class mathang

{

private:

char mhid[5]; char mhname[20]; char dvt[10]; char mancc[5]; public:

char *getid();

friend istream &operator>>(istream &is,mathang &t)

{

cout<<"Ma mat hang:";is.getline(t.mhid,5); cout<<"Ten mat hang:";is.getline(t.mhname,30); cout<<"Don vi tinh:";is.getline(t.dvt,10); cout<<"Ma nha cung cap:";is.getline(t.mancc,11); return is;

}

friend ostream &operator<<(ostream &os, const mathang &t)

{

cout<<"n Ma mat hang:"<<t.mhid; cout<<"n Ten mat hang:"<<t.mhname; cout<<"n Don vi tinh:"<<t.dvt; cout<<"n Ma nha cung cap:"<<t.mancc; return os;

}

friend fstream &operator<<(fstream &fs, const mathang &t)

{

fs<<t.mhid<<endl; fs<<t.mhname<<endl;


fs<<t.dvt<<endl; fs<<t.mancc<<endl; return fs;

}

friend fstream &operator>>(fstream &fs,mathang &t)

{

fs.getline(t.mhid,5); fs.getline(t.mhname,30); fs.getline(t.dvt,10); fs.getline(t.mancc,5); return fs;

}

};

char *mathang::getid()

{

return mhid;

}

class nhacungcap:public nguoi

{

private:

char account[10]; public:

friend istream &operator>>(istream &is,nhacungcap &t)

{

cout<<"Ma:"; is.getline(t.id,5); cout<<"Ho va ten:"; is.getline(t.name,30); cout<<"Dia chi:"; is.getline(t.add,30); cout<<"Email:"; is.getline(t.email,30); cout<<"Dien thoai:"; is.getline(t.phone,11); cout<<"So tai khoan:"; is.getline(t.account,10); return is;

}

friend ostream &operator<<(ostream &os, const nhacungcap &t)

{

cout<<"nMa:"<<t.id; cout<<"nHo va ten:"<<t.name; cout<<"nDia chi:"<<t.add; cout<<"nEmail:"<<t.email; cout<<"nDien thoai:"<<t.phone;

cout<<"nSo tai khoan:"<<t.account;


return os;

}

friend fstream &operator<<(fstream &fs, const nhacungcap &t)

{

fs<<t.id<<endl; fs<<t.name<<endl; fs<<t.add<<endl; fs<<t.email<<endl; fs<<t.phone<<endl; fs<<t.account<<endl; return fs;

}

friend fstream &operator>>(fstream &fs,nhacungcap &t)

{

fs.getline(t.id,5); fs.getline(t.name,30); fs.getline(t.add,30); fs.getline(t.email,30); fs.getline(t.phone,11); fs.getline(t.account,10); return fs;

}

char *getid();

};

char *nhacungcap::getid()

{

return id;

}

//lớp hoá đơn

class hoadon

{

char hdid[5]; char ngay[10]; char khid[5]; char mhid[5]; char mhname[20]; char nvid[5]; unsigned int sl; unsigned int gia; public:

friend istream &operator>>(istream &is,hoadon &t)

{

cout<<"So hoa don:"; is.getline(t.hdid,5); cout<<"Ma nhan vien ban hang:"; is.getline(t.nvid,5);


cout<<"Ma khach mua hang:"; is.getline(t.khid,5); cout<<"Ma mat hang:"; is.getline(t.mhid,5); cout<<"Ten mat hang:"; is.getline(t.mhname,20); cout<<"So luong:"; is>>t.sl;

cout<<"Gia:"; is>>t.gia; is.ignore(); cout<<"Ngay ban:"; is.getline(t.ngay,10); return is;

}

friend ostream &operator<<(ostream &os, const hoadon &t)

{

cout<<"nSo hoa don:"<<t.hdid; cout<<"nMa nhan vien ban hang:"<<t.nvid; cout<<"nMa khach mua hang:"<<t.khid; cout<<"nMa mat hang:"<<t.mhid; cout<<"nTen mat hang:"<<t.mhname; cout<<"nSo luong mua:"<<t.sl; cout<<"nGia mua:"<<t.gia;

cout<<"n Ngay ban:"<<t.ngay; return os;

}

friend fstream &operator<<(fstream &fs, const hoadon &t)

{

fs<<t.hdid<<endl; fs<<t.nvid<<endl; fs<<t.khid<<endl; fs<<t.mhid<<endl; fs<<t.mhname<<endl; fs<<t.sl<<endl; fs<<t.gia<<endl; fs<<t.ngay<<endl; return fs;

}

friend fstream &operator>>(fstream &fs,hoadon &t)

{

fs.getline(t.hdid,5); fs.getline(t.nvid,5); fs.getline(t.khid,5); fs.getline(t.mhid,5);


fs.getline(t.mhname,20); fs>>t.sl;

fs>>t.gia; fs.ignore(); fs.getline(t.ngay,10); return fs;

}

char *getid(); float getgia(); float getsl(); char *getmanv(); char *getmamh(); char *getmakh();

};

char *hoadon::getmanv()

{

return nvid;

}

char *hoadon::getmamh()

{

return mhid;

}

char *hoadon::getmakh()

{

return khid;

}

float hoadon::getgia()

{

return gia;

}

float hoadon::getsl()

{

return sl;

}

char *hoadon::getid()

{

return hdid;

}

//khuôn hình lớp nút trong danh sách nối đơn

template <class t> class node

{

public: t info;

node *link;

};

//khuôn hình lớp danh sách nối đơn


template <class s> class list

{

node<s> *home; public: list()

{

home=NULL;

}

~list()

{

home=NULL;

}

void create()

{

node<s> *p, *end; s x;

char ans;

cout<<"Nhap danh sach thi sinhn"; do

{

cin>>x; add(x); cin.ignore(1);

cout<<"Continue? C/K:";cin>>ans;

}

while((ans!='k')&&(ans!='K'));

}

void doc_tep(char *filename)

{

s x;

fstream f(filename,ios::in|ios::trunc); if(f.bad()) cout<<"Loi doc tep";

else

{

while(f>>x,!f.eof()) add(x);

f.close();

}

}

void ghi_tep(char *filename)

{

node<s> *p;

fstream f(filename,ios::out|ios::in|ios::trunc); p=home;

while(p!=NULL)

{


f<<p->info; p=p->link;

}

f.close();

}

void ghi_bs(char *filename,s x)

{

node<s> *p;

fstream f(filename,ios::app); f<<x;

f.close();

}

void display()

{

node<s> *p; p=home; while(p!=NULL)

{

cout<<p->info; p=p->link;

}

}

unsigned int count()

{

node<s> *p; unsigned int dem=0; p=home; while(p!=NULL)

{

dem++;

p=p->link;

}

return dem;

}

void add(s x)

{

node<s> *p, *end; p=new node<s>;

p->info=x;

p->link=NULL; if(home==NULL) home=p; else

{

end=home;

while(end->link!=NULL) end=end->link; end->link=p;

}


}

void remove(node<s> *p)

{

node<s> *q; if(home==NULL) return; else

{

if(p==home)

if(home->link==NULL) home=NULL; else

{

home=home->link; p->link=NULL;

}

else

{

q=home;

while(q->link!=p) q=q->link; q->link=p->link;

}

delete p;

}

}

node<s> *find_add(char *x)

{

node<s> *p; p=home;

while((p!=NULL)&&(strcmp((p->info).getid(),x)!=0) p=p->link;

return p;

}

void find_tt(char *x)

{

node<s> *p; p=home;

while((p!=NULL)&&(strcmp((p->info).getid(),x)!=0)) p=p->link;

if(p!=NULL) cout<<p->info; else cout<<"Khong tim thay";

}

void remove(char *x)

{

node<s> *p,*q; p=home; while(p!=NULL)

{

q=p;

..... Xem trang tiếp theo?
⇦ Trang trước - Trang tiếp theo ⇨

Ngày đăng: 03/07/2022