Berikut adalah contoh Source Code Program Bahasa C (Desain Layar) :
Contoh 1
Sumber : Abdul Kadir, 2003 Pemrograman Dasar Turbo C untuk IBM PC.
Contoh 1
/* ------------------------- */
/* file program: CLREOL.C */
/* contoh pemakaian clreol() */
/* untuk menghapus text mulai posisi kursor */
/* hingga akhir baris , dengan tujuan */
/* untuk membentuk garis berwarna-warni */
/* -------------------------------------------- */
#include "conio.h"
main()
{
int j;
clrscr();
for(j=1;j<7;j++)
{
textbackground(j); /* pilih latar belakang */
gotoxy(1,j); /* ke awal baris */
clreol(); /* hapus hingga akhir baris */
getch();
}
}
Contoh 2 /* -------------------------------- */
/* file program info layar */
/* untuk memperoleh informrasi video */
/* -------------------------------- */
#include "conio.h"
main()
{
struct text_info data;
clrscr();
directvideo=0; /* output kelalyar melalui ROM-BIOS */
window(10,2,70,15); /* atur jendela */
textcolor(16*1+15); /* atur atribut */
gettextinfo(&data); /* peroleh info video */
window(1,1,80,25); /* jendela sebesar layar penuh */
cprintf("DATA KEADAAN VIDEO: \r\n");
cprintf("koordinat jendela : \r\n");
cprintf("kolom: kiri=%2d kanan=%2d\r\n",data.winleft,data.winright);
cprintf("baris: atas:%2d bawa:%2d\r\n",data.wintop,data.winbottom);
cprintf("data warna: \r\n");
cprintf("atribut text = %2d\r\n",data.attribute);
cprintf("atribut normal = %2d\r\n",data.normattr);
cprintf("lain-lain\r\n");
cprintf("mode video = %d\r\n",data.currmode);
cprintf("tinggi layar = %d\r\n",data.screenheight);
cprintf("lebr layar = %d\r\n",data.screenwidth);
cprintf("posisi kursor = baris =%2d kolom=%2d\r\n",data.cury,data.curx);
getch();
}
Contoh 3 /* ------------------------------- */
/* fileprogram : INSDEL.C */
/* contoh pemakaian insline() dan delline() */
/* untuk membuat animasi penampilan teks */
/* ----------------------------------------------- */
#include "conio.h"
#include "stdio.h"
#include "string.h"
main()
{
static char st[][20]=
{"iiiiiiiiiiiiiiiiiiii",
"i ANIMASI TEKS i",
"i DENGAN i",
"i TURBO C i",
"iiiiiiiiiiiiiiiiiiii"};
int x,i;
/* --keadaan awal---*/
clrscr();
x=40-strlen(st[1])/2;
gotoxy(x,1); cputs(st[0]);
gotoxy(x,2); cputs(st[1]);
gotoxy(x,13); cputs(st[2]);
gotoxy(x,24); cputs(st[3]);
gotoxy(x,25); cputs(st[4]);
/* buat animasi penggeseran baris */
for(i=1;i<11; i++)
{
window(1,1,80,12); /* jendela untuk penggeseran kebawah*/
insline(); /* geser baris kebawah */
window(1,14,80,25); /* jendela untuk penggeseran keatas */
delline(); /* geser bais keatas */
}
getch();
}
Contoh 4 /* --------------------------------- */
/* file program:KOTAK.C */
/* membuat kotak yang berubah */
/* jadi kecil menjadi besar */
/* --------------------------------- */
#include "stdio.h"
main()
{
int i,j;
textbackground(7); /* warna kotak */
for(i=1;i<=10;i++)
{
window(41-4*i, 11-i, 40+4*i, 15+1); /* definisi kotak */
clrscr();
for(j=0;j<3000;j++)
; /* tunda sebentar */
}
getch();
}
Contoh 5 /* ----------------------- */ /* File program: KURSOR.C */ /* Memperoleh posisi kursor */ /* ------------------------ */ #includeContoh 6main() { int pos_brs,pos_klm; clrscr(); /* hapus layar */ gotoxy(12,15); /* menempatkan kursor */ pos_brs= wherey(); /* posisi baris kursor berada */ pos_klm= wherey(); /* posisi kolom kursor berada */ cprintf("posisi kursor - baris = %d kolom = %d",pos_brs,pos_klm); getch(); }
/* ----------------------------------------- */
/* file program : MODLYR.C */
/* contoh mengatur mode layar */
/* ----------------------------------------- */
#include "conio.h"
void tekan_enter(void);
main()
{
clrscr();
cputs("Mode awal pada keadaan awal");
tekan_enter();
textmode(C40);
cputs("Mode layar 40 kolom");
tekan_enter();
textmode(C80);
cputs("Mode layar 80 kolom");
tekan_enter();
getch();
}
void tekan_enter(void)
{
cputs("\r\nTekanlah enter untuk melanjutkan\r\n");
while (getch() !=13); /*baca enter */
}
Contoh 7 /* -------------------------------------- */
/* file program: SCREEn.C */
/* contoh menampilkan keluaran kelayar */
/* menggunakan cprintf() dan cputs() */
/* serta dengan mengatur variabel directvideo */
/* -------------------------------------- */
#include "conio.h"
main()
{
int brs=2;
directvideo=0; /* atur penampilan kelayar melalui ROM-BIOS */
clrscr();
cputs("String ini ditampilkan kelayar\r\n");
cprintf("Ini merupakan baris ke-%d\r\n",brs);
getch();
}
Contoh 8 /* --------------------------------- */
/* file program: SLNLAYAR.C */
/* contoh pemakaian gettext() dan puttext() */
/* -------------------------------------------------- */
#include "conio.h"
main()
{
char buffer[180*25*2]; /* untuk memegang data satu layar */
/* layar awal */
textattr(BLUE*16+15); /* kuning diatas biru */
clrscr();
cputs(" ini merupakan data semula\r\n");
cputs(" yang ada pada layar");
cputs("\r\n");
cputs(" tekanlah ENTER.");
while(getche() !=13); /* baca enter */
gettext(1,1,80,25,buffer); /* simpan seluruh data pada layar */
/* layar kedua */
textattr(LIGHTGRAY*16); /* hitam diatas abu-abu */
clrscr();
cputs(" LATAR KEDUA\r\n");
cputs("\r\n");
cputs(" tekanlah enter untuk\r\n");
cputs(" menuju layar pertama");
while(getche() !=13);
puttext(1,1,80,25,buffer); /* tampilkan isi layar pertama */
while (getche() !=13);
getch();
}
Contoh 9 /* -------------------------------------- */
/* file programa tengan: TENGAH.C */
/* mengatur penempatan kursor */
/* untuk menampilkan text ditengan layar */
/* -------------------------------------- */
#include "conio.h"
main()
{
char *teks="TURBO C";
clrscr(); /* hapus layar */
gotoxy(40-strlen(teks)/2,12); /* tengah layar */
cputs(teks); /* tampilkan teks */
getch();
}
Contoh 10 /* ------------------------------------------ */
/* file program: WARNA1.C */
/* contoh pengaturan warna text */
/* ------------------------------------------ */
#include "stdio.h"
main()
{
int i;
clrscr();
for(i=1;i<6;i++)
{
gotoxy(i,i); /* penempatan kursor */
textcolor(i); /* warna depan text */
cprintf("Warna ke-%d",i);
}
getch();
}
Contoh 11 /* ------------------------------------------ */
/* file program : WARNA2.C */
/* conto mengatur warna depan dan */
/* latar belakang text */
/* ------------------------------------------ */
#include "conio.h"
main()
{
clrscr();
textcolor(15); /* warna text putih */
textbackground(4); /* latar belakang merah */
cputs("teks putih, latar belakang merah\r\n");
textcolor(14+BLINK); /* warna text kuning berkedip */
textbackground(1); /* latar belakang biru */
cputs("teks kuning berkedip, diatas warna biru\r\n");
textcolor(7); /* warna normal */
textbackground(0); /* latar belakang hitam */
cputs("text dengan warna normal");
getch();
}
Contoh 12 /* ------------------------------- */
/* file program : WARNA3.C */
/* contoh pengaturan warna text menggunakan */
/* textattr(), lowvideo(), highvideo(), dan normvideo() */
/* -------------------------------------------------------------*/
#include "conio.h"
main()
{
clrscr();
textattr(LIGHTCYAN); /* warna sian cerah */
cputs("TURBO C\r\n");
lowvideo();
cputs("TURBO.C\r\n");
highvideo();
cputs("TURBO C\r\n");
normvideo();
cputs("TURBO C\r\n");
getch();
}
Sumber : Abdul Kadir, 2003 Pemrograman Dasar Turbo C untuk IBM PC.


14.50
alie
Posted in:
0 komentar:
Posting Komentar