Advertisement
Five_NT

Test_2

Apr 6th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.33 KB | None | 0 0
  1. /********************/
  2. /********************/
  3. /*      Catalog.h   */
  4. /********************/
  5. /********************/
  6. /********************/
  7. #pragma once
  8. #include <string>
  9. #include <map>
  10. #include <vector>
  11.  
  12. using namespace std;
  13. //completati in acest punct cu ce definiti considerati ca sunt necesare pentru ca proiectul sa compileze
  14.  
  15. class Catalog
  16. {
  17.     map<string, Student> Studenti;
  18.     map<string, int> Materii;
  19. public:
  20.     // 3p - daca exista deja returneaza false
  21.     // verificarea se face cu ignore case pentru numele studentului
  22.     bool AddStudent(string name) {
  23.         map<string, Student>::iterator it;
  24.         it = this->Studenti.find(name);
  25.         if (it == this->Studenti.end()) {
  26.             return false;
  27.         }
  28.     }
  29.  
  30.     // 1p - adauga o materie si numarul de credite asociat
  31.     // daca materia exista deja, returneaza false si nu updateaza creditele
  32.     // returneaza false si daca numarul de credite e mai mic decat 1
  33.     bool AddMaterie(string name, int credite) {
  34.         if (credite < 1) return false;
  35.         map<string, int>::iterator it;
  36.         it = this->Materii.find(name);
  37.         if (it == this->Materii.end()) {
  38.             this->Materii[name] = credite;
  39.         }
  40.         else return false;
  41.  
  42.     }
  43.  
  44.     // 1p - seteaza creditele la o materie (materia trebuie sa existe)
  45.     // returneaza false si daca numarul de credite e mai mic decat 1
  46.     bool operator() (string materie, int credite) {
  47.         if (credite < 1) return false;
  48.         map<string, int>::iterator it;
  49.         it = this->Materii.find(materie);
  50.         if (it != this->Materii.end()) {
  51.             this->Materii[materie] = credite;
  52.         }
  53.         else return false;
  54.     }
  55.  
  56.     // 4p - returneaza -1 daca studentul nu exista
  57.     // -2 daca materia nu exista
  58.     // -3 daca nici studentul nici materia nu exista
  59.     // 0 data studentul exista dar nu are nota la materie
  60.     // sau nota studentului
  61.     // verificarea numelui studentului si a materiei se face cu ignore case
  62.     int GetNota(string student, string materie) {
  63.    
  64.         return 0;
  65.     }
  66.        
  67.  
  68.     // 1p - returneaza referinta catre un student
  69.     //Student& operator[](string nume) {
  70.     //  return *0;
  71.     //}
  72.  
  73.     // 4p - returneaza cel mai bun student dupa media ponderata la toate materiile
  74.     // daca cineva nu are o nota la o materie, se considera ca are 0 credite acolo
  75.     Student* GetBestStudent(int& credite) {
  76.         /*map<string, int>::iterator it;
  77.         for (auto i : Studenti) {
  78.             int media[i.size()];
  79.             for (auto j : Note) {
  80.                 media[i] += Note[j->second];
  81.  
  82.             }
  83.             media[i] /= i.size();
  84.         }
  85.  
  86.         int maxim = media[0];
  87.         for (int i = 1; i < i.size(); i++)
  88.             if (maxim < media[i])
  89.                 maxim = media[i];
  90.  
  91.         return i;*/
  92.     }
  93.  
  94.     // 2p - returneaza lista de studenti
  95.     // pair-ul contine obiectul student si media la materia in cauza
  96.     vector<pair<Student, int>> GetStudentList(string materie) {
  97.  
  98.     }
  99. };
  100.  
  101.  
  102.  
  103. /********************/
  104. /********************/
  105. /*      Student.h   */
  106. /********************/
  107. /********************/
  108. /********************/
  109. #pragma once
  110. #include <map>
  111. #include <string>
  112.  
  113. using namespace std;
  114.  
  115. //completati in acest punct cu ce definiti considerati ca sunt necesare pentru ca proiectul sa compileze
  116.  
  117. class Student
  118. {
  119.     // Numele studentului
  120.     string Name;
  121.     // map cu notele studentului (Cheia este numele materiei, iar valoarea este nota)
  122.     // map<nume_materie,nota_la_materie>
  123.     map<string, int> Note;
  124. public:
  125.     // 2p - toti 3 constructorii
  126.     Student() {
  127.     };
  128.     Student(const char *name) {
  129.         this->Name = name;
  130.     }
  131.     Student(const Student &student) {
  132.  
  133.     }
  134.  
  135.     // 1p
  136.     string GetName() {
  137.         //return this->Name;
  138.  
  139.         return 0;
  140.     }
  141.  
  142.     // 1p - returneaza true daca are nota la materia in cauza, false altfel
  143.     bool operator() (string numeMaterie) {
  144.         map<string, int>::iterator it;
  145.         it = Note.find(numeMaterie);
  146.         if (it == Note.end())
  147.             return false;
  148.         else
  149.         {
  150.             if (it->second == 0)
  151.                 return false;
  152.             else return true;
  153.         }
  154.     }
  155.  
  156.     // 1p - returneaza nota de la materie (se prespune ca materia exista)
  157.     int operator[] (string numeMaterie) {
  158.         map<string, int>::iterator it;
  159.         it = Note.find(numeMaterie);
  160.        
  161.         return it->second;
  162.     }
  163.  
  164.     // 2p - seteaza nota pentru o materie
  165.     // daca materie nu exista o adauga
  166.     // returneaza false daca nota este invalida (<1 sau >10)
  167.     bool SetNota(string materie, int nota) {
  168.         if (nota < 1 || nota > 10) return false;
  169.         map<string, int>::iterator it;
  170.         it = Note.find(materie);
  171.         if (it == Note.end()) {
  172.             Note[materie] = nota;
  173.             return true;
  174.         }
  175.         else {
  176.             return false;
  177.         }
  178.     }
  179. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement