contoh program c++ menggunakan struct

#include <conio>
#include <iostream>
main()
{
//pendeklarasian struct
struct mobil{
char no_mesin[8],no_rangka[20],no_plat[10];
float harga;
};

… struct pemesan {
char no_ktp[16],nama[20];
};

struct tanggal{
char dd[2],mm[2],yyyy[4];
};

struct pesan{
char no_pesan[10];
float tharga;
struct tanggal tglpsn;
struct mobil mbl[3];
struct pemesan pmsn;
};

struct pengembalian{
char no_kembali[10];
struct tanggal tglkembali;
struct pesan psn;
};

int n,m;
char pilih;
//inisialisasi main struct
struct pesan psn[10];
struct pengembalian kembali[10];

//proses input
cout<<“=============================”<<endl;
cout<<“SISTEM INFORMASI RENTAL MOBIL”<<endl;
cout<<“=============================”<<endl;
cout<<“masukan jumlah data pesan =”;cin>>n;
for (int i=1;i<=n;i++){
cout<<“Masukan Data !\n”;
cout<<“No Pesan :”;cin>>psn[i].no_pesan;
cout<<“Tanggal :”;cin>>psn[i].tglpsn.dd>>psn[i].tglpsn.mm>>psn[i].tglpsn.yyyy;
cout<<endl;
cout<<endl;
cout<<“masukan data pemesan !\n”;
cout<<“No KTP :”;cin>>psn[i].pmsn.no_ktp;
cout<<“nama :”;cin>>psn[i].pmsn.nama;

//proses input mobil
cout<<“masukan jumlah mobil yang disewa”;cin>>m;
for(int j=1;j<=m;j++){
cout<<“Pesan Mobil Ke- “<<j;
cout<<endl;
cout<<“no Mesin :”;cin>>psn[i].mbl[j].no_mesin;
cout<<“no rangka :”;cin>>psn[i].mbl[j].no_rangka;
cout<<“no plat :”;cin>>psn[i].mbl[j].no_plat;
cout<<“harga :”;cin>>psn[i].mbl[j].harga;
cout<<endl;}}
clrscr();
getch();
cout<<“ingin menampilkan harga (0/1)?”;cin>>pilih;

if (pilih==’1′)
//output
{for (int i=1;i<=n;i++){
cout<<“data Pesanan”<<endl;
cout<<“No Pesan :”<<psn[i].no_pesan<<endl;
cout<<“Tanggal :”<<psn[i].tglpsn.dd<<“-“<<psn[i].tglpsn.mm<<“-“<<psn[i].tglpsn.yyyy<<endl;
cout<<“data Pemesan”<<endl;
cout<<“No KTP :”<<psn[i].pmsn.no_ktp<<endl;
cout<<“Nama :”<<psn[i].pmsn.nama<<endl;
cout<<endl;

for(int j=1;j<=m;j++){
cout<<“NO Mesin No Rangka Plat Harga “<<endl;
cout<<psn[i].mbl[j].no_mesin<<psn[i].mbl[j].no_rangka<<psn[i].mbl[j].no_plat<<psn[i].mbl[j].harga;
}}}
else {cout<<“”;}

cout<<endl;
getch();
clrscr();

for(int i=1;i<=n;i++)
{
//pengembalian
cout<<“pengembalian mobil”<<endl;
cout<<“data Kembali”<<endl;
cout<<“No Pesan :”<<psn[i].no_pesan;
cout<<“Tanggal :”<<psn[i].tglpsn.dd<<“-“<<psn[i].tglpsn.mm<<“-“<<psn[i].tglpsn.yyyy<<endl;
cout<<“no Kembali :”;cin>>kembali[i].no_kembali;
cout<<“tanggal kembali :”;cin>>kembali[i].tglkembali.dd>>kembali[i].tglkembali.mm>>kembali[i].tglkembali.yyyy;

cout<<“mobil yang disewa”<<endl;
for(int j=1;j<=m;j++){
cout<<“NO Mesin No Rangka Plat Harga “<<endl;
cout<<psn[i].mbl[j].no_mesin<<psn[i].mbl[j].no_rangka<<psn[i].mbl[j].no_plat<<psn[i].mbl[j].harga;
}
}
cout<<endl;

cout<<“barang sudah dikembalikan”;

getch();
}

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s