Advertisement
Jvsierra

Programa gotoxy completo

Aug 18th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. #include "meuconio.h"
  5.  
  6. #define TFL 25
  7. #define TFC 80
  8. #define FREQ_DO 261
  9. #define FREQ_RE 293
  10. #define FREQ_MI 329
  11. #define FREQ_FA 349
  12. #define FREQ_SOL 392
  13. #define FREQ_LA 440
  14. #define FREQ_SI 493
  15. #define TEMPO 1000
  16.  
  17. void desenha(int x1, int y1, int x2, int y2)
  18. {
  19. int x;
  20.  
  21. textcolor(4);
  22.  
  23. gotoxy(x1, y1);
  24. printf("*");
  25. gotoxy(x2, y1);
  26. printf("*");
  27. gotoxy(x1, y2);
  28. printf("*");
  29. gotoxy(x2, y2);
  30. printf("*");
  31.  
  32. textcolor(10);
  33.  
  34. for(x = y1 + 1; x < y2; x++)
  35. {
  36. gotoxy(x1, x);
  37. printf("|");
  38. gotoxy(x2, x);
  39. printf("|");
  40. }
  41.  
  42. for(x = x1 + 1; x < x2; x++)
  43. {
  44. gotoxy(x, y1);
  45. printf("-");
  46. gotoxy(x, y2);
  47. printf("-");
  48. }
  49.  
  50. textcolor(15);
  51. }
  52.  
  53. void desenhaCabecalho(char msg[])
  54. {
  55. desenha(2, 2, 79, 5);
  56.  
  57. gotoxy(20, 3);
  58.  
  59. printf("%s ", msg);
  60. }
  61.  
  62. int decToBin(int dec)
  63. {
  64. int ret = 0, cont = 0;
  65.  
  66. while(dec >= 1)
  67. {
  68. if(dec % 2 == 1)
  69. ret += pow(10, cont);
  70.  
  71. cont++;
  72. dec /= 2;
  73. }
  74.  
  75. return ret;
  76. }
  77.  
  78. int binToDec(int bin)
  79. {
  80. int ret = 0, cont = 0;
  81.  
  82. while(bin >= 1)
  83. {
  84. if(bin % 10 == 1)
  85. ret += pow(2, cont);
  86.  
  87. cont++;
  88. bin /= 10;
  89. }
  90.  
  91. return ret;
  92. }
  93.  
  94. int numPerf(int n)
  95. {
  96. int ret, i, soma = 0;
  97.  
  98. for(i = 1; i < n; i++)
  99. if(n % i == 0)
  100. soma += i;
  101.  
  102. if(soma == n)
  103. ret = 1;
  104. else
  105. ret = 0;
  106.  
  107. return ret;
  108. }
  109.  
  110. int difHora(int h1, int m1, int s1, int h2, int m2, int s2)
  111. {
  112. return (h2 * 3600 + m2 * 60 + s2) - (h1 * 3600 + m1 * 60 + s1);
  113. }
  114.  
  115. int fatorial(int n)
  116. {
  117. int fat = 1, i;
  118.  
  119. for(i = n; i >= 1; i--)
  120. fat *= i;
  121.  
  122. return fat;
  123. }
  124.  
  125. int menu(void)
  126. {
  127. int i;
  128.  
  129. desenha(2, 6, 35, 20);
  130.  
  131. gotoxy(15, 7);
  132.  
  133. printf("MENU");
  134.  
  135. do
  136. {
  137. gotoxy(5, 8);
  138.  
  139. printf("1 - Decimal para binario");
  140.  
  141. gotoxy(5, 9);
  142.  
  143. printf("2 - Binario para decimal");
  144.  
  145. gotoxy(5, 10);
  146.  
  147. printf("3 - Numero perfeito");
  148.  
  149. gotoxy(5, 11);
  150.  
  151. printf("4 - Diferenca entre duas horas");
  152.  
  153. gotoxy(5, 12);
  154.  
  155. printf("5 - Desenhar moldura");
  156.  
  157. gotoxy(5, 13);
  158.  
  159. printf("6 - Calcular fatorial");
  160.  
  161. gotoxy(5, 14);
  162.  
  163. printf("7 - Usar piano");
  164.  
  165. gotoxy(5, 15);
  166.  
  167. printf("8 - Sair ");
  168.  
  169. scanf("%d", &i);
  170. }while(i < 1 || i > 8);
  171.  
  172. return i;
  173. }
  174.  
  175. void piano(int op)
  176. {
  177. switch(op)
  178. {
  179. case 97:
  180. Beep(FREQ_DO, TEMPO);
  181. break;
  182. case 115:
  183. Beep(FREQ_RE, TEMPO);
  184. break;
  185. case 100:
  186. Beep(FREQ_MI, TEMPO);
  187. break;
  188. case 102:
  189. Beep(FREQ_FA, TEMPO);
  190. break;
  191. case 103:
  192. Beep(FREQ_SOL, TEMPO);
  193. break;
  194. case 104:
  195. Beep(FREQ_LA, TEMPO);
  196. break;
  197. case 106:
  198. Beep(FREQ_SI, TEMPO);
  199. break;
  200. default:
  201. printf("");
  202. }
  203. }
  204.  
  205. int menuPiano(void)
  206. {
  207. int i;
  208.  
  209. gotoxy(39, 7);
  210. printf("a - do");
  211. gotoxy(39, 8);
  212. printf("s - re");
  213. gotoxy(39, 9);
  214. printf("d - mi");
  215. gotoxy(39, 10);
  216. printf("f - fa");
  217. gotoxy(39, 11);
  218. printf("g - sol");
  219. gotoxy(39, 12);
  220. printf("h - la");
  221. gotoxy(39, 13);
  222. printf("j - si");
  223. gotoxy(39, 14);
  224.  
  225. i = getch();
  226. return i;
  227. }
  228.  
  229. void desenhaRodape(char msg[100])
  230. {
  231. desenha(2, 21, 79, 24);
  232.  
  233. gotoxy(25, 22);
  234.  
  235. printf("%s", msg);
  236. }
  237.  
  238. void usoFuncoes(int op)
  239. {
  240. int n, x1, y1, x2, y2, h1, m1, s1, h2, m2, s2;
  241.  
  242. switch(op)
  243. {
  244. case 1:
  245. gotoxy(39, 7);
  246. printf("Digite o numero em decimal:\n");
  247. gotoxy(39, 8);
  248. scanf("%d", &n);
  249. gotoxy(39, 9);
  250. printf("%d = %d em binario\n", n, decToBin(n));
  251. gotoxy(39, 10);
  252. getch();
  253. break;
  254. case 2:
  255. gotoxy(39, 7);
  256. printf("Digite o numero em binario:\n");
  257. gotoxy(39, 8);
  258. scanf("%d", &n);
  259. gotoxy(39, 9);
  260. printf("%d = %d em decimal\n", n, binToDec(n));
  261.  
  262. gotoxy(39, 10);
  263. getch();
  264. break;
  265. case 3:
  266. gotoxy(39, 7);
  267. printf("Digite o numero:\n");
  268. gotoxy(39, 8);
  269. scanf("%d", &n);
  270.  
  271. gotoxy(39, 9);
  272.  
  273. if(numPerf(n) == 1)
  274. printf("O numero e perfeito\n");
  275. else
  276. printf("O numero nao e perfeito\n");
  277.  
  278. gotoxy(39, 10);
  279.  
  280. getch();
  281. break;
  282. case 4:
  283. gotoxy(39, 7);
  284. printf("Digite a primeira hora (h, m, s):");
  285. gotoxy(39, 8);
  286. scanf("%d %d %d", &h1, &m1, &s1);
  287. gotoxy(39, 9);
  288. printf("Digite a segunda hora (h, m, s):");
  289. gotoxy(39, 10);
  290. scanf("%d %d %d", &h2, &m2, &s2);
  291.  
  292. gotoxy(39, 11);
  293.  
  294. printf("Diferenca = %d segundos", difHora(h1, m2, s1, h2, m2, s2));
  295.  
  296. gotoxy(39, 12);
  297.  
  298. getch();
  299. break;
  300. case 5:
  301. do
  302. {
  303. gotoxy(39, 7);
  304. printf("Digite a linha inicial:");
  305.  
  306. gotoxy(39, 8);
  307.  
  308. scanf("%d", &y1);
  309. }while(y1 < 1 || y1 > TFL);
  310.  
  311. do
  312. {
  313. gotoxy(39, 9);
  314. printf("Digite a coluna inicial:");
  315.  
  316. gotoxy(39, 10);
  317. scanf("%d", &x1);
  318. }while(x1 < 1 || x1 > TFC);
  319.  
  320. do
  321. {
  322. gotoxy(39, 11);
  323. printf("Digite a linha final:");
  324.  
  325. gotoxy(39, 12);
  326.  
  327. scanf("%d", &y2);
  328. }while(y2 < 1 || y2 > TFL);
  329.  
  330. do
  331. {
  332. gotoxy(39, 13);
  333. printf("Digite a coluna final:");
  334.  
  335. gotoxy(39, 14);
  336. scanf("%d", &x2);
  337. }while(x2 < 1 || x2 > TFC);
  338.  
  339.  
  340. clrscr();
  341.  
  342. desenha(x1, y1, x2, y2);
  343.  
  344. getch();
  345. break;
  346. case 6:
  347. gotoxy(39, 7);
  348. printf("Digite o numero:\n");
  349. gotoxy(39, 8);
  350. scanf("%d", &n);
  351.  
  352. gotoxy(39, 9);
  353. printf("Fatorial de %d = %d\n", n, fatorial(n));
  354.  
  355. gotoxy(39, 10);
  356. getch();
  357. break;
  358. case 7:
  359. n = menuPiano();
  360.  
  361. while(n != 27)
  362. {
  363. piano(n);
  364.  
  365. n = menuPiano();
  366. }
  367. break;
  368. default:
  369. printf("Opcao invalida\n");
  370. }
  371. }
  372.  
  373. void formulario(void)
  374. {
  375. int i;
  376.  
  377. do
  378. {
  379. clrscr();
  380.  
  381. desenha(1, 1, 80, 25);
  382.  
  383. desenhaCabecalho("**** COMPILADOR DOS EXERCICIOS ****");
  384.  
  385. desenha(37, 6, 79, 20);
  386.  
  387. desenhaRodape("Obrigado por usar o programa...");
  388.  
  389. i = menu();
  390.  
  391. if(i != 8)
  392. usoFuncoes(i);
  393. else
  394. gotoxy(1, 25);
  395. }while(i != 8);
  396. }
  397.  
  398. int main(void)
  399. {
  400. formulario();
  401.  
  402. printf("\n");
  403.  
  404. getch();
  405.  
  406. return 0;
  407. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement