Advertisement
JosepRivaille

X39577: Mitjanes selectives

Sep 25th, 2015
1,123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include "Estudiant.hh"
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. using namespace std;
  6.  
  7.  
  8. void modify(vector<bool>& v, int    S) {
  9.   int n;
  10.   for (int i = 0; i < S; ++i) {
  11.     cin >> n;
  12.     v[n-1] = true;
  13.   }
  14. }
  15.  
  16. void operate(vector<Estudiant>& v, const vector<bool>& assig, int s, int N) {
  17.   int tam_v = v.size();
  18.   for (int i = 0; i < tam_v; ++i) {
  19.     int dni;
  20.     cin >> dni;
  21.     Estudiant al(dni);
  22.     v[i] = al;
  23.     double mark = 0;
  24.     for (int j = 0; j < N; ++j) {
  25.       double nota;
  26.       cin >> nota;
  27.       if (assig[j]) {
  28.     mark += nota;
  29.       }
  30.     }
  31.     mark /= s;
  32.     v[i].afegir_nota(mark);
  33.   }
  34. }
  35.  
  36. void escriu(const vector<Estudiant>& u) {
  37.   int tam = u.size();
  38.   for (int i = 0; i < tam; ++i) u[i].escriure();
  39. }
  40.  
  41.  
  42.  
  43. int main() {
  44.   int M, N, S;
  45.   cin >> M >> N >> S;
  46.   vector<bool> assig(N, false);
  47.   modify(assig, S);
  48.   vector<Estudiant> v(M);
  49.   operate(v,assig,S,N);
  50.   escriu(v);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement