OOP xắp xếp tên tăng dần!

/// ////////////////////////////////////class sinh_viên #pragma once #include<iostream> using namespace std; #include<vector> #include<string> class sinh_vien {private: string ten; float diemtoan; public: void Nhapthongtinsinhvien(); void Xuatthongtinsinhvien(); float Xuatdiemtoan(); string xuatten1();// để truy xuất tên mà xắp xếp }; //////////////////////////////////class lop_học class Lop_Hoc { private: vector<sinh_vien> arr; public: void Nhapmangcacsinhvien(); void Xuatmangcacsinhvien(); float Timdiemtoanmax(); void Xuatcacsinhviencodiemtoanmax(); }; ////////////////thuc hien phương thức ///////////////////////////////// ///////////////phương thức bên class sinh_vien//////////////////////// void sinh_vien::Nhapthongtinsinhvien() { fflush(stdin); cout<<"\nMoi ban nhap ten sinh vien cua minh vao: ";getline(cin,ten); cout<<"\nMoi ban nhap diem chuyen nganh: ";cin>>diemtoan; } float sinh_vien::Xuatdiemtoan() { return diemtoan; } string sinh_vien::xuatten1() { return ten; } void sinh_vien::Xuatthongtinsinhvien() { cout<<"\nten sinh vien: "<<ten; cout<<"\ndiem thi mon chuyen nganh: "<<diemtoan; } //////////////////////////phương thức bên class lop_hoc//////////////////// void Lop_Hoc::Nhapmangcacsinhvien() { int chon; do{ cout<<"\n=======================\n"; cout<<"1.Nhap\n"; cout<<"0.thoat"; cout<<"\n=======================\n"; cout<<"\nMoi ban chuc nang: ";cin>>chon; if(chon>1) { cout<<"\nBan bam cai quai j vay coi lai nha ^++^"; } if(chon==1) { sinh_vien s1; s1.Nhapthongtinsinhvien(); arr.push_back(s1); } }while(chon!=0); } void Lop_Hoc::Xuatmangcacsinhvien() { int k=arr.size(); for(int i=0;i<k;i++) { arr[i].Xuatthongtinsinhvien(); } } float Lop_Hoc::Timdiemtoanmax() { float max=arr[0].Xuatdiemtoan(); int k=arr.size(); for(int i=1;i<k;i++) { if(max<arr[i].Xuatdiemtoan()) { max=arr[i].Xuatdiemtoan(); } } return max; } void Lop_Hoc::Xuatcacsinhviencodiemtoanmax() { float max=Timdiemtoanmax(); int k=arr.size(); int diem=0; for(int i=0;i<k;i++) { if(arr[i].Xuatdiemtoan()==max) { diem+=1; } } for(int i=0,j=1;i<diem-1,j<diem;i++,j++) { if(arr[i].xuatten1()>arr[j].xuatten1()) { swap(arr[i],arr[j]);// hàm hoán đổi có trong c++: } } for(int i=0;i<diem;i++) { arr[i].Xuatthongtinsinhvien(); } } int main() { Lop_Hoc s; s.Nhapmangcacsinhvien(); s.Xuatmangcacsinhvien(); cout<<"\nDanh sach cac sinh vien co diem toan lon nhat: \n"; s.Xuatcacsinhviencodiemtrungbinhlonnhat(); system("pause"); 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.