Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. //===================================================
  2. // Nome: Filipe Conceição
  3. // Número de aluno: 2014196660
  4. // Turma: PL6
  5. // Folha: 9ª
  6. //===================================================
  7. #include <iostream>
  8. #include <string>
  9. using namespace std;
  10.  
  11. struct clube
  12. {
  13. string nome; // nome do clube (mais do que uma palavra)
  14. string cidade; // nome da cidade a que pertence (mais do que uma palavra)
  15. unsigned int ano; // ano da sua fundacao
  16. float orcamento; // orcamento anual
  17. };
  18.  
  19. const int MAX_DIM = 150;
  20.  
  21. void le_clube(clube &um);
  22. int elem(clube tab[]);
  23. void mostra(clube tab[], int dim);
  24. int ano_antigo(clube tab[], int dim);
  25.  
  26. int main()
  27. {
  28. struct clube tab[MAX_DIM];
  29. int dim;
  30. dim = elem(tab);
  31. mostra(tab,dim);
  32. cout << "O ano mais antigo dentro dos clubes armazenados e: " << ano_antigo(tab,dim) << endl;
  33. return(0);
  34. }
  35.  
  36. void le_clube(clube &um)
  37. {
  38. cin.ignore(1000,'\n');
  39. cout << "Introduza o nome do clube: " << endl;
  40. getline(cin,um.nome);
  41. cout << "Introduza a cidade a que pertence o clube: " << endl;
  42. getline(cin,um.cidade);
  43. cout << "Introduza o ano em que o clube foi fundado: " << endl;
  44. cin >> um.ano;
  45. cout << "Introduza o orcamento anual do clube: " << endl;
  46. cin >> um.orcamento;
  47. }
  48.  
  49. int elem(clube tab[])
  50. {
  51. int dim;
  52. do
  53. {
  54. cout << "Introduza o numero de elementos a preencher (max. " << MAX_DIM << "): ";
  55. cin >> dim;
  56. }while(dim > MAX_DIM);
  57.  
  58. for(int i = 0; i < dim; i++)
  59. {
  60. le_clube(tab[i]);
  61. }
  62.  
  63. return(dim);
  64. }
  65.  
  66. void mostra(clube tab[], int dim)
  67. {
  68. for(int i = 0; i < dim; i++)
  69. {
  70. cout << tab[i].nome << ' ' << tab[i].cidade << ' ' << tab[i].ano << ' ' << tab[i].orcamento << endl;
  71. }
  72. }
  73. int ano_antigo(clube tab[], int dim)
  74. {
  75. unsigned int menor;
  76. for(int i = 0;i < dim;i++)
  77. {
  78. if(i == 0)
  79. {
  80. menor = tab[i].ano;
  81. }
  82. else
  83. {
  84. if(tab[i].ano < menor)
  85. {
  86. menor = tab[i].ano;
  87. }
  88. }
  89. }
  90. return(menor);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement