bogdanNiculeasa

proiect elevi

Oct 14th, 2021
711
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. struct nod {
  8.     char nume[50];
  9.     char prenume[50];
  10.     float notaLimbaRomana;
  11.     float notaMatematica;
  12.     float notaPurtare;
  13.     float medieGenerala;
  14.     nod* next;
  15. };
  16.  
  17. void initializare(nod* &p);
  18. void adaugareDreapta(nod* &p, nod* &u);
  19. void afisare(nod * p);
  20. int numarDeElementeInLista(nod *p);
  21. float calculareMedieGeneralaEleviPromovati(nod *p);
  22. int eCorigent(nod *elev);
  23. void afisareEleviPromovatiInOrdineDescAMediei(nod * &p);
  24. int calculEleviPromovati(nod *p);
  25. void afisareStudentiCorigenti(nod * p);
  26.  
  27. int main() {
  28.     ifstream file("elevi.in");
  29.     char line[255];
  30.     nod* primulStudent = nullptr;
  31.  
  32.     while (file.getline(line, sizeof(line))) {
  33.         char *token = strtok(line, ",");
  34.         nod *studentulCurent = new nod;
  35.         strcpy(studentulCurent->nume, token);
  36.         token = strtok(NULL, ",");
  37.         strcpy(studentulCurent->prenume, token);
  38.         token = strtok(NULL, ",");
  39.         studentulCurent->notaLimbaRomana = atof(token);\
  40.         token = strtok(NULL, ",");
  41.         studentulCurent->notaMatematica = atof(token);
  42.         token = strtok(NULL, ",");
  43.         studentulCurent->notaPurtare = atof(token);
  44.         token = strtok(NULL, ",");
  45.         studentulCurent->medieGenerala = atof(token);
  46.         if (primulStudent == nullptr) {
  47.             primulStudent = studentulCurent;
  48.             initializare(primulStudent);
  49.         } else {
  50.            adaugareDreapta(primulStudent, studentulCurent);
  51.         }
  52.     }
  53.     afisare(primulStudent);
  54.     cout << "Cerinta 1. \n";
  55.     cout << "Media generala a elevilor care nu sunt corigenti: " << calculareMedieGeneralaEleviPromovati(primulStudent);
  56.     cout << "\nCerinta 2.\n";
  57.     cout << "Afisare elevi promovati in ordinea descrescatoare a mediei generale: \n";
  58.     afisareEleviPromovatiInOrdineDescAMediei(primulStudent);
  59.     cout <<"\nCerinta 3\n";
  60.     cout << "Afisare baza de date elevi corigenti:\n ";
  61.     afisareStudentiCorigenti(primulStudent);
  62. }
  63.  
  64. void initializare(nod* &primulNod) {
  65.     {
  66.         primulNod->next = nullptr;
  67.     }
  68. }
  69.  
  70. void adaugareDreapta(nod* &primulNod, nod* &nodDeAdaugat) {
  71.     nod *curent;
  72.     curent = primulNod;
  73.     while (curent->next != nullptr){
  74.         curent = curent->next;
  75.     }
  76.     curent->next = nodDeAdaugat;
  77.     nodDeAdaugat->next = nullptr;
  78. }
  79.  
  80. void afisareEleviPromovatiInOrdineDescAMediei(nod * &p) {
  81.     nod *elevulCurent;
  82.     elevulCurent = p;
  83.     int numarEleviPromovati = calculEleviPromovati(elevulCurent);
  84.     struct nod eleviPromovati[numarEleviPromovati];
  85.  
  86.     int i =0;
  87.     while (elevulCurent != nullptr) {
  88.         if (!eCorigent(elevulCurent)) {
  89.             eleviPromovati[i] = *elevulCurent;
  90.             i++;
  91.         }
  92.         elevulCurent = elevulCurent->next;
  93.     }
  94.  
  95.     for (int i = 0; i < numarEleviPromovati; i++) {
  96.         for (int j = 0; j < numarEleviPromovati-1; j++) {
  97.             if (eleviPromovati[j].medieGenerala < eleviPromovati[j+1].medieGenerala) {
  98.                 nod temp = eleviPromovati[i];
  99.                 eleviPromovati[i] = eleviPromovati[j];
  100.                 eleviPromovati[j] = temp;
  101.             }
  102.         }
  103.     }
  104.  
  105.     for (int i = 0; i < numarEleviPromovati; i++) {
  106.         cout << eleviPromovati[i].nume << " " << eleviPromovati[i].prenume << endl;
  107.     }
  108. }
  109.  
  110.  
  111. float calculareMedieGeneralaEleviPromovati(nod* primulNod) {
  112.     int numarElevi=0;
  113.     float sumaNote = 0.0;
  114.     nod *temp = primulNod;
  115.     while (temp->next != nullptr) {
  116.         if (!eCorigent(temp)) {
  117.             sumaNote += temp->medieGenerala;
  118.             numarElevi++;
  119.         }
  120.         temp = temp->next;
  121.     }
  122.     return sumaNote / numarElevi;
  123. }
  124.  
  125. int eCorigent(nod* elev) {
  126.     if (elev->notaMatematica < 5 || elev->notaLimbaRomana < 5) {
  127.         return 1;
  128.     } else {
  129.         return 0;
  130.     }
  131. }
  132.  
  133. void adaugareStanga(nod* &primulNod, nod* &nodDeAdaugat) {
  134.     nodDeAdaugat->next = primulNod;
  135.     primulNod = nodDeAdaugat;
  136. }
  137.  
  138. void afisare(nod * p) {
  139.     nod *c;
  140.     c = p;
  141.     while (c != 0) {
  142.         cout<<"Nume: " << c->nume <<"\t";
  143.         cout<<"\nPrenume: " << c->prenume <<"\t";
  144.         cout<<"\nNota Lb. Romana: " << c->notaLimbaRomana << "\t";
  145.         cout<<"\nNota Matematica: " << c->notaMatematica << "\t";
  146.         cout<<"\nNota Purtare: " << c->notaPurtare << "\t";
  147.         cout<<"\nNota Media Generala: " << c->medieGenerala << "\t";
  148.         c = c->next;
  149.         cout << endl<<endl<<endl;
  150.     }
  151. }
  152. void afisareStudentiCorigenti(nod * p) {
  153.     nod *elevulCurent;
  154.     elevulCurent = p;
  155.     while (elevulCurent != 0) {
  156.         if (eCorigent(elevulCurent)) {
  157.             cout<<"Nume: " << elevulCurent->nume <<"\t";
  158.             cout<<"\nPrenume: " << elevulCurent->prenume <<"\t";
  159.             cout << endl;
  160.         }
  161.         elevulCurent = elevulCurent->next;
  162.     }
  163. }
  164.  
  165.  
  166. int calculEleviPromovati(nod *p) {
  167.     int numar = 0;
  168.     nod  *c = p;
  169.     while(c != nullptr) {
  170.         if (!eCorigent(c)) {
  171.             numar++;
  172.         }
  173.         c = c->next;
  174.     }
  175.     return numar;
  176. }
  177.  
RAW Paste Data