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


}

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

{

fs<<t.sbd<<endl; fs<<t.ten<<endl; fs<<t.diem<<endl; return fs;

}

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

{

fs.getline(t.sbd,5); fs.getline(t.ten,30); fs>>t.diem; fs.ignore();

return fs;

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

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

}

char *getsbd(); char *getten()

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

{

return ten;

}

unsigned int getdiem()

{

return diem;

}

};

char *ts::getsbd()

{

return sbd;

}

class node

{

public:


ts info; node *link;

};

class list

{

node *home; public:

list()

{

home=NULL;

}

void create()

{

node *p, *end; ts 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 display()

{

node *p; p=home; while(p!=NULL)

{

cout<<p->info;


p=p->link;

}

}

unsigned int count()

{

node *p;

unsigned int dem=0; p=home; while(p!=NULL)

{

dem++; p=p->link;

}

return dem;

}

void add(ts x)

{

node *p, *end; p=new node; 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 *p)

{

node *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 *find_add(char *x)

{

node *p; p=home;

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

}

void find_sbd(char *x)

{

node *p; p=home;

while((p!=NULL)&&(strcmp((p->info).getsbd(),x)!=0)) p=p->link; if(p!=NULL) cout<<p->info;

else cout<<"Khong tim thay thi sinh co so bao danh tren";

}


void find_ten(char *x)

{

node *p; p=home;

while((p!=NULL)&&(strcmp((p->info).getten(),x)!=0)) p=p->link; if(p!=NULL) cout<<p->info;

else cout<<"Khong tim thay thi sinh co so bao danh tren";

}

void find_max()

{

node *p;

unsigned int diemmax=0; p=home; while(p!=NULL)

{

if((p->info).getdiem()>diemmax) diemmax=(p->info).getdiem(); p=p->link;

}

p=home; while(p!=NULL)

{

if((p->info).getdiem()==diemmax) cout<<p->info; p=p->link;

}

}

void find_min()

{

node *p;

unsigned int diemmin=65535; p=home;

while(p!=NULL)

{

if((p->info).getdiem()<diemmin) diemmin=(p->info).getdiem();


p=p->link;

}

p=home; while(p!=NULL)

{

if((p->info).getdiem()==diemmin) cout<<p->info; p=p->link;

}

}

list xettuyen_diem(unsigned int diemchuan)

{

node *p; list kq; p=home;

cout<<"Danh sach thi sinh trung tuyenn"; while(p!=NULL)

{

if((p->info).getdiem()>=diemchuan) kq.add(p->info); p=p->link;

}

return kq;

}

void sort_asc()

{

node *p,*q; ts tg; p=home;

while(p->link!=NULL)

{

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

{

if((p->info).getdiem()>(q->info).getdiem())


{

tg= p->info; p->info=q->info; q->info=tg;

}

q=q->link;

}

p=p->link;

}

}

void remove(char *x);

};

void list::remove(char *x)

{

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

{

q=p;

while((q!=NULL)&&(strcmp((q->info).getsbd(),x)!=0)) q=q->link; if(q!=NULL)

{

p=q->link; remove(q);

}

else p=NULL;

}

}

void main()

{

list l,tt,kq; ts x;

unsigned int diemchuan,soluong; char bd[5],ht[30];

char lc;


int chon;

do

{

clrscr();

cout<<"n 1. Lap danh sach thi sinh"; cout<<"n 2. Hien thi danh sach thi sinh"; cout<<"n 3. Tim kiem thong tin"; cout<<"n 4. Bo sung vao danh sach"; cout<<"n 5. Xoa khoi danh sach"; cout<<"n 6. Sap xep danh sach"; cout<<"n 7. Xet tuyen";

cout<<"n 8. Ket thuc chuong trinh"; cout<<"nChon chuc nang:";cin>>chon; switch (chon)

{

case 1:

l.create(); break;

case 2:

cout<<"nDanh sach thi sinh:n"; l.display();

getch(); break;

case 3: do

{

clrscr();

cout<<"na. Tim theo so bao danh"; cout<<"nb. Tim theo ten";

cout<<"nc. Thi sinh co diem cao nhat"; cout<<"nd. Thi sinh co diem thap nhat"; cout<<"ne. Quay lai(nhan r):"; cout<<"n Ban chon:";

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

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