Buscar

Função em C que Retorna o elemento de maior Frequencia de um vetor,exclui de um vetor exibe e varrega um vetor

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

FixacaoVetoresFunc.cpp
#include<stdlib.h>
#include<conio2.h>
#include <stdio.h>
#define TF 10
//Variaveis Globais de Sistema
 
 int tl=0,vetor[TF];
// Declarações das funções
 
 char imprimeMenu();
 void leVetor(int vetor[TF],int &tl);
 void exibeVetor(int vetor[TF], int tl);
 void iniciarPrograma(void);
 int higFreqVet(int vetor[],int tl);
 int consultaVetor(int vetor[], int elemento, int tl);
 int eraseFromVet(int vetor[],int tl, int elemento);
// Fim Decl. Funções
void iniciarPrograma(void)
{
 char opcao;
 do
 {
 opcao=imprimeMenu();
 switch(opcao)
 {
 case '1':
 leVetor(vet,tam);
 getch();
 break;
 case '2':
 exibeVetor(vet,tam);
 getch();
 break;
 case '3':
 printf("Voce digitou a opcao Tres \n");
 getch();
 break;
 case '4':
 printf("Voce digitou a opcao Quatro \n");
 getch();
 break;
 case '5':
 printf("Voce digitou a opcao Tres \n");
 getch();
 break;
 
 case 27:
 printf("Voce esta saindo do programa \n");
 _sleep(1000);
 break;
 }
 }while(opcao!=27);
}
char imprimeMenu(void)
{
 clrscr();
 printf("*** Large Shit Maker Function Menu ***\n");
 printf("[ 1 ] Ler um vetor \n");
 printf("[ 2 ] Exibir Vetor em Tela \n");
 printf("[ 3 ] Elemento de maior Frequencia \n");
 printf("[ 4 ] Consulta um Elemento no vetor \n");
 printf("[ 5 ] Excluir um Elemento no Vetor \n");
 printf("[ Esc ] Sair do Programa \n");
 return getch();
}
void leVetor(int vetor[TF], int &tl)
{
 int aux;
 printf("Entre com o numero [%d]:",tl);
 scanf("%d",&aux);
 while(tl<TF && aux!=0)
 {
 vetor[tl++]=aux;
 if(tl<TF)
 {
 printf("numero[%d]",tl);
 scanf("%d",&aux);
 }
 else
 {
 printf("Vetor Cheio");
 getch();
 }
 }
}
void exibeVetor(int vetor[TF], int tl)
{
 int i;
 clrscr();
 printf(" \n elemento do vetor \n");
 if(tl>0)
 for(i=0;i<tl;i++)
 printf(" \n numero [%d]: %d",i,vetor[i]);
 else
 printf("\n Vetor Vazio");
 getch();
}
int higFreqVet(int vetor[],int tl)
{
 int i=0,j=0,nAux,maiorFreq=0,cont;
 
 for(j=0;j<tl;j++)
 {
 cont=0;
 for(i=j;i<tl;i++)
 {
 if(vetor[j]==vetor[i])
 cont++;
 
 }
 
 if(cont>maiorFreq)
 {
 maiorFreq=cont;
 nAux=vetor[j];
 }
 
 } 
 
 return nAux;
}
int consultaVetor(int vetor[], int elemento, int tl)
{
 int i=0,pos;
 
 for(i=0;i<tl;i++)
 {
 if(vetor[i]==elemento)
 {
 pos=i;
 return pos;
 }
 else
 return -1;
 }
}
int eraseFromVet(int vetor[],int &tl, int elemento)
{
 int i=0, pos,nAux;
 pos=consultaVetor(vetor,elemento,tl);
 if(pos!=-1)
 {
 nAux=vetor[pos]
 for(i=pos;i<tl-1;i++)
 {
 vetor[i]=vetor[i+1];
 }
 tl--;
 }
}

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Continue navegando