Advertisement
Guest User

ciao

a guest
Feb 9th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. const int max = 5;
  5. int testa = max;
  6. int i = 5;
  7.  
  8. struct persona{
  9. string cognome;
  10. };
  11. typedef struct persona uomo;
  12. uomo tabella[max];
  13.  
  14.  
  15. void menu()
  16. {
  17. cout << "MENU: \n";
  18. cout << "1. Caricamento dati: \n";
  19. cout << "2. Percentuale di persone che si chiamano Smith: \n";
  20. cout << "3. Estrazione: \n";
  21. cout << "4. Visualizzazione prime due persone non si chiamano White: \n"; //?????????
  22. }
  23.  
  24. void push(uomo a[max], int x)
  25. {
  26. if (testa == 0){
  27. cout << "La pila è piena! \n";
  28. }
  29. else{
  30. caricamento(tabella, max);
  31. }
  32. }
  33.  
  34. void caricamento(uomo a[max], int x)
  35. {
  36. string cogn; int conta = 0;
  37. while (conta > 3){
  38. cout << "Inserire il cognome: \n";
  39. cin >> cogn;
  40. a[i].cognome = cogn;
  41. i--;
  42. testa--; }
  43. }
  44.  
  45. void percentuale(uomo a[max], int x)
  46. {
  47. int j; int conta1 = 0; float perc;
  48. for (j = 0; j < testa; j++)
  49. {
  50. while (a[j].cognome != "Smith")
  51. {
  52. conta1 += 1;
  53. }
  54. perc = (conta1 / testa) * 100;
  55. cout << "La percentuale è: \n" << perc;
  56. }
  57. }
  58.  
  59. void pop(uomo a[max], int x) //giusta???
  60. {
  61. if (testa == max)
  62. {
  63. cout << "La pila è vuota, impossibile estrarre un dato! \n";
  64. }
  65. else {
  66. cout << "Il cognome dell'ultimo uomo inserito è: \n" << a[testa + 1].cognome;
  67. testa++;
  68. }
  69. }
  70.  
  71. void visualizzazione(uomo a[max], int x)
  72. {
  73. int conta2 = 0;
  74. while (a[i].cognome == "White" || conta2 > 2)
  75. {
  76. conta2 += 1;
  77. cout << "I cognomi saranno: \n" << a[i].cognome;
  78. }
  79. }
  80.  
  81. int main()
  82. {
  83. int scelta;
  84. do{
  85. do{
  86. menu();
  87. cout << "Selezionare una voce da menu: \n";
  88. cin >> scelta;
  89. } while (scelta<1 || scelta>5);
  90. switch (scelta)
  91. {
  92. case 1:
  93. push(tabella, max);
  94. break;
  95. case 2:
  96. percentuale(tabella, max);
  97. break;
  98. case 3:
  99. pop(tabella, max); //giusta???
  100. break;
  101. case 4:
  102. visualizzazione(tabella, max);
  103. break;
  104. }
  105. } while (scelta != 5);
  106. system("PAUSE");
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement