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