C++ Program Simulation of BBM Purchase

Posted by Didi Setyapramana On 4:33 AM 0 komentar

#include <cstdlib>
#include <iostream>
using namespace std;
class SPBU{
friend ostream& operator<<(ostream&, const SPBU&);
friend istream& operator<<(istream&, SPBU&);
public:
void pilihan_liter();
void pilihan_uang();
void solar();
void premium();
void pertamax();
private:
int a,b,c;
int liter,uang;
int jumlah;
char p;
};
void SPBU::solar(){
a=4500;
cout<<"solar: "<<a<<endl;
cout<<"========================================="<<endl;
cout<<"+             Menu Pilihan              +"<<endl;
cout<<"========================================="<<endl;
cout<<"1. Satuan Liter"<<endl;
cout<<"2. Satuan uang"<<endl;
cout<<endl;
}
void SPBU::premium(){
b=4500;
cout<<"premium    : "<<b<<endl;
cout<<"========================================="<<endl;
cout<<"+             Menu Pilihan              +"<<endl;
cout<<"========================================="<<endl;
cout<<"1. Satuan Liter"<<endl;
cout<<"2. Satuan uang"<<endl;
cout<<endl;
}
void SPBU::pertamax(){
c=9000;
cout<<"pertamax    : "<<c<<endl;
cout<<"========================================="<<endl;
cout<<"+             Menu Pilihan              +"<<endl;
cout<<"========================================="<<endl;
cout<<"1. Satuan Liter"<<endl;
cout<<"2. Satuan uang"<<endl;
cout<<"masukkan jumlah liter: "<<endl;
cin>>liter;
jumlah=liter*9000;
cout<<"total yang harus di bayar: "<<jumlah;
cout<<endl;
}
void SPBU::pilihan_liter(){
cout<<"masukkan jumlah liter: ";
cin>>liter;
jumlah=liter*4500;
cout<<"total yang harus dibayar: Rp. "<<jumlah;
cout<<endl;
}
void SPBU::pilihan_uang(){
cout<<"masukkan jumlah uang: ";
cin>>uang;
jumlah=uang/4500;
cout<<"jumlah yang anda peroleh: "<<jumlah<<" liter ";
cout<<endl;
}
int main(){
SPBU X;
cout<<"================================================="<<endl;
cout<<"+          SELAMAT DATANG DI SPBU KAMI          +"<<endl;
cout<<"+                Daftar Harga BBM               +"<<endl;
cout<<"================================================="<<endl;
cout<<endl;
int p;
cout<<"Pilih jenis bbm yang anda inginkan: "<<endl;
cout<<endl;
cout<<"1. Solar"<<endl;
cout<<"2. Premium"<<endl;
cout<<"3. Pertamax"<<endl;
cout<<endl;
cin>>p;
switch(p){
case 1: X.solar();
cout<<endl;
cout<<"pilih: ";
cin>>p;
switch(p){
case 1:X.pilihan_liter();
break;
case 2:X.pilihan_uang();
break;
default: cout<<"pilihan anda salah";
break;
}
break;
case 2: X.premium();
cout<<"pilih : ";
cin>>p;
switch(p){
case 1:X.pilihan_liter();
break;
case 2:X.pilihan_uang();
break;
default: cout<<"pilihan anda salah";
break;
}
break;
case 3: X.pertamax();
cout<<"pilih : ";
cin>>p;
switch(p){
case 1:X.pilihan_liter();
break;
case 2:X.pilihan_uang();
break;
default: cout<<"pilihan anda salah";
break;
}
break;
default: cout<<"maaf pilihan yang anda masukkan salah";
}
cout<<endl<<endl;
system("PAUSE");
system("cls");
return main();
}

Categories:

0 Response for the "C++ Program Simulation of BBM Purchase"

Post a Comment