TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Exercícios de Computação: Algoritmos e Programação II

Por:   •  20/2/2016  •  Exam  •  4.910 Palavras (20 Páginas)  •  329 Visualizações

Página 1 de 20

             Universidade Presbiteriana Mackenzie

           Curso: Engenharia Civil

    Disciplina: Computação. Algoritmos e Programação II

             Professor: Ms. Massaki Igarashi

Nome do aluno:Gustavo Marcatti Tofanello       T.I.A:31549039

Turma: 02S11                                   Trabalho: Aula 07(Minima)

Exercícios referentes ao capitulo 15a:

        

        Exercício 15.5:

Vetores.h

#ifndef VETORES_H

#define VETORES_H

const int Max = 30;

typedef int Vetor[Max];

int Dimensao();

void LeVetor(Vetor &v, int n);

void DobraVetor(Vetor &v, int n);

void ExibeVetor(Vetor &v, int n);

int SomaPositivos(Vetor &v, int n);

int QuantidadeNegativos(Vetor &v, int n);

void MaiorMenor(Vetor &v, int n, int &a, int &b);

int MediaPar(Vetor &v, int n);

#endif

Vetores.cpp

#include "Vetores.h"

#include

#include

#include

using namespace std;

int Dimensao(){

        int n;        

        cout << "Tamanho do vetor = "; cin >> n;

        while(n < 1 || n > Max){

                cout << "Valor invalido!\n";

                cout << "Tamanho = "; cin >> n;

        }

        return n;

}

void LeVetor(Vetor &v, int n){

        for (int i = 0; i < n; i++){

                cout << "v[" << i << "]= ";

                cin >> v[i];

        }

}

void DobraVetor(Vetor &v, int n){

        for(int i = 0; i < n; i++)

                v[i]= 2*v[i];

}

void ExibeVetor(Vetor &v, int n){

        for(int i = 0; i < n; i++)

                cout<< v[i] << endl;

}

int SomaPositivos(Vetor &v, int n){

        int s = 0;

        for(int i = 0; i < n; i++){

                if(v[i] > 0)

                        s = s + v[i];

        }

        return s;

}

int QuantidadeNegativos(Vetor &v, int n){

        int p = 0;

        for(int i = 0; i < n; i++){

                if(v[i] < 0)

                        p++;}

        return p;

}

void MaiorMenor(Vetor &v, int n, int &a, int &b){

        int aux = v[0];

        a = v[0];

        b = v[0];

        for(int i = 0; i < n; i++){

                if(v[i] > aux)

                aux = v[i];

                if(aux > a)

                a = aux;

                

                if(v[i] < aux)

                aux = v[i];

                if(aux < b)

                b = aux;

        }

}

int MediaPar(Vetor &v, int n){

        int c = 0;

        int m;

        int s = 0;

        for(int i = 0; i < n; i++){

                if(v[i]%2 == 0){

                        s = s + v[i];

                        c++;}

        }

        m = s/c;

        return m;

}

mainVetores.cpp

#include

#include

#include

#include

#include "Vetores.h"

using namespace std;

int main(int argc, char** argv){

        

        Vetor v;

        int n, a, b;

        

        n = Dimensao();

        LeVetor(v, n);

        

        cout << "\nSoma dos positivos = " << SomaPositivos(v, n) << endl;

        cout << "\nQuantidade de negativos = " << QuantidadeNegativos(v, n) << endl;

        

        MaiorMenor(v, n, a, b);

        cout << "\nMaior vetor = " << a << endl;

        cout << "\nMenor vetor = " << b << endl;

        

        cout << \n"Media dos Pares = " << MediaPar(v, n) << endl;

        

        DobraVetor(v, n);

        cout << "\nVetores dobrados: " << endl << endl;

        ExibeVetor(v, n);

        

        

        system("pause");

        return 0;

}

        Exercício 15.4:

Vetores.h

#ifndef VETORES_H

#define VETORES_H

const int Max = 40;

typedef int Vetor[Max];

int Dimensao();

void Sortear(Vetor &v, int n);

int MediaPar(Vetor &v, int n);

int Impares(Vetor &v, int n);

#endif

Vetores.cpp

#include "Vetores.h"

#include

#include

#include

#include

using namespace std;

int Dimensao(){

        int n;        

        cout << "Tamanho do vetor = "; cin >> n;

...

Baixar como (para membros premium)  txt (14.7 Kb)   pdf (168.2 Kb)   docx (16.5 Kb)  
Continuar por mais 19 páginas »
Disponível apenas no TrabalhosGratuitos.com