---
# System prepended metadata

title: Untitled

---

1. Sa se citeasca din fisierul magazine.txt un numar N si apoi N magazine de forma:
    char nume[50];
    float chirie;
    int numar_clienti;
2. Sa se afiseze numele magazinelor in ordine alfabetica inversa
3. Sa se afiseze total de clienti din toate magazinele
4. Sa se sorteze lista de magazine in functie de chirie (crescator)
5. sa se afiseze top 3 magazine cu cei mai multi clienti
6. sa se afiseze magazinele care intre 100 si 300 de clienti 


```
10
Zara
150.0
300
H&M
300.5
70
IStyle
147.7
500
Bershka
221.89
297
C&A
255.2
920
KFC
299.99
1000
Levi's
289.02
920
Pandora
3000
907
Vans
500.1
973
OroToro
789.33
101
```

```cpp=
#include <iostream>
#include <fstream>
#include <algorithm> 

using namespace std;

typedef struct Magazin {
    char nume[50];
    float chirie;
    int numar_clienti;
} Magazin;

void afisare_magazin(Magazin magazin) {
    cout << magazin.nume << "\t\t" << magazin.chirie << "\t\t" << magazin.numar_clienti << endl;
}

void afisare(Magazin lista_magazine[10], int numar_magazine) {
    for (int i = 0; i < numar_magazine; i++) {
        afisare_magazin(lista_magazine[i]);
    }
}

void sortare_nume_invers_alfabetic(Magazin lista_magazine[10], int numar_magazine) {
    for(int i = 0; i < numar_magazine; i++) {
        for(int j = 0; j < numar_magazine; j++) {
            if (strcmp(lista_magazine[i].nume, lista_magazine[j].nume) > 0) {
                Magazin aux = lista_magazine[i];
                lista_magazine[i] = lista_magazine[j];
                lista_magazine[j] = aux;
            }
        }
    }
    afisare(lista_magazine, numar_magazine);
}

void sortare_chirie(Magazin lista_magazine[10], int numar_magazine) {
    for(int i = 0; i < numar_magazine; i++) {
        for(int j = 0; j < numar_magazine; j++) {
            if (lista_magazine[i].chirie < lista_magazine[j].chirie) {
                Magazin aux = lista_magazine[i];
                lista_magazine[i] = lista_magazine[j];
                lista_magazine[j] = aux;
            }
        }
    }
    afisare(lista_magazine, numar_magazine);
}

void top_3_clienti(Magazin lista_magazine[10], int numar_magazine) {
    for(int i = 0; i < numar_magazine; i++) {
        for(int j = 0; j < numar_magazine; j++) {
            if (lista_magazine[i].numar_clienti > lista_magazine[j].numar_clienti) {
                Magazin aux = lista_magazine[i];
                lista_magazine[i] = lista_magazine[j];
                lista_magazine[j] = aux;
            }
        }
    }
    afisare(lista_magazine, 3);
}


int total_clienti(Magazin lista_magazine[10], int numar_magazine) {
    int total = 0;
    for (int i = 0; i < numar_magazine; i++) {
        total += lista_magazine[i].numar_clienti;
    }
    return total;
}

void magazine_cu_100_300_clienti(Magazin lista_magazine[10], int numar_magazine) {
    for (int i = 0; i < numar_magazine; i++) {
        if (100 <= lista_magazine[i].numar_clienti && lista_magazine[i].numar_clienti <= 300){
            afisare_magazin(lista_magazine[i]);
        }
    }
}

int main() {
    ifstream fin("magazine.txt");
    int numar_magazine;
    Magazin lista_magazine[10];
    
    fin >> numar_magazine;
    for (int i = 0; i < numar_magazine; i++) {
        fin >> lista_magazine[i].nume;
        fin >> lista_magazine[i].chirie;
        fin >> lista_magazine[i].numar_clienti;
    }
    afisare(lista_magazine, numar_magazine);
    cout << endl;
    cout << "----------- 1 -----------\n";
    sortare_nume_invers_alfabetic(lista_magazine, numar_magazine);
    cout << endl;

    cout << "----------- 2 -----------\n";
    cout << "Numarul total de clienti este: " << total_clienti(lista_magazine, numar_magazine) ;
    cout << endl;

    cout << "----------- 3 -----------\n";
    sortare_chirie(lista_magazine, numar_magazine);
    cout << endl;

    cout << "----------- 4 -----------\n";
    top_3_clienti(lista_magazine, numar_magazine);
    cout << endl;

    cout << "----------- 5 -----------\n";
    magazine_cu_100_300_clienti(lista_magazine, numar_magazine);
    cout << endl;

    return 0;
}
```