Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- const int max = 5;
- int testa = max;
- int i = 5;
- struct persona{
- string cognome;
- };
- typedef struct persona uomo;
- uomo tabella[max];
- void menu()
- {
- cout << "MENU: \n";
- cout << "1. Caricamento dati: \n";
- cout << "2. Percentuale di persone che si chiamano Smith: \n";
- cout << "3. Estrazione: \n";
- cout << "4. Visualizzazione prime due persone non si chiamano White: \n"; //?????????
- }
- void push(uomo a[max], int x)
- {
- if (testa == 0){
- cout << "La pila è piena! \n";
- }
- else{
- caricamento(tabella, max);
- }
- }
- void caricamento(uomo a[max], int x)
- {
- string cogn; int conta = 0;
- while (conta > 3){
- cout << "Inserire il cognome: \n";
- cin >> cogn;
- a[i].cognome = cogn;
- i--;
- testa--; }
- }
- void percentuale(uomo a[max], int x)
- {
- int j; int conta1 = 0; float perc;
- for (j = 0; j < testa; j++)
- {
- while (a[j].cognome != "Smith")
- {
- conta1 += 1;
- }
- perc = (conta1 / testa) * 100;
- cout << "La percentuale è: \n" << perc;
- }
- }
- void pop(uomo a[max], int x) //giusta???
- {
- if (testa == max)
- {
- cout << "La pila è vuota, impossibile estrarre un dato! \n";
- }
- else {
- cout << "Il cognome dell'ultimo uomo inserito è: \n" << a[testa + 1].cognome;
- testa++;
- }
- }
- void visualizzazione(uomo a[max], int x)
- {
- int conta2 = 0;
- while (a[i].cognome == "White" || conta2 > 2)
- {
- conta2 += 1;
- cout << "I cognomi saranno: \n" << a[i].cognome;
- }
- }
- int main()
- {
- int scelta;
- do{
- do{
- menu();
- cout << "Selezionare una voce da menu: \n";
- cin >> scelta;
- } while (scelta<1 || scelta>5);
- switch (scelta)
- {
- case 1:
- push(tabella, max);
- break;
- case 2:
- percentuale(tabella, max);
- break;
- case 3:
- pop(tabella, max); //giusta???
- break;
- case 4:
- visualizzazione(tabella, max);
- break;
- }
- } while (scelta != 5);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement