Contoh Program Prosedur BORLAND C++



 

Bagi teman yang pengen belajar program dengan borland c++ saya ada contoh nya sedikit ...


#include <stdio.h>
#include <conio.h>
entry()
{
FILE *vf;
char mad='y',dsb='y';
struct
{char tt[10] ;
 char np[15];
 int jl;
 char jm;
}vr;
vf=fopen("copy.dat","w");
if
(vf==NULL)
{
clrscr();
gotoxy(25,23);printf("Data Tidak Disimpan");
getch();
vf=fopen("copy.dat","w");
}
while (mad=='y'||mad=='Y')
{
clrscr();
gotoxy(25,5) ;printf("ENTRY DATA FOTO COPY");
gotoxy(25,6) ;printf("--------------------");
gotoxy(25,7) ;printf("TANGGAL TRANSAKSI             :"); gets(vr.tt);
gotoxy(25,8) ;printf("NAMA PELANGGAN                :"); gets(vr.np);
gotoxy(25,9) ;printf("JENIS MESIN                   :"); scanf("%c",&vr.jm);fflush(stdin);
gotoxy(25,10) ;printf("JUMLAH LEMBAR                 :"); scanf("%i",&vr.jl);fflush(stdin);
gotoxy(25,11) ;printf("DATA SUDAH BENAR[Y/T]         :");scanf("%c",&dsb);fflush(stdin);
  if (dsb=='y'|| dsb== 'Y')
  {
fwrite(&vr,sizeof(vr),1,vf);
  }
else
  {
gotoxy(25,14);printf("DATA TIDAK DISIMPAN");
  }
gotoxy(25,12) ;printf("MASIH ADA DATA[Y/T]           :");scanf("%c",&mad);fflush(stdin);
}
fclose(vf);
}
laporan()
{
FILE * vf;
long int tot;
int br,no;
int tl;
struct
{char tt[10];
 char np[15];
 int jl;
 char jm;
}vr;
vf=fopen("copy.dat","r");
if(vf==NULL)
{clrscr();
gotoxy(25,23);printf("Data Tidak Dibuat");
getch();
}
clrscr();
gotoxy(15,1);printf("LAPORAN DATA TRANSAKSI FOTOCOPY KHAIRUNNISA");
gotoxy(1,2);printf("----------------------------------------------------------------");
gotoxy(1,3);printf("|NO  | tanggal  | nama pelanggan|jenis|tarif/|jumlah|total     |");
gotoxy(1,4);printf("|    |transaksi |               |mesin|lembar|lembar|tarif     |");
gotoxy(1,5);printf("----------------------------------------------------------------");
                  /*123456789012345678901234567890123456789012345678901234567890123456
                             1         2         3         4         5         6      */

br=5;no=0;
while(fread(&vr,sizeof(vr),1,vf))
{
no=no+1;
if (vr.jm=='a')
  { tl=75;}
   else if (vr.jm=='b')
  { tl=100;}
   else
   {tl=125;}
 tot=vr.jl*tl;
gotoxy(1,br);printf("%s""%i","|",no);
gotoxy(6,br);printf("%s""%s","|",vr.tt);
gotoxy(17,br);printf("%s""%s","|",vr.np);
gotoxy(33,br);printf("%s""%c","|",vr.jm);
gotoxy(39,br);printf("%s""%i","|",tl);
gotoxy(46,br);printf("%s""%i","|",vr.jl);
gotoxy(53,br);printf("%s""%li","|",tot);
gotoxy(64,br);printf("%s","|");
br=br+1;
}
gotoxy(1,br);printf("----------------------------------------------------------------");
fclose(vf);
getche();
}
entry();
laporan();
main()
{
    int pil=0;
    while(pil<3)
    {
clrscr();
gotoxy (25, 5) ; printf("MENU PILIHAN");
gotoxy (25, 6) ; printf("[1] ENTRY ");
gotoxy (25, 7) ; printf("[2] LAPORAN");
gotoxy (25, 8) ; printf("[3] EXIT");
gotoxy (25, 9) ; printf("Input  Pilihan [1-3]:");scanf("%i",&pil);fflush(stdin);
if (pil==1)
{   entry();  continue; }
  else if (pil==2)
    { laporan();  continue; }
       }
}


Sekian semoga bermanfaat !!!

Posting Komentar