1. Cara Pertama
//Print Data KTP Dengan Bahasa C
#include <stdio.h>
main()
{
printf("\n\tCONTOH PEMROGRAMAN MENAMPILKAN DATA KTP\n\n");
printf("---------------------------------------------------\n");
printf("| %-17s | %-28s |\n",
"NIK", "320234979798989028061990");
printf("| %-17s | %-28s |\n",
"Nama", "Rahmat Hidayat");
printf("| %-17s | %-28s |\n",
"Tempat Tgl Lahir", "Bogor,28 Juni 1991");
printf("| %-17s | %-28s |\n",
"Jenis Kelamin", "Laki-Laki");
printf("| %-17s | %-28s |\n",
"Alamat", "Jl.Mawar1 Blok F35 No.17");
printf("|\t %-10s | %-28s |\n",
"RT/RW", "010/014");
printf("|\t %-10s | %-28s |\n",
"Desa/Kel", "DUREN JAYA");
printf("|\t %-10s | %-28s |\n",
"Kecamatan", "Bekasi Timur");
printf("| %-17s | %-28s |\n",
"Agama", "Islam");
printf("| %-17s | %-28s |\n",
"Pekerjaan", "Wiraswasta");
printf("| %-17s | %-28s |\n",
"Berlaku Hingga", "28-06-2019");
printf("| %-17s | %-28s |\n",
"Kewarganegaraan", "WNI");
printf("---------------------------------------------------\n");
fflush(stdin); getchar();
return 0;
}
2.Cara Kedua
#include<conio.h>
#include<iostream>
using namespace std;
typedef struct {
char nik[30];
char nama[30];
char alamat[30];
char status[30];
char pekerjaan[30];
char agama[30];
char goldarah[30];
}ktp;
ktp k;
ktp *t = &k;
void input(){
cout<<" * Input Data\n\n";
cout<<" Nik = ";cin.getline(k.nik,30);
cout<<" Nama = ";cin.getline(k.nama,30);
cout<<" Alamat = ";cin.getline(k.alamat,30);
cout<<" Status = ";cin.getline(k.status,30);
cout<<" Pekerjaan = ";cin.getline(k.pekerjaan,30);
cout<<" Agama = ";cin.getline(k.agama,30);
cout<<" Golongan Darah = ";cin.getline(k.goldarah,30);
cout<<"\n";
}
void cetak(){
cout<<" * Cetak Data\n\n";
cout<<" Nik = "<<k.nik,30;cout<<endl;
cout<<" Nama = "<<k.nama,30;cout<<endl;
cout<<" Alamat = "<<k.alamat,30;cout<<endl;
cout<<" Status = "<<k.status,30;cout<<endl;
cout<<" Pekerjaan = "<<k.pekerjaan,30;cout<<endl;
cout<<" Agama = "<<k.agama,30;cout<<endl;
cout<<" Golongan Darah = "<<k.goldarah,30;cout<<endl;
}
void edit(){
cout<<" * Edit Data\n\n";
cout<<" Nik = ";cin>>t->nik,30;
cout<<" Nama = ";cin>>t->nama,30;
cout<<" Alamat = ";cin>>t->alamat,30;
cout<<" Status = ";cin>>t->status,30;
cout<<" Pekerjaan = ";cin>>t->pekerjaan,30;
cout<<" Agama = ";cin>>t->agama,30;
cout<<" Golongan Darah = ";cin>>t->goldarah,30;
cout<<"\n";
}
void border(){
cout<<"--------------------------------\n";
cout<<" PROGRAM KTP\n";
cout<<"--------------------------------\n";
}
void thx(){
border();
cout<<"\n\n\n";
cout<<" Rahmat Hidayat\n";
cout<<"\n";
}
main (){
char yn;
border();
input();
border();
cetak();
cout<<"\n\n Ket: Hanya 1x edit";
cout<<"\n Anda ingin ubah data? [y/n] = ";cin>>yn;
switch (yn){
case 'y':
border();
edit();
border();
cetak();
getch();
thx();
break;
case 'n':
thx();
break;}}