Bai 2

//Tran Van Hien 15T3 #include <iostream> using namespace std; struct sv{ string ten; float diem; }; void Nhap(sv *list, int n){ for(int i = 1; i<=n; i++){ cin.ignore(); cout<<"Nhap ten sinh vien thu "<<i<<": "; getline(cin,list->ten); cout<<endl; cout<<"Nhap diem sinh vien thu "<<i<<": "; cin>>list->diem; cout<<endl; list++; } } void HoanVi(sv *x, sv *y){ sv temp = *x; *x = *y; *y= temp; } void SapXep(sv *list, int n){ for(int i=0; i<n; i++) for(int j = i+1; j<n; j++){ if( (list+i)->diem < (list+j)->diem) HoanVi(list+i,list+j); } } void Xuat(sv *list, int n, float diem_chuan){ for(int i=1; i<=n; i++) if (list->diem >= diem_chuan) { cout<<"Ten sinh vien: "<<list->ten<<". Diem: "<<list->diem<<endl; list++; } else break; } int main(){ int n; float diem_chuan; cout<<"Nhap so luong sinh vien"; cin>>n; sv *list = new sv[n]; Nhap(list,n); SapXep(list,n); cout<<"-----------DANH SACH SINH VIEN----------"<<endl; Xuat(list,n,0); cout<<"Nhap diem chuan: "; cin>>diem_chuan; cout<<endl<<"------------DANH SACH TRUNG TUYEN---------"<<endl; Xuat(list,n,diem_chuan); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.