Minggu, 03 April 2011

Fuel Programming

This program is about to find out how much that you must pay or how many liter when you buy some fuel.
The simply explanation about this program is about choose the option. Then named the function like in step 8 to 11. In private you must declared the data types and the variables that you want (step 13 and 14). Closing the pombensin class with }; like in step 15.
In step 17, the statement that must choosing is in here. Its explaned about which one that user must be choose.
In step 25 if else statement is occurred. Its about which one that must choose, in liter or rupiah?
Then if user choose in liter, go to all of step 31 but if in rupiah then go to all of step  40. Finally result is depend on step 51 in int main.


1 #include <cstdlib>
2 #include <iostream>
3
4 using namespace std;
5
6 class pombensin{
7 public:
8 void awal();
9 void proses();
10 void liter();
11 void rupiah();
12 private:
13 int pilih;
14 double masukan,keluaran;
15 };
16
17 void pombensin::awal(){
18 cout<<”Pilihan anda :\n”;
19 cout<<”1. LITER\n”;
20 cout<<”2. RUPIAH\n”;
21 cin>>pilih;
22 proses();
23 }
24
25 void pombensin::proses(){
26 if(pilih==1){system(“cls”);liter();}
27 else if(pilih==2){system(“cls”);rupiah();}
28 else{cout<<”Pilihan tidak ada,!\n”;}
29 }
30
31 void pombensin::liter(){
32 cout<<”\n\nLITER\n\n”;
33 cout<<”Mau beli berapa liter,?\n”;
34 cout<<”-> “;
35 cin>>masukan;
36 keluaran=masukan*4500;
37 cout<<”Uang yang harus dibayar : “<<keluaran<<” rupiah”<<endl;
38 }
39
40 void pombensin::rupiah(){
41 cout<<”\n\nRUPIAH\n\n”;
42 cout<<”Mau beli berapa rupiah,?\n”;
43 cout<<”-> “;
44 cin>>masukan;
45 keluaran=masukan/4500;
46 cout<<”Anda membeli bensin : “<<keluaran<<” liter”<<endl;
47 }
48
49 int main(int argc, char *argv[])
50 {
51 pombensin pastipas;
52 pastipas.awal();
53
54 system(“PAUSE”);
55 return EXIT_SUCCESS;
56 }
Such a simple program, isn’t it? You can try in your stuff…..:))

Tidak ada komentar:

Posting Komentar