type="text/javascript">

Minggu, 30 Maret 2014

Memasuki menu ATM dengan C++

 #Program C++ nya :

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int username,password;
    int a;
    cout<<"WELCOME IN ATM"<<endl;
    cout<<endl;
    int user = 0000;
    int pass = 1234;
   
    a=1;
    do{
        cout<<"Masukka Username Anda = ";cin>>username;
        cout<<"Masukkan Password Anda = ";cin>>password;
        if (username==user&&password==pass){
                                        cout<<"Anda masuk di ATM"<<endl;
                                        }else{
                                              cout<<"Username dan Password yang anda masukkan salah, silahkan coba lagi"<<endl;
                                              a=a+1;
                                              }}
        while (a<=3);
        cout<<"ATM ANDA TERBLOKIR !!! Segera Hubungi Customer Service !!!"<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}


Menghitung Nilai dari Deret 1-(1/2)+(1/3)-(1/4)+...+(1/n)

Program c++ nya :
#include <cstdlib>
#include <iostream>

using namespace std;

class hitung
{
public:
       void input();
       int proses();
private:
        int n;
        float rumus,jumlah,total;
        };

void hitung::input(){
cin>>n;
cout<<endl;}

int hitung::proses(){
jumlah=0;
total=0;
rumus=-1;
for(int j=1; j<=n; j++){
rumus=(rumus*(-1));
total=rumus/j;
jumlah+=total;
if(j==1)
cout<<"("<<total<<")";
if(j>1)
cout<<"+("<<total<<")";
}

cout<<endl<<endl<<"hasil penjumlahan deret = "<<jumlah;
return jumlah;
}

int main(int argc, char *argv[])
{
    cout<<"menghitung jumlah dari rumus 1-(1/2)+(1/3)-(1/4)+...+(1/n)"<<endl<<endl;
    cout<<"Masukkan niali : ";
    hitung deret;
    deret.input();
    deret.proses();
   
    system("PAUSE");
    return EXIT_SUCCESS;
}
 

 #screenshot :




 #hasil :
 

Mencetak Bilangan dari 1 sampai 4



Sabtu, 29 Maret 2014

Menghitung bilangan ke cm dan inci

1. Analisis
     Menghitung bilangan ke cm dan inci
2. Identifikasi
       Input     : a
       Output   : cm dan inci
3. Algoritmanya
      Deklarasi
                a,cm, inci
      Deskripsinya     :
 cm = a*100
 inci = a*100/2.54

Menghitung hasil kali dari 2 bilangan bulat

1. Analisisnya
     Menghitung hasil kali dari 2 buah bilangan
2. Identifikasi
       Input     : a, b
       Output   : Hasil
3. Algoritmanya
      Deklarasi
               int a, b, kali
      Deskripsinya     :
  Hasil = a*b
 

 

Menjumlahkan 3 bilangan bulat

1. Analisis
     Menjumlahkan 3 bilangan bulat
2. Identifikasi
       Input     : a, b,c
       Output   :hashil jumlah
3. Algoritmanya
      Deklarasi
               int a,b,c,jumlah
      Deskripsinya     :
 jumlah = a+b+c
 
 
 

 
 

5.11 Figure 5.23 Program to draw a moving ball



5.11 Figure 5.22 Program to draw a quilt #include


5.9 Figure 5.19 Finding a Function Root Using the Bisection Method


5.9 Figure 5.16 Using a Function Parameter


5.7 Figure 5.12 Program to Process Bald Eagle Sightings for a Year

Program c++ nya :
 
#include <cstdlib>
#include <iostream>
#define SENTINEL 0
#define NUM_MONTHS 12

using namespace std;

int main(int argc, char *argv[])
{
    int m, mem_sight,sightings;
   
    cout<<"BALD EAGLE SIGHTINGS"<<endl;
    cout<<endl;
    for(m=1;m<=NUM_MONTHS;m++){
    sightings=0;
    cin>>mem_sight;
    while(mem_sight != SENTINEL){
                   if(mem_sight>=0)
                   sightings+= mem_sight;
                   else
                   cout<<"Warning negative count ingores"<<mem_sight<<endl;
                   }
                   cout<<"month = "<<m<<sightings;
                   }
    system("PAUSE");
    return EXIT_SUCCESS;
}


screenshot :


5.8 Figure 5.14 Validating Input Using do-while Statement


5.7 Figure 5.13 Nested Counting Loop Program

Program c++ nya :
 
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int a, b;
    cout<<"a\tb"<<endl;
    cout<<endl;
   
    for(a=1;a<4;++a){
        cout<<"Outer   "<<a<<endl;
    for(b=0;b<a;++b){
        cout<<"Inner   "<<b<<endl;
        }
        }
       
    system("PAUSE");
    return EXIT_SUCCESS;
}

#screenshot :
 

Menentukan bilangan terbesar dari 2 bilangan

Program c++ nya :

 #include <iostream>
#include <string>

using namespace std;
int main()
{
   string raptor_prompt_variable_zzyz;
   int b, a;

   raptor_prompt_variable_zzyz ="Masukkan angka pertama = ";
   cout << raptor_prompt_variable_zzyz << endl;
   cin >> a;
   raptor_prompt_variable_zzyz ="Masukkan angka kedua = ";
   cout << raptor_prompt_variable_zzyz << endl;
   cin >> b;
   if (a>b)
   {
      cout << "Nilai"<<a<<"   lebih besar dari pada nilai "<<b << endl;   }
   else
   {
      cout << "Nilai  "<<a<<"lebih kecil dari pada nilai  "<<b << endl;   }

   system("PAUSE");
    return EXIT_SUCCESS;
}

#screenshot c++ :




#screenshot raptor  :


5.6 Figure 5.10 Sentinel-Controlled while Loop

Program c++ nya :

#include <cstdlib>
#include <iostream>
#define sentinel -44

using namespace std;

int main(int argc, char *argv[])
{
    int sum=0,score;
   
    cout<<"Enter first score ( or "<<sentinel<<"to quit)>";
    cin>>score;
    while (score !=sentinel){
          sum += score;
          cout<<"enter next score("<<sentinel<<"to quit)>";
          cin>>score;
          }
          cout<<"Sum of exam score is "<<sum<<endl;
         
    system("PAUSE");
    return EXIT_SUCCESS;
}

#Screenshotnya :
 



5.5 Figure 5.9 Program to Monitor Gasoline Storage Tank

 Program c++ nya :

#include <cstdlib>
#include <iostream>
#define capacity 80000.0
#define min_pct 10
#define gals_per_brl 42.0

double monitor_gas(double min_supplay,double start_supply);

using namespace std;


int main(void)
{
    double start_supply, min_supply, current;
    min_supply = min_pct/100.0*capacity;
    cout<<"Number of barrels currently in tank = ";
    cin>>start_supply;

    current = monitor_gas(min_supply,start_supply);
    cout<<"only barrels are left."<<current<<endl<<endl;
    cout<<"*** WARNING ***"<<endl;
    cout<<"Available supply is less than percent of"<<min_pct<<"tank's "<<endl;
    cout<<capacity<<"barrel capacity."<<endl;



    system("PAUSE");
    return EXIT_SUCCESS;
}

double monitor_gas(double min_supply, double start_supply)
{
       double remov_gals, remov_brls,current;
              for (current = start_supply; current >= min_supply; current -= remov_brls){
                  cout<<"barrels are available."<<current<<endl<<endl;
                  cout<<"Enter number of gallons removed> ";
                  cin>>remov_gals;
                  remov_brls = remov_gals/gals_per_brl;
              
                  cout<<"After removal of"<<remov_gals<<" gallone {"<<remov_brls<<" barrels)"<<endl;
                  }
                 return (current);
                 }
   

#Screenshot :
 
 

Hasil :