Senin, Maret 28

Source Code C++ Data Motor

Program c++ ini memiliki fungsi menambah data,hapus,edit dan tampil. Bagi yang menbutuhkan silahkan di downlaod, tetapi souce kode ini jauh dari kesempurnaan, mohon untuk diedit ulang,tks


#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<string.h>
typedef struct motor
{
char nama[20];
char alamat[20];
char merek[20];
int th;
char warna[20];
int cc;
int id;
}motor;
int main()
{
float id;
FILE *fp,*ft;
char another, choice;
motor stu;

long int recsize;
fp=fopen("master.DAT","rb+");
if(fp==NULL)
{
fp=fopen("master.DAT","wb+");
if(fp==NULL)
{
printf("File gagal diakses");
}
}
recsize=sizeof(stu);
while(!(choice=='5'))
{
printf("\n================");
printf("\nDAFTAR PILIHAN");
printf("\n================");
printf("\n1.TAMBAH DATA ");
printf("\n2.HAPUS DATA ");
printf("\n3.EDIT DATA ");
printf("\n4.TAMPIL DATA ");
printf("\n5.KELUAR ");
printf("\n===================");
printf("\nPILIHLAH SALAH SATU");

fflush(stdin);
scanf("%c",&choice);
printf("\n===================");
switch(choice)
{
case'1':
fseek(fp,0,SEEK_END);
another='Y';
while(another=='Y'||another=='y')
{
clrscr();
printf("\n===================================");
printf("\nDATA Motor");
printf("\n===================================");
printf("\n Nama Pemilik : ");scanf("%s",&stu.nama);
printf("\n Alamat Pemilik : ");scanf("%s",&stu.alamat);
printf("\n Merek : ");scanf("%d",&stu.merek);
printf("\n Tahun Perakitan : ");scanf("%s",&stu.th);
printf("\n Warna : ");scanf("%s",&stu.warna);
printf("\n Volume Silinder(CC) : ");scanf("%s",&stu.cc);

fwrite(&stu,recsize,1,fp);
printf("\n===================================");
printf("\nMAU TAMBAH DATA LAGI[Y/T]? ");
fflush(stdin);
another=getchar();
}break;
case'2':
another='Y';
while(another=='Y'||another=='y')
{
clrscr();
printf("\n");

printf("\n===========================");
printf("\nDATA YANG AKAN DIHAPUS");
printf("\n===========================");
printf("\n Nama Pemilik : ");scanf("%s",&stu.nama);
printf("\n Alamat Pemilik : ");scanf("%s",&stu.alamat);
printf("\n Merek : ");scanf("%d",&stu.merek);
printf("\n Tahun Perakitan : ");scanf("%s",&stu.th);
printf("\n Warna : ");scanf("%s",&stu.warna);
printf("\n Volume Silinder(CC) : ");scanf("%s",&stu.cc);
printf("\n===========================");
ft=fopen("TEMP.DAT","wb");
rewind(fp);
while(fread(&stu,recsize,1,fp)==1)
{
if(stu.id!=0)
fwrite(&stu,recsize,1,ft);
}
fclose(fp);
fclose(ft);
remove("master.DAT");
rename("TEMP.DAT","master.DAT");
fp=fopen("master.DAT","wb+");
printf("\nMAU HAPUS DATA LAGI[Y/T]?");
fflush(stdin);
another=getchar();
}break;
case'3':
another='Y';
while(another=='Y'||another=='y')
{
clrscr();
printf("\n");
printf("\n===============================");
printf("\nDATA MOTOR ");
printf("\n===============================");
printf("\n Nama Pemilik : ");scanf("%s",&stu.nama);
printf("\n Alamat Pemilik : ");scanf("%s",&stu.alamat);
printf("\n Merek : ");scanf("%d",&stu.merek);
printf("\n Tahun Perakitan : ");scanf("%s",&stu.th);
printf("\n Warna : ");scanf("%s",&stu.warna);
printf("\n Volume Silinder(CC) : ");scanf("%s",&stu.cc);

printf("\n===============================");
printf("\nMAU EDIT DATA LAGI[Y/T]?");
fflush(stdin);
another=getchar();
}break;
case'4':
rewind(fp);
clrscr();
printf("\n=====================================");
printf("\n DAFTAR DATA ");
printf("\n=====================================");
while(fread(&stu,recsize,1,fp)==1)
{
printf("\n=====================================");
printf("\nDATA MOTOR ");
printf("\n=====================================");
cout<<"\nNama Pemilik : "<<stu.nama;
cout<<"\nAlamat Pemilik : "<<stu.alamat;
cout<<"\nMerek : "<<stu.merek;
cout<<"\nTahun Perakitan : "<<stu.th;
cout<<"\nWarna : "<<stu.warna;
cout<<"\nVolume Silinder(CC) : "<<stu.cc;

printf("\n=====================================");
}break;
case'5':
{
clrscr();

}
break;
}//switch(choice)
}//while(!(choice=='5'))
}
Previous Post
Next Post

2 komentar: