sábado, 21 de junho de 2014

Unindo e Ordenando Vetor de caracteres


O programa começa mostrando a tela inicial que contém o meu nome e meu e-mail, e foi criado por mim mesmo e tive muitas dificuldades pra chegar
a estes excelentes resultados, muito tempo e dedicação foram gastos pra isto.
Escolhendo uma das duas opções da tela inicial, o programa prossegue
pedindo pra que se digite um número, más não pense você que ele aceita qualquer número, porque não é bem assim, os números ficaram lilitados pela macro #tam em vinte seis no máximo, e também está ápto a rejeitar qualquer caracter digitado, ou o que não seja um dígito ou um número válido dentro das especificações.
Passando isto, ele pede pra que se digite os caracteres do vetor A, terminando pede a quantidade de caracteres pro vetor B, e finalmente
exibe todos os caracteres do vetor A e sua quantidade, e do vetor B e sua quantidade, Mostra ainda a união dos dois vetores, e por último mostra os dois vetores unidos num só e ordenados.
Excelente código indicados aos amantes da linguagem c, o código foi compilado no compilador da Borland.

Veja algumas imagens do programa em execução:







Veja abaixo o código do programa:



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
//#include "gottextback.DLL"
#define tam 26
void Janela5 ( ) {
     int lin, col;
     system ( "color 5F" );
     for ( lin = 0; lin <= 36 ; lin++ ) {
         for ( col = 0; col <= 80 ; col++ ) {
              gotoxy ( col , lin );
              if ( lin == 2 ) {
                   textbackground ( BLACK );
                   printf ( " " );
              }
              if ( col == 1 ) {
                   textbackground ( BLACK );
                   printf ( " " );
              }
              if ( lin == 36 ) {
                   textbackground ( BLACK );
              }
              if ( col == 80 ) {
                   textbackground ( BLACK );
                   printf ( " " );
              }
         }
     }
     textbackground ( BLACK );
}
int Func_Uteis ( int *n , int *m , char Vetor [ tam ] , char Vet [ tam ] ,
         char Vet_or [ tam ] , char string [ tam ] );
int Func_Uteis_Dois ( int *n , int *m , char Vetor [ tam ] , char Vet [ tam ] ,
         char Vet_or [ tam ] , char string [ tam ] );
int Unin_Ord_Caracter ( int *n , int *m , char Vetor [ tam ] ,
         char Vet [ tam ] , char Vet_or [ tam ] );
void bolha_ordem ( char *item , int count ) {
     register int a, b;
     register char t;
     for ( a = 0; a < count ; ++a )
         for ( b = count - 1; b >= a ; --b ) {
              if ( item [ b - 1 ] > item [ b ] ) {
                   /* troca os elementos */
                   t = item [ b - 1 ];
                   item [ b - 1 ] = item [ b ];
                   item [ b ] = t;
              }
         }
}
int Func_Uteis ( int *n , int *m , char Vetor [ tam ] , char Vet [ tam ] ,
         char Vet_or [ tam ] , char string [ tam ] ) {
     int i;
     do {
         system ( "cls" );
         Janela5 ( );
         textcolor ( LIGHTRED );
         gotoxy ( 25 , 3 );
         printf ( "UNINDO E ORDENANDO VETOR DE CARACTERES" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 20 , 5 );
         printf ( "Quantos Caracteres para o Vetor A ? " );
         textcolor ( YELLOW );
         fgets ( string , sizeof ( string ) , stdin );
         if ( ( *string >= '0' ) && ( *string <= '9' ) ) {
              textcolor ( LIGHTBLUE );
              gotoxy ( 20 , 7 );
              printf ( "Você digitou" );
              textcolor ( LIGHTRED );
              printf ( " %s" , string );
         } else {
              textcolor ( LIGHTBLUE );
              gotoxy ( 20 , 7 );
              printf ( "Você digitou " );
              textcolor ( LIGHTRED );
              gotoxy ( 32 , 7 );
              printf ( " %s" , string );
              textcolor ( LIGHTBLUE );
              gotoxy ( 34 , 7 );
              printf ( " Isto não e um dígito" );
              getche ( );
              Func_Uteis ( m , n , Vetor , Vet , Vet_or , string );
         }
         n = ( int* ) malloc ( tam * sizeof(int) );
         getche ( );
         *n = atoi ( string );
         if ( *n < 0 || *n > tam ) {
              gotoxy ( 20 , 14 );
              printf ( "\aSó são aceitos Números Acima de 0 e menor que %d " ,
                        tam );
              getche ( );
              system ( "cls" );
         }
     } while ( ( *n < 0 ) || ( *n > tam ) );
     for ( i = 0; i < *n ; i++ ) {
         system ( "cls" );
         Janela5 ( );
         textcolor ( LIGHTRED );
         gotoxy ( 25 , 3 );
         printf ( "UNINDO E ORDENANDO VETOR DE CARACTERES" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 18 , 5 );
         printf ( "Digite um caractere para a posição " );
         textcolor ( LIGHTRED );
         printf ( " %do " , i + 0 );
         fflush ( stdin );
         textcolor ( LIGHTBLUE );
         printf ( "do Vetor A " );
         textcolor ( YELLOW );
         gotoxy ( 70 , 5 );
         scanf ( "%c" , &Vetor [ i ] );
         fflush ( stdin );
         if ( ( Vetor [ i ] >= '0' ) && ( Vetor [ i ] <= '9' ) ) {
              textcolor ( LIGHTBLUE );
              gotoxy ( 18 , 7 );
              printf ( "Você digitou" );
              textcolor ( LIGHTRED );
              printf ( " %c" , *Vetor );
              textcolor ( LIGHTBLUE );
              printf ( " Números não são aceitos" );
              getche ( );
              Func_Uteis ( m , n , Vetor , Vet , Vet_or , string );
              break;
         }
     }
     Func_Uteis_Dois ( n , m , Vetor , Vet , Vet_or , string );
     return ( 0 );
}
int Func_Uteis_Dois ( int *n , int *m , char Vetor [ tam ] , char Vet [ tam ] ,
         char Vet_or [ tam ] , char string [ tam ] ) {
     int i;
     do {
         system ( "cls" );
         Janela5 ( );
         textcolor ( LIGHTRED );
         gotoxy ( 25 , 3 );
         printf ( "UNINDO E ORDENANDO VETOR DE CARACTERES" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 20 , 5 );
         printf ( "Quantos Caracteres para o Vetor B  ? " );
         textcolor ( YELLOW );
         fgets ( string , sizeof ( string ) , stdin );
         if ( ( *string >= '0' ) && ( *string <= '9' ) ) {
              textcolor ( LIGHTBLUE );
              gotoxy ( 20 , 7 );
              printf ( "Você digitou" );
              textcolor ( LIGHTRED );
              printf ( " %s" , string );
         } else {
              textcolor ( LIGHTBLUE );
              gotoxy ( 20 , 7 );
              printf ( "Você digitou " );
              textcolor ( LIGHTRED );
              gotoxy ( 32 , 7 );
              printf ( " %s" , string );
              textcolor ( LIGHTBLUE );
              gotoxy ( 34 , 7 );
              printf ( " Isto não e um dígito" );
              getche ( );
              Func_Uteis_Dois ( m , n , Vetor , Vet , Vet_or , string );
         }
         getche ( );
         m = ( int* ) malloc ( tam * sizeof(int) );
         *m = atoi ( string );
         if ( *m < 0 || *m > tam ) {
              gotoxy ( 20 , 14 );
              printf ( "\aSó são aceitos Números Acima de 0 e menor que %d " ,
                        tam );
              getche ( );
              system ( "cls" );
         }
     } while ( ( *m < 0 ) || ( *m > tam ) );
     for ( i = 0; i < *m ; i++ ) {
         system ( "cls" );
         Janela5 ( );
         textcolor ( LIGHTRED );
         gotoxy ( 25 , 3 );
         printf ( "UNINDO E ORDENANDO VETOR DE CARACTERES" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 18 , 5 );
         printf ( "Digite um caractere para a posição " );
         textcolor ( LIGHTRED );
         printf ( " %do " , i + 0 );
         fflush ( stdin );
         textcolor ( LIGHTBLUE );
         printf ( "do Vetor B " );
         textcolor ( YELLOW );
         gotoxy ( 70 , 5 );
         scanf ( "%c" , &Vet_or [ i ] );
         fflush ( stdin );
         if ( ( Vet_or [ i ] >= '0' ) && ( Vet_or [ i ] <= '9' ) ) {
              textcolor ( LIGHTBLUE );
              gotoxy ( 18 , 7 );
              printf ( "Você digitou" );
              textcolor ( LIGHTRED );
              printf ( " %c" , *Vet_or );
              textcolor ( LIGHTBLUE );
              printf ( " Números não são aceitos" );
              getche ( );
              Func_Uteis_Dois ( m , n , Vetor , Vet , Vet_or , string );
              break;
         }
     }
     Unin_Ord_Caracter ( n , m , Vetor , Vet , Vet_or );
     return ( 0 );
}
void inicio ( int *n , int *m , char Vetor [ tam ] , char Vet [ tam ] ,
         char Vet_or [ tam ] , char string [ tam ] ) {
     int i;
     system ( "cls" );
     do {
         Janela5 ( );
         textcolor ( LIGHTRED );
         gotoxy ( 25 , 7 );
         printf ( "UNINDO E ORDENANDO VETOR DE CARACTERES" );
         textcolor ( YELLOW );
         gotoxy ( 25 , 10 );
         printf ( "Programa desenvolvido por:" );
         textcolor ( LIGHTCYAN );
         gotoxy ( 52 , 10 );
         printf ( "Samuel Lima" );
         textcolor ( LIGHTGREEN );
         gotoxy ( 34 , 12 );
         printf ( "sa_sp10@hotmail.com" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 24 , 14 );
         printf ( "DIGITE    PARA SAIR OU   PARA CONTINUAR  " );
         textcolor ( LIGHTRED );
         gotoxy ( 32 , 14 );
         printf ( "1" );
         textcolor ( LIGHTRED );
         gotoxy ( 47 , 14 );
         printf ( "2" );
         gotoxy ( 41 , 16 );
         scanf ( "%d" , &i );
         fflush ( stdin );
         if ( i == 1 ) {
              textcolor ( LIGHTRED );
              gotoxy ( 30 , 20 );
              printf ( "MUITO OBRIGADO" );
              Sleep ( 1800 );
              exit ( 0 );
         }
         if ( i == 2 ) {
              system ( "cls" );
              Func_Uteis ( m , n , Vetor , Vet , Vet_or , string );
         } else {
              textcolor ( LIGHTBLUE );
              gotoxy ( 37 , 20 );
              printf ( "\aOPÇÃO ERRADA" );
              Sleep ( 1800 );
              system ( "cls" );
         }
     } while ( i );
}
int Unin_Ord_Caracter ( int *n , int *m , char Vetor [ tam ] ,
         char Vet [ tam ] , char Vet_or [ tam ] ) {
     int i;
     system ( "cls" );
     Janela5 ( );
     textcolor ( LIGHTRED );
     gotoxy ( 25 , 3 );
     printf ( "UNINDO E ORDENANDO VETOR DE CARACTERES" );
     textcolor ( YELLOW );
     gotoxy ( 27 , 5 );
     printf ( "ESTES SÃO OS VETORES PREENCHIDOS" );
     textcolor ( LIGHTBLUE );
     gotoxy ( 20 , 7 );
     printf ( "Mostrando abaixo os " );
     textcolor ( LIGHTRED );
     printf ( "%d" , *n );
     textcolor ( LIGHTBLUE );
     printf ( " Caracteres do Vetor A " );
     textcolor ( LIGHTRED );
     gotoxy ( 20 , 9 );
     for ( i = 0; i < *n ; i++ ) {
         printf ( " %c " , Vetor [ i ] );
         Vet [ i ] = Vetor [ i ];
     }
     getche ( );
     textcolor ( LIGHTBLUE );
     gotoxy ( 20 , 11 );
     printf ( "Mostrando abaixo os " );
     textcolor ( LIGHTRED );
     printf ( "%d" , *m );
     textcolor ( LIGHTBLUE );
     printf ( " Caracteres do Vetor B " );
     textcolor ( LIGHTRED );
     gotoxy ( 20 , 13 );
     for ( i = 0; i < *m ; i++ ) {
         printf ( " %c " , Vet_or [ i ] );
         Vet [ i + *n ] = Vet_or [ i ];
     }
     getche ( );
     textcolor ( LIGHTBLUE );
     gotoxy ( 10 , 15 );
     textcolor ( LIGHTBLUE );
     printf ( "Mostrando abaixo os " );
     textcolor ( LIGHTRED );
     printf ( "%d" , *n + *m );
     textcolor ( LIGHTBLUE );
     printf ( " Caracteres do Vetor A + O Vetor B " );
     textcolor ( YELLOW );
     gotoxy ( 10 , 17 );
     for ( i = 0; i < ( *n + *m ) ; i++ ) {
         printf ( " %c " , Vet [ i ] );
     }
     getche ( );
     textcolor ( LIGHTBLUE );
     gotoxy ( 10 , 19 );
     printf ( "Mostrando abaixo os " );
     textcolor ( LIGHTRED );
     printf ( "%d" , *n + *m );
     textcolor ( LIGHTBLUE );
     printf ( " Caracteres do Vetor A + O Vetor B Ordenados" );
     bolha_ordem ( Vet , strlen ( Vet ) );
     textcolor ( YELLOW );
     gotoxy ( 10 , 21 );
     for ( i = 0; i <= ( *n + *m ) ; i++ ) {
         printf ( " %c " , Vet [ i ] );
     }
     Sleep ( 1800 );
     textcolor ( LIGHTRED );
     gotoxy ( 35 , 23 );
     printf ( "MUITO OBRIGADO" );
     getche ( );
     exit ( 0 );
     return ( 0 );
}
int main ( ) {
     int *n = 0, *m = 0;
     system ( "title UNINDO E ORDENANDO VETOR DE CARACTERES" );
     char Vetor [ tam ];
     char Vet_or [ tam ];
     char Vet [ tam ];
     char string [ 3 ];
     inicio ( n , m , Vetor , Vet , Vet_or , string );
     return ( 0 );
}



Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.