csansoon

P9.02 P11141 Students

Dec 1st, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. struct Student {
  5.     int idn;
  6.     string name;
  7.     double mark;        // The mark is a value between 0 and 10, or -1 that represents NP
  8.     bool repeater;
  9. };
  10. void information(const vector<Student>& stu, double& min, double& max, double& avg) {
  11.     int repeaters=0;
  12.     bool first=true;
  13.     for (int i=0; i<stu.size(); ++i) {
  14.         if (stu[i].repeater or stu[i].mark==-1) ++repeaters;
  15.         else {
  16.             if (first) {
  17.                 min=stu[i].mark;
  18.                 max=stu[i].mark;
  19.                 avg=stu[i].mark;
  20.                 first=false;
  21.             }
  22.             else avg = avg + stu[i].mark;
  23.             if (stu[i].mark<min) min=stu[i].mark;
  24.             if (stu[i].mark>max) max=stu[i].mark;
  25.         }
  26.     }
  27.     if (repeaters==stu.size()) {
  28.         min=-1;
  29.         max=-1;
  30.         avg=-1;
  31.     }
  32.     else avg = avg /(stu.size()-repeaters);
  33. }
  34.  
  35. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Add Comment
Please, Sign In to add comment