fork download
  1. // Bai 2
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. class SV{
  5. private:
  6. char msv[15],nganh[20];
  7. string ten;
  8. string xep;
  9. int ng,th,nam;
  10. float toan,van,tin,tong;
  11. public:
  12. void nhap(){
  13. cout<<"Nhap ho ten: "; getline(cin,ten);
  14. cout<<"Ma sinh vien: "; cin.getline(msv,15);
  15. cout<<"Nganh hoc: "; cin.getline(nganh,20);
  16. cout<<"Ngay sinh(date): "; cin >> ng >> th >> nam;
  17. while(ng > 31){
  18. cout<<"Moi nhap lai ngay: "; cin>>ng;
  19. }
  20. while(th > 12){
  21. cout<<"Moi nhap lai thang: "; cin>>th;
  22. }
  23. while(nam > 2024){
  24. cout<<"Moi nhap lai nam: "; cin>>nam;
  25. }
  26. cout<<"Nhap diem toan: "; cin >> toan;
  27. cout<<"Nhap diem van: "; cin >> van;
  28. cout<<"Nhap diem tin: "; cin >> tin;
  29. cin.ignore();
  30. cout<<endl;
  31.  
  32. }
  33. void tinh(){
  34. tong = (toan*4 + van*4 + tin*2)/10;
  35. if(tong >= 9){
  36. xep = "Xuat sac";
  37. }else
  38. if(tong >= 7.5){
  39. xep = "Gioi";
  40. }else
  41. if(tong >= 6){
  42. xep = "Kha";
  43. }else
  44. if(tong >= 4){
  45. xep = "Trung binh";
  46. }else
  47. if(tong < 4){
  48. xep = "Yeu";
  49. }
  50.  
  51. }
  52.  
  53. void xuat(){
  54. cout<<setw(20)<<left<<ten
  55. <<setw(15)<<left<<msv;
  56. if(ng<10) cout<<"0"<<ng<<"/";
  57. else cout<<ng<<"/";
  58. if(th < 10) cout<<"0"<<th<<"/";
  59. else cout<<nam<<"/";
  60. cout<<setw(10)<<left<<nam
  61. <<setw(10)<<left<<nganh
  62. <<setw(13)<<left<<tong
  63. <<setw(10)<<left<<xep<<endl;
  64. }
  65. float gettong(){
  66. return this->tong;
  67. }
  68. int getten(){
  69. return this->ten.size();
  70. }
  71. };
  72.  
  73. bool cmp(SV a, SV b){
  74. if(a.gettong() < b.gettong()) return a.gettong();
  75. // if(a.gettong() > b.gettong()) return b.gettong();
  76. // else{
  77. if(a.gettong() == b.gettong()){
  78. if(a.getten() < b.getten()) return a.getten();
  79. }
  80. // else return b.getten();
  81. // }
  82. // }
  83. }
  84. int main(){
  85. int n;
  86. cout<<"Nhap so luong sv: "; cin >> n;
  87. SV sv[n];
  88. cin.ignore();
  89. for(int i = 0; i < n; i++){
  90. sv[i].nhap();
  91. sv[i].tinh();
  92. }
  93. sort(sv,sv+n,cmp);
  94. cout<<endl<<"--------\n";
  95. cout<<setw(20)<<left<<"Ho va ten"
  96. <<setw(15)<<left<<"Ma sinh vien"
  97. <<setw(16)<<left<<"Ngay sinh"
  98. <<setw(10)<<left<<"Nganh"
  99. <<setw(13)<<left<<"Diem tong"
  100. <<setw(10)<<left<<"Xep loai"<<endl;
  101. for(int i = 0; i < n; i++){
  102. sv[i].xuat();
  103. }
  104.  
  105. }
Success #stdin #stdout 0.01s 5276KB
stdin
3
Do Hieu
123
IT
11 3 2005
7.8
9.2
10
Pham Huu Chinh
222
oto
3 1 2001
2
6
5
Nguyen Canh
333
it
1 3 2001
7.8
9.2
10
stdout
Nhap so luong sv: Nhap ho ten: Ma sinh vien: Nganh hoc: Ngay sinh(date): Nhap diem toan: Nhap diem van: Nhap diem tin: 
Nhap ho ten: Ma sinh vien: Nganh hoc: Ngay sinh(date): Nhap diem toan: Nhap diem van: Nhap diem tin: 
Nhap ho ten: Ma sinh vien: Nganh hoc: Ngay sinh(date): Nhap diem toan: Nhap diem van: Nhap diem tin: 

--------
Ho va ten           Ma sinh vien   Ngay sinh       Nganh     Diem tong    Xep loai  
Nguyen Canh         333            01/03/2001      it        8.8          Gioi      
Pham Huu Chinh      222            03/01/2001      oto       4.2          Trung binh
Do Hieu             123            11/03/2005      IT        8.8          Gioi