Hai..
Kali ini saya akan berbagi mengenai tugas Algoritma & Pemrograman tentang Array Berdimensi
disini saya akan memberi contoh tentang :
program penyewaan hotel
langsung saja..
ini adalah screen shootnya
dan ini adalah source codenya menggunakan borland C++
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <iomanip.h>
main()
{
int x;
int banyak, lama[9],harga[9];
long total[9];
char nama [9][9],kode[9][9];
char type[9][9],kodenama[9][9];
long pendapatan=0;
clrscr();
cout<<"================================================================="<<endl;
cout<<" ADJIE's HOTEL "<<endl;
cout<<"================================================================="<<endl;
cout<<" Kode Nama Type Harga "<<endl;
cout<<"================================================================="<<endl;
cout<<" MLT Melati Reguler 100000 "<<endl;
cout<<" VIP 150000 "<<endl;
cout<<" MWR Mawar Reguler 130000 "<<endl;
cout<<" VIP 200000 "<<endl;
cout<<" BNG Bunga Reguler 150000 "<<endl;
cout<<" VIP 250000 "<<endl;
cout<<"================================================================="<<endl;
cout<<"Banyak Penyewa : ";cin>>banyak;
for(x=1;x<=banyak;x++)
{
cout<<"Penyewa Ke-"<<x<<endl;
cout<<" Input Nama Penyewa : ";cin>>nama[x];
cout<<" Input Lama Sewa : ";cin>>lama[x];
cout<<" Input Kode Kamar [MLT/MWR/BNG] : ";cin>>kode[x];
cout<<" Input Type Kamar [REGULER/VIP] : ";cin>>type[x];
if (strcmp(kode[x],"MLT")==0 || strcmp(kode[x],"mlt")==0)
{
strcpy(kodenama[x],"Melati");
if(strcmp(type[x],"Reguler")==0||strcmp(type[x],"reguler")==0)
{
harga[x]=100000;
}
else
{
harga[x]=150000;
}
}
else if (strcmp (kode[x],"MWR")==0 || strcmp(kode[x],"mwr")==0)
{
strcpy(kodenama[x],"Mawar");
if(strcmp(type[x],"Reguler")==0||strcmp(type[x],"reguler")==0)
{
harga[x]=130000;
}
else
{
harga[x]=200000;
}
}
else if (strcmp (kode[x],"BNG")==0 || strcmp(kode[x],"bng")==0)
{
strcpy(kodenama[x],"Bunga");
if(strcmp(type[x],"Reguler")==0||strcmp(type[x],"reguler")==0)
{
harga[x]=150000;
}
else
{
harga[x]=250000;
}
}
total[x]=harga[x]*lama[x];
}
cout<<"============================================================================"<<endl;
cout<<" ADJIE's HOTEL "<<endl;
cout<<"============================================================================"<<endl;
cout<<"No. Nama Kode Kamar Nama Kamar Type Kamar harga Kamar Lama Total "<<endl;
cout<<"============================================================================"<<endl;
for(x=1;x<=banyak;x++)
{
cout<<setiosflags(ios::left)<<setw(8)<<x;
cout<<setiosflags(ios::left)<<setw(12)<<nama[x];
cout<<setiosflags(ios::left)<<setw(12)<<kode[x];
cout<<setiosflags(ios::left)<<setw(12)<<kodenama[x];
cout<<setiosflags(ios::left)<<setw(10)<<type[x];
cout<<setiosflags(ios::left)<<setw(13)<<harga[x];
cout<<setiosflags(ios::left)<<setw(3)<<lama[x];
cout<<setiosflags(ios::left)<<setw(10)<<total[x]<<endl;
pendapatan=pendapatan+total[x];
}
cout<<"============================================================================"<<endl;
cout<<"Total Pendapatan ADJIE's Hotel : "<<pendapatan<<endl;
getch();
}
#include <stdio.h>
#include <iostream.h>
#include <iomanip.h>
main()
{
int x;
int banyak, lama[9],harga[9];
long total[9];
char nama [9][9],kode[9][9];
char type[9][9],kodenama[9][9];
long pendapatan=0;
clrscr();
cout<<"================================================================="<<endl;
cout<<" ADJIE's HOTEL "<<endl;
cout<<"================================================================="<<endl;
cout<<" Kode Nama Type Harga "<<endl;
cout<<"================================================================="<<endl;
cout<<" MLT Melati Reguler 100000 "<<endl;
cout<<" VIP 150000 "<<endl;
cout<<" MWR Mawar Reguler 130000 "<<endl;
cout<<" VIP 200000 "<<endl;
cout<<" BNG Bunga Reguler 150000 "<<endl;
cout<<" VIP 250000 "<<endl;
cout<<"================================================================="<<endl;
cout<<"Banyak Penyewa : ";cin>>banyak;
for(x=1;x<=banyak;x++)
{
cout<<"Penyewa Ke-"<<x<<endl;
cout<<" Input Nama Penyewa : ";cin>>nama[x];
cout<<" Input Lama Sewa : ";cin>>lama[x];
cout<<" Input Kode Kamar [MLT/MWR/BNG] : ";cin>>kode[x];
cout<<" Input Type Kamar [REGULER/VIP] : ";cin>>type[x];
if (strcmp(kode[x],"MLT")==0 || strcmp(kode[x],"mlt")==0)
{
strcpy(kodenama[x],"Melati");
if(strcmp(type[x],"Reguler")==0||strcmp(type[x],"reguler")==0)
{
harga[x]=100000;
}
else
{
harga[x]=150000;
}
}
else if (strcmp (kode[x],"MWR")==0 || strcmp(kode[x],"mwr")==0)
{
strcpy(kodenama[x],"Mawar");
if(strcmp(type[x],"Reguler")==0||strcmp(type[x],"reguler")==0)
{
harga[x]=130000;
}
else
{
harga[x]=200000;
}
}
else if (strcmp (kode[x],"BNG")==0 || strcmp(kode[x],"bng")==0)
{
strcpy(kodenama[x],"Bunga");
if(strcmp(type[x],"Reguler")==0||strcmp(type[x],"reguler")==0)
{
harga[x]=150000;
}
else
{
harga[x]=250000;
}
}
total[x]=harga[x]*lama[x];
}
cout<<"============================================================================"<<endl;
cout<<" ADJIE's HOTEL "<<endl;
cout<<"============================================================================"<<endl;
cout<<"No. Nama Kode Kamar Nama Kamar Type Kamar harga Kamar Lama Total "<<endl;
cout<<"============================================================================"<<endl;
for(x=1;x<=banyak;x++)
{
cout<<setiosflags(ios::left)<<setw(8)<<x;
cout<<setiosflags(ios::left)<<setw(12)<<nama[x];
cout<<setiosflags(ios::left)<<setw(12)<<kode[x];
cout<<setiosflags(ios::left)<<setw(12)<<kodenama[x];
cout<<setiosflags(ios::left)<<setw(10)<<type[x];
cout<<setiosflags(ios::left)<<setw(13)<<harga[x];
cout<<setiosflags(ios::left)<<setw(3)<<lama[x];
cout<<setiosflags(ios::left)<<setw(10)<<total[x]<<endl;
pendapatan=pendapatan+total[x];
}
cout<<"============================================================================"<<endl;
cout<<"Total Pendapatan ADJIE's Hotel : "<<pendapatan<<endl;
getch();
}
Semoga Bermanfaat
-AK-