Algoritma Pom Bensin {mencetak harga & liter dalam penjualan pom bensin} |
Deklarasi jum, jum1 : integer rp, ltr, litlit, : float wait : void |
Deskripsi float b -> 1/2; cout <- b; |
Listing
#include <cstdlib> |
#include <iostream> |
#include <time.h> |
#include <math.h> |
#include <iomanip> |
using namespace std; |
class SPBU{ |
private: |
float rp; |
float ltr; |
int jum; |
float litlit; |
int jum1; |
float bensin,bensin2,bensin3,bensin4; |
public: |
float menu(); |
float liter(); |
void rupiah(); |
double ulang(); |
void wait (float seconds); |
}; |
float SPBU::menu(){ |
char pil; |
cout<<"\b"; |
cout<<"\a\t\t+\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\5\5\5\5\5\5\5\5+\n"; |
cout<<"\t\t\3 \3\n"; |
cout<<"\t\t\3 SELAMAT DATANG DI POM BENSIN PASTI PAS BANGET \3\n"; |
cout<<"\t\t\3 \3\n"; |
cout<<"\t\t+\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\5\5\5\5\5\5\5\5\5+\n"; |
cout << "\t\t +-----------------------------------+" << endl; |
cout << "\t\t | MENU |" << endl; |
cout << "\t\t +-----------------------------------+" << endl << endl; |
cout<<"\t\t\t\tSilahkan Pilih: \n"; |
cout<<"\t\t\t\t1. Rupiah"<<endl; |
cout<<"\t\t\t\t2. Liter"<<endl; |
cout<<"\t\t\t\t3. Exit"<<endl; |
cout<<"\t\t\t\t=================="<<endl; |
cout<<"\t\t\t\tMasukkan Pilihan: ";cin>>pil; |
pil=toupper(pil); |
while(!((pil=='1')||(pil=='2')||(pil=='3'))){ |
cout<<"Pilian SALAH\nPilihan diluar jangkauan..!\nPilih nomor 1-3\n"; |
cout<<"Pilih salah satu:";cin>>pil; |
pil=toupper(pil); |
} |
switch(pil){ |
case '1': rupiah(); break; |
case '2': liter(); break; |
case '3': cout<<"Terima Kasih\n"; system("exit"); break; |
default: cout<<"Terimakasih"<<endl; |
} |
} |
float SPBU::liter(){ |
system("CLS"); |
cout << "\a\t\t\t+-----------------------------------+" << endl; |
cout << "\t\t\t| PILIHAN LITER |" << endl; |
cout << "\t\t\t+-----------------------------------+" << endl << endl; |
bensin=4500; |
bensin3=1; |
bensin4=bensin3/bensin; |
cout<<"Liter: ";cin>>ltr; |
jum1=ltr*4500; |
cout<<"Harga: "<<jum1; |
for (int n=0; n<=jum1; n++) { |
cout <<system("CLS") ; |
cout<<"\b"<<"Beli : Rp."<<jum1<<"\nHarga: Rp."<<n<<endl; |
bensin2=bensin4*n; |
cout<<"Liter: "<<setprecision(3)<<fixed<<bensin2<<endl; |
wait (0.1); |
if(n==jum1){goto step1;} |
} |
step1: |
cout<<"\n=================\n"; |
cout<<"\a\aHarga: Rp."<<jum1<<endl; |
cout<<"Liter: "<<ltr<<" Liter"<<endl; |
ulang(); |
} |
void SPBU::rupiah(){ |
system("CLS"); |
cout << "\a\t\t\t+-----------------------------------+" << endl; |
cout << "\t\t\t\t| PILIHAN RUPIAH |" << endl; |
cout << "\t\t\t\t+-----------------------------------+" << endl << endl; |
bensin=4500; |
bensin3=1; |
bensin4=bensin3/bensin; |
cout<<"Rupiah: ";cin>>rp; |
litlit=rp/4500; |
jum=litlit*4500; |
cout<<"Liter: "<<jum; |
for (int n=0; n<=jum; n++) { |
cout <<system("CLS") ; |
cout<<"\b"<<"Harga: "<<n<<"\nBeli : Rp."<<jum<<endl; |
bensin2=bensin4*n; |
cout<<"Liter: "<<setprecision(3)<<fixed<<bensin2<<endl; |
wait (0.1); |
if(n==jum){goto step1;} |
} |
step1: |
cout<<"\n=================\n"; |
cout<<"\a\aHarga: Rp. "<<int(rp)<<endl; |
cout<<"Liter: "<<bensin2<<" Liter"<<endl; |
ulang(); |
} |
double SPBU::ulang(){ |
char aa; |
cout<<"\n\n\nApakah anda ingin mengulang ? (y/n) : ";cin>>aa; |
aa=toupper(aa); |
while(!((aa=='Y')||(aa=='y')||(aa=='n')||(aa=='N'))){ |
cout<<"\aPilihan tidak tersedia, ulangi, Pilih (Y)es/(N)o "<<endl; |
cout<<"\ahitung lagi/keluar?<Y/N> ";cin>>aa; |
aa=toupper(aa);} |
switch(aa){ |
case 'Y': system("cls");return menu(); break; |
case 'N': cout << "\a\a\a\a\t\t\t+-----------------------------------+" << endl; |
cout << "\t\t\t\| TERIMAKASIH ATAS KUNJUNGAN ANDA |" << endl; |
cout << "\t\t\t\+-----------------------------------+" << endl ; |
cout<<"\t\t\t Kepuasan anda adalah kebahagian kami\n"; |
cout<<" \t\t\t \1 \1 \1 \1 \1 \1 \1 \1 \1 \1\n\n" << endl; |
system("PAUSE");return EXIT_SUCCESS;break; |
} |
} |
void SPBU::wait ( float seconds ){ |
clock_t endwait; |
endwait = clock () + seconds * CLOCKS_PER_SEC ; |
while (clock() < endwait) {} |
} |
int main(){ |
float b=1/2; |
cout<<b; |
SPBU x; |
x.menu(); |
} |
Tidak ada komentar:
Posting Komentar