Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- #include "meuconio.h"
- #define TFL 25
- #define TFC 80
- #define FREQ_DO 261
- #define FREQ_RE 293
- #define FREQ_MI 329
- #define FREQ_FA 349
- #define FREQ_SOL 392
- #define FREQ_LA 440
- #define FREQ_SI 493
- #define TEMPO 1000
- void desenha(int x1, int y1, int x2, int y2)
- {
- int x;
- textcolor(4);
- gotoxy(x1, y1);
- printf("*");
- gotoxy(x2, y1);
- printf("*");
- gotoxy(x1, y2);
- printf("*");
- gotoxy(x2, y2);
- printf("*");
- textcolor(10);
- for(x = y1 + 1; x < y2; x++)
- {
- gotoxy(x1, x);
- printf("|");
- gotoxy(x2, x);
- printf("|");
- }
- for(x = x1 + 1; x < x2; x++)
- {
- gotoxy(x, y1);
- printf("-");
- gotoxy(x, y2);
- printf("-");
- }
- textcolor(15);
- }
- void desenhaCabecalho(char msg[])
- {
- desenha(2, 2, 79, 5);
- gotoxy(20, 3);
- printf("%s ", msg);
- }
- int decToBin(int dec)
- {
- int ret = 0, cont = 0;
- while(dec >= 1)
- {
- if(dec % 2 == 1)
- ret += pow(10, cont);
- cont++;
- dec /= 2;
- }
- return ret;
- }
- int binToDec(int bin)
- {
- int ret = 0, cont = 0;
- while(bin >= 1)
- {
- if(bin % 10 == 1)
- ret += pow(2, cont);
- cont++;
- bin /= 10;
- }
- return ret;
- }
- int numPerf(int n)
- {
- int ret, i, soma = 0;
- for(i = 1; i < n; i++)
- if(n % i == 0)
- soma += i;
- if(soma == n)
- ret = 1;
- else
- ret = 0;
- return ret;
- }
- int difHora(int h1, int m1, int s1, int h2, int m2, int s2)
- {
- return (h2 * 3600 + m2 * 60 + s2) - (h1 * 3600 + m1 * 60 + s1);
- }
- int fatorial(int n)
- {
- int fat = 1, i;
- for(i = n; i >= 1; i--)
- fat *= i;
- return fat;
- }
- int menu(void)
- {
- int i;
- desenha(2, 6, 35, 20);
- gotoxy(15, 7);
- printf("MENU");
- do
- {
- gotoxy(5, 8);
- printf("1 - Decimal para binario");
- gotoxy(5, 9);
- printf("2 - Binario para decimal");
- gotoxy(5, 10);
- printf("3 - Numero perfeito");
- gotoxy(5, 11);
- printf("4 - Diferenca entre duas horas");
- gotoxy(5, 12);
- printf("5 - Desenhar moldura");
- gotoxy(5, 13);
- printf("6 - Calcular fatorial");
- gotoxy(5, 14);
- printf("7 - Usar piano");
- gotoxy(5, 15);
- printf("8 - Sair ");
- scanf("%d", &i);
- }while(i < 1 || i > 8);
- return i;
- }
- void piano(int op)
- {
- switch(op)
- {
- case 97:
- Beep(FREQ_DO, TEMPO);
- break;
- case 115:
- Beep(FREQ_RE, TEMPO);
- break;
- case 100:
- Beep(FREQ_MI, TEMPO);
- break;
- case 102:
- Beep(FREQ_FA, TEMPO);
- break;
- case 103:
- Beep(FREQ_SOL, TEMPO);
- break;
- case 104:
- Beep(FREQ_LA, TEMPO);
- break;
- case 106:
- Beep(FREQ_SI, TEMPO);
- break;
- default:
- printf("");
- }
- }
- int menuPiano(void)
- {
- int i;
- gotoxy(39, 7);
- printf("a - do");
- gotoxy(39, 8);
- printf("s - re");
- gotoxy(39, 9);
- printf("d - mi");
- gotoxy(39, 10);
- printf("f - fa");
- gotoxy(39, 11);
- printf("g - sol");
- gotoxy(39, 12);
- printf("h - la");
- gotoxy(39, 13);
- printf("j - si");
- gotoxy(39, 14);
- i = getch();
- return i;
- }
- void desenhaRodape(char msg[100])
- {
- desenha(2, 21, 79, 24);
- gotoxy(25, 22);
- printf("%s", msg);
- }
- void usoFuncoes(int op)
- {
- int n, x1, y1, x2, y2, h1, m1, s1, h2, m2, s2;
- switch(op)
- {
- case 1:
- gotoxy(39, 7);
- printf("Digite o numero em decimal:\n");
- gotoxy(39, 8);
- scanf("%d", &n);
- gotoxy(39, 9);
- printf("%d = %d em binario\n", n, decToBin(n));
- gotoxy(39, 10);
- getch();
- break;
- case 2:
- gotoxy(39, 7);
- printf("Digite o numero em binario:\n");
- gotoxy(39, 8);
- scanf("%d", &n);
- gotoxy(39, 9);
- printf("%d = %d em decimal\n", n, binToDec(n));
- gotoxy(39, 10);
- getch();
- break;
- case 3:
- gotoxy(39, 7);
- printf("Digite o numero:\n");
- gotoxy(39, 8);
- scanf("%d", &n);
- gotoxy(39, 9);
- if(numPerf(n) == 1)
- printf("O numero e perfeito\n");
- else
- printf("O numero nao e perfeito\n");
- gotoxy(39, 10);
- getch();
- break;
- case 4:
- gotoxy(39, 7);
- printf("Digite a primeira hora (h, m, s):");
- gotoxy(39, 8);
- scanf("%d %d %d", &h1, &m1, &s1);
- gotoxy(39, 9);
- printf("Digite a segunda hora (h, m, s):");
- gotoxy(39, 10);
- scanf("%d %d %d", &h2, &m2, &s2);
- gotoxy(39, 11);
- printf("Diferenca = %d segundos", difHora(h1, m2, s1, h2, m2, s2));
- gotoxy(39, 12);
- getch();
- break;
- case 5:
- do
- {
- gotoxy(39, 7);
- printf("Digite a linha inicial:");
- gotoxy(39, 8);
- scanf("%d", &y1);
- }while(y1 < 1 || y1 > TFL);
- do
- {
- gotoxy(39, 9);
- printf("Digite a coluna inicial:");
- gotoxy(39, 10);
- scanf("%d", &x1);
- }while(x1 < 1 || x1 > TFC);
- do
- {
- gotoxy(39, 11);
- printf("Digite a linha final:");
- gotoxy(39, 12);
- scanf("%d", &y2);
- }while(y2 < 1 || y2 > TFL);
- do
- {
- gotoxy(39, 13);
- printf("Digite a coluna final:");
- gotoxy(39, 14);
- scanf("%d", &x2);
- }while(x2 < 1 || x2 > TFC);
- clrscr();
- desenha(x1, y1, x2, y2);
- getch();
- break;
- case 6:
- gotoxy(39, 7);
- printf("Digite o numero:\n");
- gotoxy(39, 8);
- scanf("%d", &n);
- gotoxy(39, 9);
- printf("Fatorial de %d = %d\n", n, fatorial(n));
- gotoxy(39, 10);
- getch();
- break;
- case 7:
- n = menuPiano();
- while(n != 27)
- {
- piano(n);
- n = menuPiano();
- }
- break;
- default:
- printf("Opcao invalida\n");
- }
- }
- void formulario(void)
- {
- int i;
- do
- {
- clrscr();
- desenha(1, 1, 80, 25);
- desenhaCabecalho("**** COMPILADOR DOS EXERCICIOS ****");
- desenha(37, 6, 79, 20);
- desenhaRodape("Obrigado por usar o programa...");
- i = menu();
- if(i != 8)
- usoFuncoes(i);
- else
- gotoxy(1, 25);
- }while(i != 8);
- }
- int main(void)
- {
- formulario();
- printf("\n");
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement