Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #define Righe 5
  4. #define Colonne 5
  5. #define MAXSURNAME 30
  6. #define NETA 10
  7.  
  8. using namespace std;
  9.  
  10. struct FAMIGLIA
  11. {
  12. char cognome[MAXSURNAME];
  13. unsigned int numComponenti;
  14. unsigned int eta[NETA];
  15. };
  16.  
  17. // prototipi di funzioni
  18. void leggi (FAMIGLIA a[][Colonne]);
  19. void stampa (FAMIGLIA a[][Colonne]);
  20. void piuanziano (FAMIGLIA a[][Colonne]);
  21. void piugiovane (FAMIGLIA a[][Colonne]);
  22.  
  23.  
  24. int main (){
  25.  
  26. FAMIGLIA famiglia[Righe][Colonne];
  27. /* chiamata alle funzioni */
  28. leggi (famiglia);
  29.  
  30. stampa (famiglia);
  31.  
  32. piuanziano (famiglia);
  33.  
  34. piugiovane (famiglia);
  35.  
  36. return 0;
  37. }
  38.  
  39.  
  40. void leggi (FAMIGLIA a[Righe][Colonne]) {
  41. int i, j;
  42. for (i = 0; i < Righe; ++i)
  43. for (j = 0; j < Colonne; ++j) {
  44. cout << "Inserire cognome: " << endl;
  45. cin >> a[i][j].cognome;
  46. cout << "Quanti componenti siete in famiglia: " << endl;
  47. cin >> a[i][j].numComponenti;
  48. for(int k = 0; k < a[i][j].numComponenti; ++k){
  49. cout << "Quanti anni hai? " << endl;
  50. cin >> a[i][j].eta[k];
  51. }
  52. }
  53. }
  54.  
  55. void stampa (FAMIGLIA a[Righe][Colonne]) {
  56. int i, j;
  57. for (i = 0; i < Righe; i ++) {
  58. for (j = 0; j < Colonne; j ++) {
  59. cout << "cognome: " << a[i][j].cognome << endl;
  60. cout << "componenti nella famiglia: " << a[i][j].numComponenti << endl;
  61. for(int k = 0; k < a[i][j].numComponenti; ++k){
  62. cout << "età: " << a[i][j].eta[k] << endl;
  63. }
  64. }
  65. }
  66. }
  67.  
  68. void piuanziano (FAMIGLIA a[Righe][Colonne]){
  69. int i , j;
  70. unsigned int anziano = a[0][0].eta[0];
  71. for( i = 0 ; i < Righe; i ++) {
  72. for(j = 0 ; j < Colonne; j ++){
  73. for(int k = 0; k < a[i][j].numComponenti; ++k)
  74. if(a[i][j].eta[k] > anziano)
  75. anziano = a[i][j].eta[k];
  76. }
  77. }
  78. cout << "il più anziano ha: " << anziano << " anni" << endl;
  79. }
  80. void piugiovane (FAMIGLIA a[Righe][Colonne]){
  81. int i , j;
  82. unsigned int giovane = a[0][0].eta[0];
  83. for( i = 0 ; i < Righe; i ++) {
  84. for(j = 0 ; j < Colonne; j ++){
  85. for(int k = 0; k < a[i][j].numComponenti; ++k)
  86. if(a[i][j].eta[k] < giovane)
  87. giovane = a[i][j].eta[k];
  88. }
  89. }
  90. cout << "il più giovane ha: " << giovane << " anni" << endl;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement