You are on page 1of 9

hari ini mao posting ahh tentang listing CPP 2, mumpung abis belajar Algoritma & Pemrograman 2 hehe.

Dan juga sedikit bagi ilmu lah hhehehee.. langkah pertama yaitu kita buka dulu Software Borland c++ 5.02 ya ok.. lalu pilih File lalu New lalu pilih Project

Setelah itu muncullah kotak seperti dibawah ini Ini adalah nama tempat penyimpanan filenya dan nama filenya

Ini adalah nama yang akan tampil pada layar project di Borland ini Disini saya pake DOS (standard) dan small aja soalnya kan masih biasa standard aja dlu heheh

Kita buat namanya yaitu latihan 01

Lalu kita klik kanan pilih View dan Edit Text

Lalu kita bisa membuat listing programnya disini

Dan ini salah satu contoh listing programnnya: Mencetak huruf AZ dengan warna huruf Putih dan Background Biru #include<conio.h> #include<dos.h> #include<stdlib.h> #define VIDEO_INT 0x10 #define UCHAR unsigned char void getCursorPos(UCHAR*y,UCHAR*x); void setCursorPos(UCHAR y,UCHAR x); void writeChar(UCHAR letter,UCHAR attr); main() { UCHAR baris, kolom; getCursorPos(&baris,&kolom); writeChar('A',0x1f); setCursorPos(baris,++kolom); writeChar('Z',0x1f); setCursorPos(baris,++kolom); getch();

return EXIT_SUCCESS; } void getCursorPos(UCHAR*y,UCHAR*x) { UCHAR row,col; asm mov ah,0x03; asm mov bh, 0x00; asm int VIDEO_INT; asm mov row,dh; asm mov col, dl; *y=row; *x=col; return; } void setCursorPos(UCHAR y, UCHAR x) { asm mov ah, 0x02; asm mov bh, 0x00; asm mov dh, y; asm mov dl, x; asm int VIDEO_INT; } void writeChar(UCHAR letter, UCHAR attr) { asm mov ah, 0x09; asm mov al, letter; asm mov bh, 0x00; asm mov bl, attr; asm mov ch, 0x00; asm mov cl, 0x01; asm int VIDEO_INT; return; } Ini adalah hasil Outputnya:

Untuk mencetak String #include<conio.h> #include<dos.h> #include<stdlib.h> #define VIDEO_INT 0x10 #define UCHAR unsigned char void getCursorPos(UCHAR *y, UCHAR *x); void setCursorPos(UCHAR y, UCHAR x); void writeChar(UCHAR letter, UCHAR attr); void writeString(UCHAR *str, UCHAR attr); int main(void) { UCHAR baris, kolom; getCursorPos(&baris, &kolom); // Baca posisi kursor writeChar('>', 0x1f); // Cetak karakter > setCursorPos(baris, ++kolom); // Pindahkan kursor writeString("Mencetak String", 0x4f); getCursorPos(&baris, &kolom); setCursorPos(baris, ++kolom); writeChar('<', 0x1f); // Cetak karakter < setCursorPos(baris, ++kolom); // Pindahkan kursor getch(); return EXIT_SUCCESS;

} void getCursorPos(UCHAR *y, UCHAR *x) // Baca posisi { // kursor UCHAR row, col; asm mov ah, 0x03; // Register AH = 3 heksadesimal asm mov bh, 0x00; // Register BH = 0 heksadesimal asm int VIDEO_INT; // Lakukan interupsi asm mov row, dh; // Salin register DH ke row asm mov col, dl; // Salin register DL ke col *y = row; *x = col; // Salin row ke y, col ke x return; } void setCursorPos(UCHAR y, UCHAR x) // Memindahkan { // Posisi kursor asm mov ah, 0x02; // Register AH = 3 heksadesimal asm mov bh, 0x00; // Register BH = 0 heksadesimal asm mov dh, y; // Register DH = letak baris asm mov dl, x; // Register DL = letak kolom asm int VIDEO_INT; // Lakukan interupsi return; } void writeChar(UCHAR letter, UCHAR attr) // Mencetak { // huruf asm mov ah, 0x09; // Register AH = 9 heksadesimal asm mov al, letter; // Register AL = hurufnya asm mov bh, 0x00; // Register BH = 0 heksadesimal asm mov bl, attr; // Register BL = warna huruf asm mov ch, 0x00; // Register CH dan CL menentukan asm mov cl, 0x01; // banyak pencetakan asm int VIDEO_INT; // Lakukan interupsi return; }

void writeString(UCHAR *str, UCHAR attr) // Mencetak { // string UCHAR x, y; getCursorPos(&y, &x); // Simpan posisi kursor for (; *str != '\0'; str++) // Loop sampai ditemukan { // NULL if (x > 79) { // Jika sudah sampai kolom y++; x = 0; // ke-80, pindah baris dan } // pindah ke kolom ke-1 setCursorPos(y, x++); // Pindahkan posisi kursor writeChar(*str, attr); // Cetak per karakter } return; } Ini Outputnya:

Ini listing untuk mengubah posisi layar normal #include <stdio.h> #include <iostream.h> #include <conio.h> #include <iomanip.h> #include <dos.h> #include <stdlib.h> #define UNCHAR unsigned char void bebas (UNCHAR bsi); main () {

cout<<"Posisi di Layar normal.." <<"\nTekan ENTER untuk merubah..."; getch(); bebas(0x01); cout<<"Posisi berubah..." <<"\nTekan ENTER untuk kembali ke normal..."; getch(); bebas(0x03); cout<<"Normal.."; getch(); return EXIT_SUCCESS; } void bebas ( UNCHAR bsi) { asm mov ah, 0x00; asm mov al, bsi; asm int 0x10; return ; } Ini outputnya:

You might also like