Senin, 14 November 2011

kalkulator (c++)


#include "math.h"
#include "stdlib.h"
#include "screen.cpp"
#include "keyboard.cpp"
#include "mouse.cpp"

int main(void)
{
Screen *layar = new Screen();
   Keyboard *tombol = new Keyboard(layar);
   Mouse *tikus = new Mouse();

   UCHAR *str, str2[11];
   double n1, n2, nh;
   int a, b;
   USHORT x, y, i;



   awal:
   layar->setMode(0x03);
   layar->cls();nh = 0;
   for (i=9; i<=59; i++)
   {
layar->setCursorPos(3,i);layar->writeChar(0xc4);
      layar->setCursorPos(7,i);layar->writeChar(0xc4);
   }
for (i=3; i<=7; i++)
   {
layar->setCursorPos(i,9);layar->writeChar(0xb3);
      layar->setCursorPos(i,59);layar->writeChar(0xb3);
      layar->setCursorPos(i,34);layar->writeChar(0xb3);
   }
   layar->setCursorPos(3,9);layar->writeChar(0xda);
   layar->setCursorPos(3,59);layar->writeChar(0xbf);
   layar->setCursorPos(7,9);layar->writeChar(0xc0);
   layar->setCursorPos(7,59);layar->writeChar(0xd9);
   layar->setCursorPos(3,34);layar->writeChar(0xc2);
   layar->setCursorPos(7,34);layar->writeChar(0xc1);

   layar->setCursorPos(2,10);
   layar->writeString("Kalkulator Sederhana menggunakan C++");
   layar->setCursorPos(4,10);
   layar->writeString("Nilai 1 : [          ]");
   layar->setCursorPos(5,10);
   layar->writeString("Nilai 2 : [          ]");
   layar->setCursorPos(6,10);
   layar->writeString("  Hasil : [          ]");
   layar->setCursorPos(4,35);
   layar->writeString("Operasi Matematika : ");
   layar->setCursorPos(5,35);
   layar->writeString(" [+]   [x]   [%]   [!]");
   layar->setCursorPos(6,35);
   layar->writeString(" [-]   [/]   [^]   [C]");
   layar->setCursorPos(8,10);
   layar->writeString("[Quit]");

layar->setCursorPos(4,22);
   str = tombol->getString(str2, 10);
   n1 = atoi(str);

   layar->setCursorPos(5,22);
   str = tombol->getString(str2, 10);
   n2 = atoi(str);

   tombol->hideCursor();
   tikus->showMouse();

   while (TRUE)
   {
    if (tikus->getClickMode() == MOUSE_LEFT_CLICK)
      {
      x = tikus->getX() / 8;
         y = tikus->getY() / 8;
         layar->setCursorPos(6,20);
         layar->writeString("[          ]");

         if ((x >= 37)&&(x <= 39)&&(y == 5)) nh = n1 + n2;
         if ((x >= 37)&&(x <= 39)&&(y == 6)) nh = n1 - n2;
         if ((x >= 43)&&(x <= 45)&&(y == 5)) nh = n1 * n2;
         if ((x >= 43)&&(x <= 45)&&(y == 6)) nh = n1 / n2;
         if ((x >= 49)&&(x <= 51)&&(y == 5))
         {
          a=n1; b=n2;
          nh = a % b;
         }
         if ((x >= 49)&&(x <= 51)&&(y == 6))
         {
            nh=1;
            for (i=1; i<=n2; i++)
            {
          nh = nh * n1;
            }
         }
         if ((x >= 55)&&(x <= 57)&&(y == 5))
         {
            nh=n1;
            for (i=1; i<n1; i++)
            {
            nh = nh * (n1-i);
            }
         }
         if ((x >= 55)&&(x <= 57)&&(y == 6)) goto awal;
         if ((x >= 12)&&(x <= 15)&&(y == 8)) break;

         gcvt(nh, 5, str);
         layar->setCursorPos(6,21);
         layar->writeString(str);
      }
   }

   delete layar; delete tombol; delete tikus;
   return EXIT_SUCCESS;
}

created by Tauvick22@gmail.com

Tidak ada komentar:

Posting Komentar