Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. bool next = true;
  8. int jmlMhs;
  9. string mhs[20][2];
  10. int nilai[20][4];
  11.  
  12. void getMhs();
  13. void display();
  14. char getGrade(int nilai);
  15. float getAverage();
  16. int getMax();
  17. int getMin();
  18.  
  19. int main()
  20. {
  21. do{
  22. system("cls");
  23. cout << "================================" << endl;
  24. cout << "========= Hitung Nilai =========" << endl;
  25. cout << "================================" << endl;
  26.  
  27. cout << "Jumlah mahasiswa (max 30) : " ;
  28. cin >> jmlMhs;
  29.  
  30. getMhs();
  31.  
  32. display();
  33.  
  34. char x;
  35. cout << endl << "Ulang kembali ? (Y/N)" << endl;
  36. cin >> x;
  37. if(x == 'N' || x == 'n')
  38. next = false;
  39.  
  40. }while(next == true);
  41. return 0;
  42. }
  43.  
  44. void display(){
  45. system("cls");
  46. cout << " DAFTAR NILAI" << endl;
  47. cout << " PRODI TEKNIK INFORMATIKA" << endl;
  48. cout << "=================================================================" << endl;
  49. cout << ": No : NIM : NAMA : UTS : UAS : TUGAS : GRADE :" << endl;
  50. cout << "=================================================================" << endl;
  51. for(int i = 0; i < jmlMhs; i++){
  52. nilai[i][3] = (nilai[i][0] + nilai[i][1] + nilai[i][2]) / 3;
  53. cout << ":" << setw(3) << i+1 << setw(2) << ":"<< setw(8) << mhs[i][0] << setw(4)
  54. << ":" << setw(15) << mhs[i][1] << setw(4) << ":" << setw(4) << nilai[i][0] << setw(2)
  55. << ":" << setw(4) << nilai[i][1] << setw(2) << ":" << setw(4) << nilai[i][2] << setw(4)
  56. << ":" << setw(4) << getGrade(nilai[i][3]) << setw(4) << ":" << endl;
  57. }
  58. cout << "=================================================================" << endl;
  59. cout << "Jumlah data : " << jmlMhs << endl;
  60. cout << "Rata kelas : " << getAverage() << endl;
  61. cout << "Nilai tertinggi : " << getMax() << endl;
  62. cout << "Nilai terendah : " << getMin() << endl;
  63. }
  64.  
  65. void getMhs(){
  66. system("cls");
  67. for(int i = 0; i < jmlMhs; i++){
  68. cout << "===================" << endl;
  69. cout << "=== Mahasiswa " << i+1 << " ===" << endl;
  70. cout << "===================" << endl;
  71. cout << "NIM : ";
  72. cin >> mhs[i][0];
  73. cout << "Nama : ";
  74. cin >> mhs[i][1];
  75. cout << "UTS : ";
  76. cin >> nilai[i][0];
  77. cout << "UAS : ";
  78. cin >> nilai[i][1];
  79. cout << "Tugas : ";
  80. cin >> nilai[i][2];
  81. cout << endl;
  82. }
  83. }
  84.  
  85. float getAverage(){
  86. float jml = 0;
  87. for(int i = 0; i < jmlMhs; i++){
  88. jml += nilai[i][3];
  89. }
  90. return jml / jmlMhs;
  91. }
  92.  
  93. char getGrade(int nilai){
  94. if(nilai <= 50)
  95. return 'E';
  96. else if(nilai <= 60)
  97. return 'D';
  98. else if(nilai <= 70)
  99. return 'C';
  100. else if(nilai <= 80)
  101. return 'B';
  102. else
  103. return 'A';
  104. }
  105.  
  106. int getMax(){
  107. int max = nilai[0][3];
  108. for(int i = 0; i < jmlMhs; i++){
  109. if(nilai[i][3] > max)
  110. max = nilai[i][3];
  111. }
  112. return max;
  113. }
  114.  
  115. int getMin(){
  116. int min = nilai[0][3];
  117. for(int i = 0; i < jmlMhs; i++){
  118. if(nilai[i][3] < min)
  119. min = nilai[i][3];
  120. }
  121. return min;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement