Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. https://github.com/triffon/oop-2019-20/tree/master/labs/5/Practice_01
  2.  
  3.  
  4.  
  5. #include<iostream>
  6. using namespace std;
  7.  
  8. const unsigned short gradeCount = 5;
  9.  
  10. struct Student{
  11. unsigned long long EGN;
  12. char firstName[30];
  13. char lastName[30];
  14. unsigned facNum;
  15. double grades[5];
  16.  
  17. void input() {
  18. cout<<"EGN: ";
  19. cin>>EGN;
  20. cout<<"ime: ";
  21. cin.get();
  22. cin.getline(firstName,29);
  23. cout<<"famil: ";
  24. cin.getline(lastName,29);
  25. cout<<"FN: ";
  26. cin>>facNum;
  27. cout<<"ocenki ("<<gradeCount<<" na broi): \n";
  28. for(int i=0; i<gradeCount; i++) {
  29. cin>>grades[i];
  30. }
  31. }
  32.  
  33. void print() {
  34. cout<<firstName<<" "<<lastName<<" "<<EGN<<" "<<facNum<<" ";
  35. for(int i=0;i<gradeCount;i++) {
  36. cout<<grades[i];
  37. }
  38. }
  39.  
  40. double avgGrade() {
  41. double sum=0;
  42. for(int i=0;i<gradeCount;i++) {
  43. sum+=grades[i];
  44. }
  45. return sum/gradeCount;
  46. }
  47. };
  48.  
  49. void addStudent(Student studs[], unsigned short &countS) {
  50. cout<<endl<<"Info about student " << countS+1<< ": \n";
  51. studs[countS].input();
  52. countS++;
  53. }
  54.  
  55. void printAllStudents(Student studs[], unsigned short countS) {
  56. cout<<endl;
  57. if(countS==0) {
  58. cout<<"nqma studenti v masiva";
  59. return;
  60. }
  61. for(unsigned short i=0; i<countS; i++) {
  62. studs[i].print();
  63. cout<<endl;
  64. }
  65. }
  66.  
  67. void printMarch(Student studs[], unsigned short countS) {
  68. cout<<endl;
  69. if(countS==0) {
  70. cout<<"nqma studenti v masiva";
  71. return;
  72. }
  73. for(unsigned short i=0; i<countS; i++) {
  74. if(((studs[i].EGN/1000000)%10)==3) {
  75. cout<<studs[i].firstName<<" "<<studs[i].lastName<<" "<<studs[i].avgGrade();
  76. }
  77. cout<<endl;
  78. }
  79. }
  80.  
  81. void avgGrades(Student studs[], unsigned short countS) {
  82. cout<<endl;
  83. if(countS==0) {
  84. cout<<"nqma studenti v masiva";
  85. return;
  86. }
  87. for(unsigned short i=0; i<countS; i++) {
  88. cout<<studs[i].avgGrade()<<endl;
  89. }
  90. }
  91.  
  92. void maxAvgGrade(Student studs[], unsigned short countS) {
  93. cout<<endl;
  94. if(countS==0) {
  95. cout<<"nqma studenti v masiva";
  96. return;
  97. }
  98. double maxG=0;
  99. for(unsigned short i=0; i<countS; i++) {
  100. double currG = studs[i].avgGrade();
  101. if(maxG<currG) maxG=currG;
  102. }
  103. cout<<maxG;
  104. }
  105.  
  106. int main() {
  107. const int MAX_STUD = 10;
  108. Student students[MAX_STUD];
  109. short unsigned studCount = 0;
  110.  
  111. int menuind=1;
  112. while(menuind) {
  113. cout<<"\n\n0 - exit \n1 - add new student \n2 - output march bois \n3 - output highest average grade \n";
  114. cin>>menuind;
  115. switch(menuind) {
  116. case 1:
  117. addStudent(students,studCount);
  118. break;
  119. case 2:
  120. printMarch(students,studCount);
  121. break;
  122. case 3:
  123. maxAvgGrade(students,studCount);
  124. break;
  125. }
  126. }
  127.  
  128. return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement