Ini adalah program sederhana dari Penjualan Motor Sederhana Saya menggunakan C++.
#include iostream.h
#include iomanip.h
#include stdio.h
#include stdlib.h
#include math.h
#include conio.h
#include string.h
struct data {
char kode[7] ;
char nama[30] ;
float harga, jumlah, total ;
} mtr[50] ;
float jumlah;
void menu() ;
void isi();
void baca();
void main()
{
char pil ='0' ;
while (pil != '3')
{
menu() ;
pil = getche() ;
switch(pil)
{
case '1' :
isi() ; break ;
case '2' :
baca() ; break ;
case '3' :
break ;
}
}
}
void menu()
{
clrscr() ;
gotoxy (15, 5) ; cout << "MENU DATA SISTEM INFORMASI MOTOR";
gotoxy (15, 6) ; cout << "-------------------------------------------------";
gotoxy (15, 7) ; cout << "[1] Mengisi/Membuat File Baru" ;
gotoxy (15, 8) ; cout << "[2] Membaca Data" ;
gotoxy (15,9) ; cout << "[3] Selesai" ;
gotoxy (15,10) ; cout << "-------------------------------------------------";
gotoxy (15,11) ; cout << "PILIHAN : " ;
}
void isi()
{ FILE *coba ;
float atof() ;
int i, n = 0 ;
while(1)
{
clrscr() ;
gotoxy (15, 5) ; cout << "MEMASUKKAN DATA PENJUALAN MOTOR" ;
gotoxy (15, 6) ; cout << "---------------------------------------------------------";
gotoxy (15, 7) ; cout << "Kode\t\t: "; gets(mtr[n].kode);
if (strlen(mtr[n].kode)==0)
break ;
gotoxy (15, 8) ; cout << "Nama\t\t: "; gets(mtr[n].nama) ;
gotoxy (15, 9) ; cout << "Harga\t\t: "; cin >> mtr[n].harga ;
gotoxy (15, 10) ; cout << "Jumlah\t\t: "; cin >> mtr[n].jumlah ;
mtr[n].total= mtr[n].harga * mtr[n].jumlah ;
gotoxy (15, 6) ; cout << "---------------------------------------------------------";
n++ ;
}
coba = fopen("c:\\Motor.Dat", "wb") ;
for ( i=0 ; i
fwrite(&mtr[i], sizeof(mtr[i]),1,coba) ;
}
fclose(coba) ;
}
void baca()
{
FILE *coba ;
int i=0, n = 0 ;
clrscr() ;
coba = fopen("c:\\Motor.Dat", "rb") ;
if (coba==NULL)
{
gotoxy (20,10) ; cout << "File Motor.Dat belum ada" ;
gotoxy (20,12) ; cout << "Tekan sembarang Tombol" ;
getch() ;
return ;
}
gotoxy (30,1) ; cout << "LAPORAN DATA PENJUALAN MOTOR" ;
gotoxy (5,2) ; cout << "__________________________________________________________________________" ;
gotoxy (6,3) ; cout << "NO";
gotoxy (10,3); cout << "KODE";
gotoxy (25,3); cout << "NAMA";
gotoxy (40,3); cout << "HARGA";
gotoxy (55,3); cout << "JUMLAH";
gotoxy (66,3); cout << "TOTAL";
gotoxy (5,4) ; cout << "__________________________________________________________________________" ;
while( (fread( &mtr[n], sizeof(mtr[n]),1, coba)) ==1 )
{
i++ ;
gotoxy(6 ,4+i) ; cout << i ;
gotoxy(10,4+i) ; cout << mtr[n].kode ;
gotoxy(24,4+i) ; cout << mtr[n].nama;
gotoxy(39,4+i) ; cout <
}
gotoxy (5, 5+i) ; cout <<"__________________________________________________________________________" ;
gotoxy(65,6+i) ; cout << setprecision(12)<< jumlah;
gotoxy (40, 6+i) ; cout <<" Total Keseluruhan" ;
getch() ;
fclose(coba) ;
}
Berikut adalah Hasil Outputnya:
1. Menu Utama,,
2. Memasukkan Kode, Nama Motor, Harga dan Qty Terjual
3. Hasil Print Out dari Data Penjulaan yang dimasukkan.
Sekian postingan saya kali ini, semoga bermanfaat...
Kaga Bisa di Code BLocks Min
BalasHapus