fork(1) download
  1. #include <iostream>
  2. #include <malloc.h>
  3. using namespace std;
  4.  
  5. typedef struct
  6. {
  7. char id[9];
  8. char name[20];
  9. float Marks[3];
  10. float DTB;
  11. }Student;
  12.  
  13. void xeploai (Student S)
  14. {
  15. if (S.DTB >= 8) cout << "Gioi";
  16. else if (S.DTB >= 7) cout << "Kha";
  17. else if (S.DTB >= 5) cout << "Trung binh";
  18. else cout << "Yeu";
  19. }
  20.  
  21. void nhap_sv(Student &sv)
  22. {
  23. cout << "Nhap id: ";
  24. cin.get(sv.id, 9);
  25. cin.ignore();
  26. cout << "Nhap name: ";
  27. cin.get(sv.name, 20);
  28. cout << "Marks: baitap, giuaky, cuoiky: ";
  29. for (int i = 0; i < 3; i++)
  30. {
  31. cin >> sv.Marks[i];
  32. }
  33. sv.DTB = sv.Marks[0] * 0.25 + sv.Marks[1] * 0.25 + sv.Marks[2]*0.5;
  34. }
  35.  
  36. void nhapDanhSach_sv(Student* &sv, const int &n)
  37. {
  38. sv = (Student*)calloc(n, sizeof(Student));
  39. if (sv == NULL) return;
  40. for (int i = 0; i < n; i++)
  41. {
  42. nhap_sv(sv[i]);
  43. }
  44. }
  45.  
  46. void xuatDanhSach_sv(Student* &sv, const int &n)
  47. {
  48. if (sv == NULL) return;
  49. for (int i = 0; i < n; i++)
  50. {
  51. cout << "Thong tin sinh vien thu " << i + 1 << "\n";
  52. cout << "MSSV: " << sv[i].id << "\n";
  53. cout << "Ho va ten: " << sv[i].name << "\n";
  54. cout << "Diem so: Bai tap, giua ky, cuoi ky: " << "\n";
  55. for (int j = 0; j < 3; j++)
  56. {
  57. cout << sv[i].Marks[j] << "\t";
  58. }
  59. cout << "\nDiem trung binh: " << sv[i].DTB << "\n";
  60. cout << "Xep loai: \n";
  61. xeploai(sv[i]);
  62. cout << "\n";
  63. }
  64. }
  65.  
  66. Student* sv_pushback(Student* &sv, int &n)
  67. {
  68. void* p = sv;
  69. n++;
  70. sv = (Student*)realloc(p, n);
  71. nhap_sv(sv[n - 1]);
  72. return sv;
  73. }
  74.  
  75. int main()
  76. {
  77. Student* a;
  78. int n;
  79. cout << "Nhap so sinh vien n = ";
  80. cin >> n;
  81. nhapDanhSach_sv(a, n);
  82. xuatDanhSach_sv(a, n);
  83. return 0;
  84. }
Success #stdin #stdout 0s 5376KB
stdin
1
stdout
Nhap so sinh vien n = Nhap id: Nhap name: Marks: baitap, giuaky, cuoiky: Thong tin sinh vien thu 1
MSSV: 
Ho va ten: 
Diem so: Bai tap, giua ky, cuoi ky: 
0	0	0	
Diem trung binh: 0
Xep loai: 
Yeu