Se tem um programa que tanto impressiona um iniciante em programação
principalmente Linguagem C, é Calculadora,
O triunfo dos que estavam aprendendo eletrônica básica a alguns anos atrás quando eu também cursava isto, era montar um rádio.
Oh! que alegria era ver um radinho funcionando, depois de tantos esforços para montá-lo olhando o esquema técnico e soldando componente a componente, com muito cuidado para não inverter as polaridades dos semicondutores, tempos de ouro que não voltam mais, que saudades!
Bom, o programa é todo baseado em funções simples, e na função do Menu: Menucalculadora(); coloquei um switch case que é perfeito para escolha e muito simples de usar, se for digitado algo que não esteja nas opções o comando default entra em ação e aciona um bip, advertindo o usuário sobre seu erro, e o comando do while, onde a variável de controle é diferente de 0 faz a repetição remontando tudo do jeito que estava no início.
Programa especialmente indicado a iniciantes em Linguagem C.
Eis as saídas deste programa no cmd:
Eis o Código abaixo:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void Janela5 ( ) {
int lin, col;
col = 0;
for ( lin = 0; lin <= 25 ; lin++ ) {
for ( col = 0; col <= 80 ; col++ ) {
gotoxy ( col , lin );
if ( lin == 2 ) {
textbackground ( LIGHTBLUE );
printf ( " " );
}
if ( col == 1 ) {
textbackground ( LIGHTBLUE );
printf ( " " );
}
if ( lin == 25 ) {
textbackground ( LIGHTBLUE );
}
if ( col == 80 ) {
textbackground ( LIGHTBLUE );
printf ( " " );
}
}
}
textbackground ( BLACK );
}
void Menucalculadora ( );
float n1, n2, porcentagem, resultado;
int load, col, timer;
void Funcsoma ( ) {
system ( "cls" );
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 38 , 7 );
printf ( "ADICAO " );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 9 );
printf ( "Digite um
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n1 );
fflush ( stdin );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 11 );
printf ( "Digite outro
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n2 );
fflush ( stdin );
resultado = n1 + n2;
textcolor ( LIGHTGREEN );
gotoxy ( 31 , 13 );
printf ( "O resultado
e: " );
textcolor ( LIGHTRED );
gotoxy ( 47 , 13 );
printf ( "%.2f\n" , resultado );
getche ( );
system ( "cls" );
}
void Funcsubtrai ( ) {
system ( "cls" );
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 36 , 7 );
printf ( "SUBTRACAO " );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 9 );
printf ( "Digite um
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n1 );
fflush ( stdin );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 11 );
printf ( "Digite outro
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n2 );
fflush ( stdin );
resultado = n1 - n2;
textcolor ( LIGHTGREEN );
gotoxy ( 31 , 13 );
printf ( "O resultado
e: " );
textcolor ( LIGHTRED );
gotoxy ( 47 , 13 );
printf ( "%.2f\n" , resultado );
getche ( );
system ( "cls" );
}
void Funcmult ( ) {
system ( "cls" );
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 36 , 7 );
printf ( "MULTIPLICACAO
" );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 9 );
printf ( "Digite um
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n1 );
fflush ( stdin );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 11 );
printf ( "Digite outro
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n2 );
fflush ( stdin );
resultado = n1 * n2;
textcolor ( LIGHTGREEN );
gotoxy ( 31 , 13 );
printf ( "O resultado
e: " );
textcolor ( LIGHTRED );
gotoxy ( 47 , 13 );
printf ( "%.2f\n" , resultado );
getche ( );
system ( "cls" );
}
void Funcdiv ( ) {
system ( "cls" );
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 37 , 7 );
printf ( "DIVISAO " );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 9 );
printf ( "Digite um
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n1 );
fflush ( stdin );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 11 );
printf ( "Digite outro
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n2 );
fflush ( stdin );
resultado = n1 / n2;
textcolor ( LIGHTGREEN );
gotoxy ( 31 , 13 );
printf ( "O resultado
e: " );
textcolor ( LIGHTRED );
gotoxy ( 47 , 13 );
printf ( "%.2f\n" , resultado );
getche ( );
system ( "cls" );
}
void Funcadporcent ( ) {
system ( "cls" );
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 29 , 7 );
printf ( "ADICAO COM
PORCENTAGENS" );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 9 );
printf ( "Digite um
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n1 );
fflush ( stdin );
textcolor ( LIGHTGRAY );
gotoxy ( 19 , 11 );
printf ( "Digite o
valor da porcentagem Sem o simbolo %%: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &porcentagem );
fflush ( stdin );
resultado = ( n1 + ( n1 * ( porcentagem / 100 ) ) );
textcolor ( LIGHTGREEN );
gotoxy ( 31 , 13 );
printf ( "O resultado
e: " );
textcolor ( LIGHTRED );
gotoxy ( 47 , 13 );
printf ( "%.2f\n" , resultado );
getche ( );
system ( "cls" );
}
void Funcsubporcent ( ) {
system ( "cls" );
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 29 , 7 );
printf ( "SUBTRACAO COM
PORCENTAGENS" );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 9 );
printf ( "Digite um
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n1 );
fflush ( stdin );
textcolor ( LIGHTGRAY );
gotoxy ( 19 , 11 );
printf ( "Digite o
valor da porcentagem Sem o simbolo %%: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &porcentagem );
fflush ( stdin );
resultado = ( n1 - ( n1 * ( porcentagem / 100 ) ) );
textcolor ( LIGHTGREEN );
gotoxy ( 31 , 13 );
printf ( "O resultado
e: " );
textcolor ( LIGHTRED );
gotoxy ( 47 , 13 );
printf ( "%.2f\n" , resultado );
getche ( );
system ( "cls" );
}
void Funcmultporcent ( ) {
system ( "cls" );
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 29 , 7 );
printf ( "MULTIPLICACAO
COM PORCENTAGENS" );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 9 );
printf ( "Digite um
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n1 );
fflush ( stdin );
textcolor ( LIGHTGRAY );
gotoxy ( 19 , 11 );
printf ( "Digite o
valor da porcentagem Sem o simbolo %%: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &porcentagem );
fflush ( stdin );
resultado = ( n1 * ( porcentagem / 100 ) );
textcolor ( LIGHTGREEN );
gotoxy ( 31 , 13 );
printf ( "O resultado
e: " );
textcolor ( LIGHTRED );
gotoxy ( 47 , 13 );
printf ( "%.2f\n" , resultado );
getche ( );
system ( "cls" );
}
void Funcdiviporcent ( ) {
system ( "cls" );
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 29 , 7 );
printf ( "DIVISAO COM
PORCENTAGENS" );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 9 );
printf ( "Digite um
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n1 );
fflush ( stdin );
textcolor ( LIGHTGRAY );
gotoxy ( 19 , 11 );
printf ( "Digite o
valor da porcentagem Sem o simbolo %%: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &porcentagem );
fflush ( stdin );
if ( n1 != 0 && porcentagem != 0 )
resultado = ( n1 / ( porcentagem / 100 ) );
textcolor ( LIGHTGREEN );
gotoxy ( 31 , 13 );
printf ( "O resultado
e: " );
textcolor ( LIGHTRED );
gotoxy ( 47 , 13 );
printf ( "%.2f\n" , resultado );
getche ( );
system ( "cls" );
}
void Funcraiz ( ) {
system ( "cls" );
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 35 , 7 );
printf ( "RAIZ QUADRADA
" );
textcolor ( LIGHTGRAY );
gotoxy ( 31 , 9 );
printf ( "Digite um
numero: " );
textcolor ( LIGHTRED );
scanf ( "%f" , &n1 );
fflush ( stdin );
textcolor ( LIGHTGREEN );
gotoxy ( 31 , 11 );
printf ( "A raiz
quadrada e: " );
textcolor ( LIGHTRED );
gotoxy ( 50 , 11 );
printf ( "%.2f\n" , sqrt ( n1 ) );
getche ( );
system ( "cls" );
}
void LOADING ( ) {
textcolor ( LIGHTGREEN );
gotoxy ( 32 , 15 );
printf ( "LOADING
" );
col = 31;
load = 200;
for ( timer = 0; timer <= 13 ; timer++ ) {
col++;
//gotoxy(41,15);
Sleep ( load );
textcolor ( LIGHTRED );
printf ( "%c" , 16 );
if ( col == 35 )
load = load - 100;
}
}
void BEMVINDO ( ) {
void Inicio ( );
system ( "cls" );
Janela5 ( );
char name [ 20 ] [ 20 ];
int aux;
for ( aux = 0; aux < 50 ; aux++ ) {
textcolor ( LIGHTRED );
gotoxy ( 35 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 26 , 5 );
printf ( "SEJA BEM
VINDO AO PROGRAMA CALCULOS" );
textcolor ( YELLOW );
gotoxy ( 27 , 7 );
printf ( "POR FAVOR,
DIGITE SEU NOME ABAIXO" );
textcolor ( LIGHTGRAY );
gotoxy ( 35 , 9 );
printf ( "NOME: " );
textcolor ( LIGHTRED );
gotoxy ( 42 , 9 );
gets ( name [ aux ] );
fflush ( stdin );
textcolor ( LIGHTBLUE );
gotoxy ( 31 , 11 );
printf ( " SEJA BEM
VINDO" );
textcolor ( LIGHTRED );
gotoxy ( 49 , 11 );
printf ( "%s" , name [ aux ] );
textcolor ( YELLOW );
gotoxy ( 31 , 13 );
printf ( "PRESSIONE
QUALQUER TECLA" );
getche ( );
LOADING ( );
Sleep ( 800 );
Inicio ( );
}
}
void Inicio ( ) {
char ch;
system ( "cls" );
do {
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 35 , 8 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( YELLOW );
gotoxy ( 24 , 10 );
printf ( "Programa
desenvolvido por:" );
textcolor ( LIGHTCYAN );
gotoxy ( 51 , 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 ( "S" );
textcolor ( LIGHTRED );
gotoxy ( 47 , 14 );
printf ( "C" );
gotoxy ( 40 , 18 );
ch = getche ( );
fflush ( stdin );
switch ( ch ) {
case 'S':
textcolor ( LIGHTRED );
gotoxy ( 35 , 18 );
printf ( "\aO ROCCO
AGRADECE" );
Sleep ( 1800 );
exit ( 0 );
break;
case 'C':
Menucalculadora ( );
break;
default:
textcolor ( LIGHTRED );
gotoxy ( 35 , 16 );
printf ( "\aOPCAO
ERRADA" );
Sleep ( 1800 );
system ( "cls" );
break;
}
} while ( 1 );
}
void Menucalculadora ( ) {
int op;
system ( "cls" );
do {
Janela5 ( );
textcolor ( LIGHTRED );
gotoxy ( 32 , 3 );
printf ( "PROGRAMA
CALCULOS" );
textcolor ( LIGHTBLUE );
gotoxy ( 35 , 5 );
printf ( "CALCULADORA" );
textcolor ( YELLOW );
gotoxy ( 29 , 7 );
printf ( "ESCOLHA UMA
OPCAO ABAIXO" );
textcolor ( LIGHTCYAN );
gotoxy ( 29 , 9 );
printf ( " 1 -
ADICAO" );
gotoxy ( 29 , 10 );
printf ( " 2 -
SUBTRACAO" );
gotoxy ( 29 , 11 );
printf ( " 3 -
MULTIPLICACAO" );
gotoxy ( 29 , 12 );
printf ( " 4 -
DIVISAO" );
gotoxy ( 29 , 13 );
printf ( " 5 - ADICAO
COM PORCENTAGENS" );
gotoxy ( 29 , 14 );
printf ( " 6 -
SUBTRACAO COM PORCENTAGENS" );
gotoxy ( 29 , 15 );
printf ( " 7 -
MULTIPLICACAO COM PORCENTAGENS" );
gotoxy ( 29 , 16 );
printf ( " 8 - DIVISAO
COM PORCENTAGENS" );
gotoxy ( 29 , 17 );
printf ( " 9 - RAIZ
QUADRADA" );
gotoxy ( 29 , 18 );
printf ( "10 - SAIR DO
PROGRAMA" );
gotoxy ( 29 , 19 );
printf ( "11 - VOLTAR
AO INICIO DO PROGRAMA" );
gotoxy ( 37 , 21 );
textcolor ( LIGHTRED );
scanf ( "%d" , &op );
fflush ( stdin );
switch ( op ) {
case 1:
Funcsoma ( );
break;
case 2:
Funcsubtrai ( );
break;
case 3:
Funcmult ( );
break;
case 4:
Funcdiv ( );
break;
case 5:
Funcadporcent ( );
break;
case 6:
Funcsubporcent ( );
break;
case 7:
Funcmultporcent ( );
break;
case 8:
Funcdiviporcent ( );
break;
case 9:
Funcraiz ( );
break;
case 10:
textcolor ( LIGHTRED );
gotoxy ( 35 , 21 );
printf ( "\aO ROCCO
AGRADECE" );
Sleep ( 1800 );
exit ( 0 );
break;
case 11:
BEMVINDO ( );
break;
default:
textcolor ( LIGHTRED );
gotoxy ( 35 , 21 );
printf ( "\aOPCAO
INVALIDA" );
getche ( );
system ( "cls" );
break;
}
} while ( op != 0 );
}
int main ( ) {
system ( "title
PROGRAMA CALCULOS" );
BEMVINDO ( );
}
Nenhum comentário:
Postar um comentário
Observação: somente um membro deste blog pode postar um comentário.