domingo, 2 de março de 2014

Cálculos para Resistores

O iniciante em eletrônica esta sempre em busca de programas para ajudá-lo em cálculos de resistores.
Este programa tem uma interface agradável com menus inteligentes e poderá ajuda-lo
nos seus cálculos de resistência. O código foi compilado no MinGw mais os programadores experientes
poderá compilá-lo em qualquer compilador e ainda fazer alterações para torná-lo mais adequado as suas necessidades.



Veja o Código abaixo:

#include <stdio.h>
#include <conio2.h>
#include <time.h>
int r1, r2, r3, rt;
void Janela6 ( ) {
     int lin, col;
     col = 0;
     for ( lin = 2; lin <= 24; lin++ )
         for ( col = 3; col <= 78; col++ ) {
              gotoxy ( col, lin );
              textbackground ( 6 );
              printf ( " " );
         }
     col = 0;
     for ( lin = 5; lin <= 21; lin++ )
         for ( col = 6; col <= 75; col++ ) {
              gotoxy ( col, lin );
              textbackground ( 16 );
              printf ( " " );
         }
}
void Janela5 ( ) {
     int lin, col;
     col = 0;
     for ( lin = 2; lin <= 24; lin++ )
         for ( col = 2; col <= 78; col++ ) {
              gotoxy ( col, lin );
              textbackground ( WHITE );
              printf ( " " );
         }
}
void Funcdefault ( ) {
     void janela5 ( );
     int opc;
     switch ( opc ) {
         default:
              Janela5 ( );
              gotoxy ( 32, 12 );
              printf ( "\aOP€ÇO INVµLIDA!\n" );
              Sleep ( 1800 );
              gotoxy ( 3, 24 );
              break;
     }
}
void Funcexit ( ) {
     time_t hora_atual;
     void Janela5 ( );
     Janela5 ( );
     gotoxy ( 32, 11 );
     textcolor ( BLACK );
     printf ( "OPERA€ÇO FINALIZADA" );
     Sleep ( 1800 );
     gotoxy ( 20, 13 );
     printf ( "MUITO OBRIGADO POR TER USADO ESTE PROGRAMA\n" );
     time ( &hora_atual );
     gotoxy ( 20, 15 );
     printf ( "A data e hora atuais sÆo: %s", ctime ( &hora_atual ) );
     Sleep ( 1800 );
     exit ( 0 );
     gotoxy ( 2, 27 );
}
void menu2 ( void ) {
     system ( "cls" );
     void Janela5 ( );
     int main ( void );
     int op;
     do {
         Janela6 ( );
         textcolor ( LIGHTRED );
         gotoxy ( 29, 3 );
         printf ( "CµLCULOS PARA RESISTORES" );
         textcolor ( LIGHTGREEN );
         gotoxy ( 31, 8 );
         printf ( "ESCOLHA UMA OP€ÇO ABAIXO" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 19, 10 );
         printf ( "1 - ASSOCIANDO TRES RESISTORES EM PARALELO\n" );
         gotoxy ( 19, 12 );
         printf ( "2 - SAIR" );
         gotoxy ( 19, 14 );
         printf ( "3 - VOLTA AO MENU PRINCIPAL" );
         gotoxy ( 19, 16 );
         textcolor ( YELLOW );
         scanf ( "%d", &op );
         fflush ( stdin );
         system ( "cls" );
         switch ( op ) {
              case 1:
                   Janela6 ( );
                   textcolor ( LIGHTRED );
                   gotoxy ( 29, 3 );
                   printf ( "CµLCULOS PARA RESISTORES" );
                   textcolor ( LIGHTBLUE );
                   gotoxy ( 26, 8 );
                   printf ( "ASSOCIANDO TRES RESISTORES EM PARALELO\n" );
                   textcolor ( YELLOW );
                   gotoxy ( 29, 10 );
                   printf ( "Digite um valor pra R1" );
                   textcolor ( LIGHTRED );
                   gotoxy ( 29, 11 );
                   printf ( "R1 = " );
                   scanf ( "%d", &r1 );
                   fflush ( stdin );
                   textcolor ( YELLOW );
                   gotoxy ( 29, 13 );
                   printf ( "Digite um valor pra R2" );
                   textcolor ( LIGHTRED );
                   gotoxy ( 29, 14 );
                   printf ( "R2 = " );
                   scanf ( "%d", &r2 );
                   fflush ( stdin );
                   textcolor ( YELLOW );
                   gotoxy ( 29, 16 );
                   printf ( "Digite um valor pra R3" );
                   textcolor ( LIGHTRED );
                   gotoxy ( 29, 17 );
                   printf ( "R3 = " );
                   scanf ( "%d", &r3 );
                   fflush ( stdin );
                   rt = ( r1 * r2 * r3 ) / ( r2 * r3 + r1 * r2 + r1 * r3 );
                   textcolor ( LIGHTGREEN );
                   gotoxy ( 29, 19 );
                   printf ( "RT = %d ", rt );
                   Sleep ( 1800 );
                   system ( "cls" );
                   break;
              case 2:
                   Funcexit ( );
                   break;
              case 3:
                   main ( );
                   break;
              default:
                   Funcdefault ( );
                   break;
         }
     } while ( op != 0 );
}
void menu1 ( void ) {
     system ( "cls" );
     void Janela6 ( );
     int main ( void );
     int op;
     do {
         Janela6 ( );
         textbackground ( BLACK );
         textcolor ( LIGHTRED );
         gotoxy ( 29, 3 );
         printf ( "CµLCULOS PARA RESISTORES" );
         textcolor ( LIGHTGREEN );
         gotoxy ( 31, 8 );
         printf ( "ESCOLHA UMA OP€ÇO ABAIXO" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 19, 10 );
         printf ( "1 - ASSOCIANDO DOIS RESISTORES EM PARALELO\n" );
         gotoxy ( 19, 12 );
         printf ( "2 - SAIR" );
         gotoxy ( 19, 14 );
         printf ( "3 - VOLTA AO MENU PRINCIPAL" );
         gotoxy ( 19, 16 );
         textcolor ( YELLOW );
         scanf ( "%d", &op );
         fflush ( stdin );
         system ( "cls" );
         switch ( op ) {
              case 1:
                   Janela6 ( );
                   textcolor ( LIGHTRED );
                   gotoxy ( 29, 3 );
                   printf ( "CµLCULOS PARA RESISTORES" );
                   textcolor ( LIGHTBLUE );
                   gotoxy ( 23, 8 );
                   printf ( "ASSOCIANDO DOIS RESISTORES EM PARALELO" );
                   textcolor ( YELLOW );
                   gotoxy ( 29, 10 );
                   printf ( "Digite um valor pra R1" );
                   gotoxy ( 29, 12 );
                   textcolor ( LIGHTRED );
                   printf ( "R1 = " );
                   scanf ( "%d", &r1 );
                   fflush ( stdin );
                   textcolor ( YELLOW );
                   gotoxy ( 29, 14 );
                   printf ( "Digite um valor pra R2" );
                   gotoxy ( 29, 16 );
                   textcolor ( LIGHTRED );
                   printf ( "R2 = " );
                   scanf ( "%d", &r2 );
                   fflush ( stdin );
                   rt = ( r1 * r2 ) / ( r1 + r2 );
                   textcolor ( LIGHTGREEN );
                   gotoxy ( 29, 18 );
                   printf ( "RT = %d ", rt );
                   Sleep ( 1800 );
                   system ( "cls" );
                   break;
              case 2:
                   Funcexit ( );
                   break;
              case 3:
                   main ( );
                   break;
              default:
                   Funcdefault ( );
                   break;
              case 10:
                   Funcexit ( );
                   break;
         }
     } while ( op != 0 );
}
int main ( void ) {
     system ( "title CÁLCULOS PARA RESISTORES" );
     void Funcexit ( );
     int op;
     do {
         Janela6 ( );
         textcolor ( LIGHTRED );
         gotoxy ( 29, 3 );
         printf ( "CµLCULOS PARA RESISTORES" );
         textcolor ( LIGHTBLUE );
         gotoxy ( 35, 8 );
         printf ( "MENU PRINCIPAL" );
         textcolor ( LIGHTGREEN );
         gotoxy ( 31, 10 );
         printf ( "ESCOLHA UMA OP€ÇO ABAIXO" );
         textcolor ( WHITE );
         gotoxy ( 19, 12 );
         printf ( "1 - ASSOCIANDO DOIS RESISTORES EM PARALELO\n" );
         gotoxy ( 19, 13 );
         printf ( "2 - ASSOCIANDO TRES RESISTORES EM PARALELO\n" );
         gotoxy ( 19, 14 );
         printf ( "3 - SAIR" );
         gotoxy ( 19, 16 );
         textcolor ( YELLOW );
         scanf ( "%d", &op );
         fflush ( stdin );
         system ( "cls" );
         switch ( op ) {
              case 1:
                   menu1 ( );
                   break;
              case 2:
                   menu2 ( );
                   break;
              case 3:
                   Funcexit ( );
                   break;
              default:
                   Funcdefault ( );
                   break;
         }
     } while ( op != 0 );
     Funcexit ( );
     return 0;
}