CONTOH SOAL + JAWABAN BORLAND C++



JAWABANNYA :

#include <math.h>
#include <stdlib.h>
#include "screen.cpp"
#include "keyboard.cpp"

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

  unsigned long int tb, hb, jb;
  UCHAR *str, str2[16];
  UCHAR key='0';


  layar->setMode(0x03);
  layar->setCursorPos(5, 14);
  layar->writeString("Struk Belanja Toko Albani's");
  layar->setCursorPos(7, 14);
  layar->writeString("Harga Barang = Rp. ");
  layar->setCursorPos(7, 38);

  str = tombol->getString(str2, 10);
  hb = atoi(str);

  layar->setCursorPos(8, 14);
  layar->writeString("Jumlah Beli  = ");
  layar->setCursorPos(8, 38);

  str = tombol->getString(str2, 10);
  jb = atoi(str);
  tb = hb * jb;

  gcvt(tb, 10, str2);

  layar->setCursorPos(9, 14);
  layar->writeString("Total Belanja= Rp. ");
  layar->setCursorPos(9, 38);
  layar->writeString(str2);

  layar->setCursorPos(11,14);
  layar->writeString("Berapa Jumlah huruf Alphabet ? ");
  layar->setCursorPos(13,14);
  layar->writeString("[A] 24");
  layar->setCursorPos(15,14);
  layar->writeString("[B] 26");
  layar->setCursorPos(17,14);
  layar->writeString("Jawaban Anda : [...]");

  tombol->hideCursor();
  key = tombol->getKey();


  switch (key)
  {
      case'a':layar->writeString("Salah, jawaban yang benar adalah B !");
                                  tombol->getKey();
              delete tombol;
              delete layar;
              exit(EXIT_FAILURE);
      case'b':layar->writeString("Selamat, Anda benar!");
              tombol->getKey();
              delete tombol;
              delete layar;
              exit(EXIT_SUCCESS);
      default:layar->writeString("Pilihlah A atau B! ");
      }

  layar->setCursorPos(17, 30);
  layar->writeChar(key);

  layar->setCursorPos(20, 14);
  layar->writeString("Tekan SHIFT ...");
  tombol->hideCursor();

  while (TRUE)
  {
    if ((tombol->getKeyState(STATE_RSHIFT)) ||
        (tombol->getKeyState(STATE_LSHIFT)))
        break;
  }

  delete layar;
  delete tombol;
  return EXIT_SUCCESS;
}

1 komentar:

aji cahya putra. Diberdayakan oleh Blogger.

Copyright © / AJI CAHYA PUTRA

Template by : Urang-kurai / powered by :blogger