domingo, 3 de novembro de 2013

Programa Struct Dinâmica

Criar uma estrutura dinâmica não é tarefa difícil para os programadores, até mesmo quem
está começando a programar agora com um pouco de esforços obtem êxito.
Más se ainda tem você dificuldades, mostro neste código como criar, e utilizar.

Veja algumas imagens do Programa abaixo:




Aproveite o código abaixo que está funcionando perfeitamente e sem obstáculos:

#include <stdio.h>
#include <ctype.h>
#include <conio.h>
struct Placa {
     int anos;
     char marca [ 20 ];
     char modelo [ 20 ];
     char cor [ 20 ];
};
void Janela5 ( ) {
     int lin, col;
     col = 0;
     for ( lin = 0; lin <= 25; lin++ ) {
         for ( col = 0; col <= 80; col++ ) {
              gotoxy ( col, lin );
              textbackground ( WHITE );
              if ( lin == 2 ) {
                   textbackground ( PRETO );
                   printf ( " " );
              }
              if ( col == 1 ) {
                   textbackground ( PRETO );
                   printf ( " " );
              }
              if ( lin == 25 ) {
                   textbackground ( PRETO );
              }
              if ( col == 80 ) {
                   textbackground ( PRETO );
                   printf ( " " );
              }
         }
     }
     textbackground ( WHITE );
}
int main ( ) {
     struct Placa *Carro [ 50 ];
     int j = 0;
     int i = 0;
     char car = '\0';
     system ( "title PROGRAMA STRUCT DINAMICA" );
     system ( "cls" );
     do {
         system ( "cls" );
         for ( j = 0; j < 50; j++ ) {
              Janela5 ( );
              textcolor ( LIGHTRED );
              gotoxy ( 30, 3 );
              printf ( "PROGRAMA STRUCT DINAMICA" );
              textcolor ( BLACK );
              gotoxy ( 22, 5 );
              printf ( "PROGRAMA DESENVOLVIDO POR:" );
              textcolor ( DARKGRAY );
              gotoxy ( 49, 5 );
              printf ( "Samuel Lima" );
              textcolor ( GREEN );
              gotoxy ( 30, 7 );
              printf ( "sa_sp10@hotmail.com" );
              textcolor ( LIGHTBLUE );
              gotoxy ( 28, 9 );
              printf ( "Aceita cadastrar seu carro? " );
              gotoxy ( 18, 10 );
              printf ( " [ C Para sim / S Para Sair / E Para Exibir  ]  " );
              textcolor ( LIGHTRED );
              scanf ( " %c", &car );
              fflush ( stdin );
              if ( tolower ( car ) == 'e' )
                   break;
              if ( tolower ( car ) == 's' ) {
                   textcolor ( VERMELHOCLARO );
                   gotoxy ( 33, 15 );
                   printf ( "O ROCCO AGRADECE" );
                   Sleep ( 1800 );
                   exit ( 0 );
              }
              Carro [ j ] = ( struct Placa * ) malloc ( sizeof(struct Placa) );
              system ( "cls" );
              textbackground ( AZULCLARO );
              Janela5 ( );
              textcolor ( LIGHTRED );
              gotoxy ( 30, 3 );
              printf ( "PROGRAMA STRUCT DINAMICA" );
              textcolor ( LIGHTBLUE );
              gotoxy ( 30, 5 );
              printf ( "Digite a marca do seu carro: " );
              textcolor ( LIGHTRED );
              scanf ( "%s", Carro [ j ]->marca );
              fflush ( stdin );
              textcolor ( LIGHTBLUE );
              gotoxy ( 30, 7 );
              printf ( "Anos de fabricado o seu %s ? ", Carro [ j ]->marca );
              textcolor ( LIGHTRED );
              scanf ( "%d", &Carro [ j ]->anos );
              fflush ( stdin );
              textcolor ( LIGHTBLUE );
              gotoxy ( 30, 9 );
              printf ( "Qual e o modelo do %s ? ", Carro [ j ]->marca );
              textcolor ( LIGHTRED );
              scanf ( "%s", Carro [ j ]->modelo );
              fflush ( stdin );
              textcolor ( LIGHTBLUE );
              gotoxy ( 30, 11 );
              printf ( "Qual e a cor do %s ? ", Carro [ j ]->marca );
              textcolor ( LIGHTRED );
              scanf ( "%s", Carro [ j ]->cor );
              fflush ( stdin );
              getche ( );
              system ( "cls" );
         }
         textcolor ( LIGHTRED );
         system ( "cls" );
         Janela5 ( );
         gotoxy ( 30, 3 );
         printf ( "PROGRAMA STRUCT DINAMICA" );
         for ( i = 0; i < j; i++ ) {
              textcolor ( LIGHTBLUE );
              printf ( "\n\n\tO seu %s tem %d anos de fabricacao ",
                        Carro [ i ]->marca, Carro [ i ]->anos );
              printf ( " O modelo e %s e a cor e %s ", Carro [ i ]->modelo,
                        Carro [ i ]->cor );
              getche ( );
         }
     } while ( 1 );
     free ( Carro [ i ] );
}

Nenhum comentário:

Postar um comentário

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