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


void list::doc_tep(char *filename)

{

ts x;

fstream f(filename,ios::in|ios::trunc); while(f>>x,!f.eof())

add(x);

f.close();

}

void list::ghi_tep(char *filename)

{

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

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

node *p; ts x;

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

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

while(p!=NULL)

{

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

}

f.close();

}

void list::display()

{

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

{

(p->info).hienthi(); p=p->link;

}

}

unsigned int list::count()

{

node *p;

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

{

dem++;

p=p->link;

}

return dem;

}

void ts::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 ts::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 *list::find_add(char *x)

{

node *p; p=home;

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

return p;

}

void list::find_sbd(char *x)

{

node *p; p=home;

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

if(p!=NULL) (p->info).hienthi();


else

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

}

void list::find_ten(char *x)

{

node *p; p=home;

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

if(p!=NULL) (p->info).hienthi(); else

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

}

void list::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) (p-

>info).hienthi(); 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)


(p->info).hienthi(); p=p->link;

}

}

list 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;

}

list list::xettuyen_soluong(unsigned int soluong)

{

node *p; list kq;

unsigned int dem; sort_desc(); p=home;

dem=0;

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

{

dem++;

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

}

return kq;

}

void list::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 list::sort_desc()

{

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 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; 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:

char filename[20]; char tl;

do

{

clrscr();

cout<<"na. Nhap tu ban phim"; cout<<"nb. Doc tu tep"; cout<<"nc. Quay lai(nhan r):"; cout<<"n Ban chon:";

cin>>lc; switch(lc)

{

case 'a':

l.create();

cin.ignore();

cout<<"Da xong, co gi vao tep khong?"; cin>>tl;

if((tl=='c')||(tl=='C'))

{

cout<<"Ten tep:"; cin.ignore(); cin.getline(filename,20); l.ghi_tep(filename);

}

break; case 'b':

cout<<"Ten tep:"; cin.ignore();


cin.getline(filename,20); l.doc_tep(filename); break;

}

}

while(lc!='r'); 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:";

cin>>lc; switch(lc)

{

case 'a': cin.ignore(1);

cout<<"So bao danh:";cin.getline(bd,5); l.find_sbd(bd);

getch();break; case 'b': cin.ignore(1);

cout<<"Ho va ten:";cin.getline(ht,30); l.find_ten(ht);

getch();break; case 'c':

cout<<"Thi sinh co diem cao nhatn"; l.find_max();

getch();break; case 'd':

cout<<"Thi sinh co diem cao nhatn"; l.find_min();

getch();break;

}

}

while(lc!='r'); break;


case 4:

cout<<"Nhap thong tin thi sinh can bo sungn"; x.nhap();

l.add(x);

cin.ignore();

cout<<"Da xong, co gi vao tep khong?"; cin>>tl;

if((tl=='c')||(tl=='C'))

{


}

break; case 5:

cout<<"Ten tep:"; cin.ignore(); cin.getline(filename,20); fstream f(filename,ios::app); f<<x;

f.close();


bon";

cout<<"Nhap so bao dand cua thi sinh can loai


cin.ignore(1); cin>>bd; l.remove(bd); break;

case 6:

do

{


clrscr();

cout<<"na. Sap xep theo diem tang dan"; cout<<"nb. Sap xep theo diem giam dan"; cout<<"nc. Quay lai(nhan r):"; cout<<"n Ban chon:";

cin>>lc; switch(lc)

{

case 'a':

l.sort_asc(); break;

case 'b': l.sort_desc(); break;

}

}

while(lc!='r'); break;

case 7:

do

Xem tất cả 256 trang.

Ngày đăng: 03/07/2022
Trang chủ Tài liệu miễn phí