Minggu, 24 April 2011

#include<conio.h>
#include<iostream.h>
void main()
{
  double tot_beli, pot=0, jum_bayar=0;
  cout<<"Total Pembelian Rp. ";
  cin>>tot_beli;
  if (tot_beli >= 10000)
  pot = 0.2 * tot_beli;
  cout<<"Besarnya Potongan Rp. "<<pot<<endl;
  jum_bayar = tot_beli - pot;
  cout<<"Jumlah yang harus dibayarkan Rp. ";
  cout<<jum_bayar;
  getch();
  }
#include <cstdlib>
#include <iostream>

using namespace std;

class hitung
{
     
public:
       int proses();
       void input();

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 << " Jumlah Rekursif = " << jumlah;
cout << endl;

return jumlah;
}

int main(int argc, char *argv[])
{
    cout << " Program Menghitung Jumlah dari Rumus 1-(1/2)+(1/3)-(1/4)+...+(1/n) ";
    cout << endl;
    cout << endl;
    cout << " Masukkan Nilai n : ";
   
    hitung deret;
    deret.input();
    deret.proses();
   
    system("PAUSE");
    return EXIT_SUCCESS;
}
#include<iostream.h>
#include<conio.h>
    class FPB{
       friend ostream& operator<<(ostream&,FPB&);
      friend istream& operator>>(istream&,FPB&);
   public:
       FPB();
      void hitung_fpb(){
                  r=a%b;
                    while (r !=0)
                    {
                    a=b;
                    b=r;
                    r=a%b;
                    }
               ;}
   private:
       int a,b,r;
      };
   FPB::FPB(){
     
      }
   istream& operator>>(istream& in,FPB& mlebu){
       cout<<"masukan angka A : ";
      in>>mlebu.a;
      cout<<"masukan angka B : ";
      in>>mlebu.b;
      return in;
      }
   ostream& operator<<(ostream& out,FPB& metu){
       cout<<"FPB dari bilangan A dan B adalah : ";
      out<<metu.b;
       return out;
      }
   main(){
       FPB z;
      cin>>z;
      z.hitung_fpb();
      cout<<z;
      getch();
      return 0;
      }
 #include <iostream.h>
#include <conio.h>

int main(){
  int jmlahhari[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int bulan, tahun, jhari;
 
  clrscr();
  cout<<"masukkan bulan <1...12> : " ;
  cin>>bulan;
  cout<<"masukkan tahunnya : ";
  cin>>tahun;
 
  if(bulan==2)
  if((tahun%4 == 0)&&(tahun%100!=0))
  jhari=29;
  else
  jhari=28;
  else
  jhari=jmlahhari[bulan-1];
 
  cout<<" jumlah hari pada ";
  cout<<"bulan :"<<bulan;
  cout<<", tahun :"<<tahun;
  cout<<", adalah :"<<jhari<<endl;
  getch();
  return 0;
}