Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===================================================
- // Nome: Filipe Conceição
- // Número de aluno: 2014196660
- // Turma: PL6
- // Folha: 9ª
- //===================================================
- #include <iostream>
- #include <string>
- using namespace std;
- struct clube
- {
- string nome; // nome do clube (mais do que uma palavra)
- string cidade; // nome da cidade a que pertence (mais do que uma palavra)
- unsigned int ano; // ano da sua fundacao
- float orcamento; // orcamento anual
- };
- const int MAX_DIM = 150;
- void le_clube(clube &um);
- int elem(clube tab[]);
- void mostra(clube tab[], int dim);
- int ano_antigo(clube tab[], int dim);
- int main()
- {
- struct clube tab[MAX_DIM];
- int dim;
- dim = elem(tab);
- mostra(tab,dim);
- cout << "O ano mais antigo dentro dos clubes armazenados e: " << ano_antigo(tab,dim) << endl;
- return(0);
- }
- void le_clube(clube &um)
- {
- cin.ignore(1000,'\n');
- cout << "Introduza o nome do clube: " << endl;
- getline(cin,um.nome);
- cout << "Introduza a cidade a que pertence o clube: " << endl;
- getline(cin,um.cidade);
- cout << "Introduza o ano em que o clube foi fundado: " << endl;
- cin >> um.ano;
- cout << "Introduza o orcamento anual do clube: " << endl;
- cin >> um.orcamento;
- }
- int elem(clube tab[])
- {
- int dim;
- do
- {
- cout << "Introduza o numero de elementos a preencher (max. " << MAX_DIM << "): ";
- cin >> dim;
- }while(dim > MAX_DIM);
- for(int i = 0; i < dim; i++)
- {
- le_clube(tab[i]);
- }
- return(dim);
- }
- void mostra(clube tab[], int dim)
- {
- for(int i = 0; i < dim; i++)
- {
- cout << tab[i].nome << ' ' << tab[i].cidade << ' ' << tab[i].ano << ' ' << tab[i].orcamento << endl;
- }
- }
- int ano_antigo(clube tab[], int dim)
- {
- unsigned int menor;
- for(int i = 0;i < dim;i++)
- {
- if(i == 0)
- {
- menor = tab[i].ano;
- }
- else
- {
- if(tab[i].ano < menor)
- {
- menor = tab[i].ano;
- }
- }
- }
- return(menor);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement