Tampilkan postingan dengan label bab 2. Tampilkan semua postingan
Tampilkan postingan dengan label bab 2. Tampilkan semua postingan

Sabtu, 09 April 2016

no 5

Program mengubah bilangan bulat menjadi scientific

#include <iostream>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
 double a,b,c;

   a = 12.3141592654;
   b = 2004.0;
   c = 1.23E1;
  
   cout.precision(4);
   cout<<a<<"\t"<<b<<"\t"<<c<<endl;
   cout<<fixed<<a<<"\t"<<b<<"\t"<<c<<endl;
   cout<<scientific<<a<<"\t"<<b<<"\t"<<c<<endl;

 return 0;
}

no 4

Program kalkulator sederhana

#include <iostream>
using namespace std;
class hitung{
    
public:
   void masukan();
   void proses();
   void keluaran();
 
private:
 float x,y,hasil1,hasil2,hasil3,hasil4;
   };
 
void hitung::masukan(){
   cout<<"\t\t --->>>MEREPRESENTASIKAN OPERASI-OPERASI<<<--- \n";
   cout<<"\n\t\t\t\t -->>ARITMATIKA<<--\n";
   cout<<"\nMasukkan Nilai Ke- 1 : ";cin>>x;
   cout<<"Masukkan Nilai ke- 2 : ";cin>>y;
   cout<<endl;
   }
 
void hitung::proses(){
 hasil1=x+y;
 hasil2=x-y;
 hasil3=x*y;
 hasil4=x/y;
   }
void hitung::keluaran(){
   cout<<"Hasil : "<<x<<" + "<<y<<"= "<<hasil1<<endl;
   cout<<"Hasil : "<<x<<" - "<<y<<"= "<<hasil2<<endl;
   cout<<"Hasil : "<<x<<" * "<<y<<"= "<<hasil3<<endl;
   cout<<"Hasil : "<<x<<" : "<<y<<"= "<<hasil4<<endl;
   }
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(){
   hitung bab2;
   char opsi;
   do{
   bab2.masukan();
   bab2.proses();
   bab2.keluaran();
   cout<<"\n\t-->>ULANGI LAGI y/n<<--\n";cin>>opsi;
   }
   while(opsi=='y');
   cout<<"\n\t--->>>TERIMAKASIH<<<---";
return 0;
}

no 3

Program membaca bilangan

#include <iostream>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
 void first (int n) {
 
  switch (n) {
  case 1: cout<<"Satu "; break;
  case 2: cout<<"Dua "; break;
  case 3: cout<<"Tiga "; break;
  case 4: cout<<"Empat "; break;
  case 5: cout<<"Lima "; break;
  case 6: cout<<"Enam "; break;
  case 7: cout<<"Tujuh "; break;
  case 8: cout<<"Delapan "; break;
  case 9: cout<<"Sembilan "; break;
  case 10: cout<<"Sepuluh "; break;
  case 11: cout<<"Sebelas "; break;
  default: break;
  }
  }
 
  void second (int n) {
  int bul, sisa;
  bul = n / 10;
  sisa = n % 10;
  if (bul == 0)
  first (sisa);
  else if (bul == 1) {
  if (sisa <= 1)
  first (n);
  else {
  first (sisa);
  cout<<"Belas ";
  }
  }
 
  else {
  first (bul);
  cout<<"Puluh ";
  first (sisa);
  }
  }
  void third (int n) {
  int bul, sisa;
  bul = n / 100;
  sisa = n % 100;
  if (bul == 0)
  second (sisa);
  else if (bul == 1) {
  if (sisa == 0)
  cout<<"Seratus ";
  else {
  cout<<"Seratus ";
  second (sisa);
  }
  }
  else {
  first (bul);
  cout<<"Ratus ";
  second (sisa);
  }
  }
 
  void fourth (int n) {
  int bul, sisa;
  bul = n / 1000;
  sisa = n % 1000;
  if (bul == 0)
  third (sisa);
  else if (bul == 1) {
  if (sisa == 0)
  cout<<"Seribu ";
  else {
  cout<<"Seribu ";
  third (sisa);
  }
  }
  else {
  third (bul);
  cout<<"Ribu ";
  third (sisa);
  }
  }
 
  void fifth (int n) {
  int bul, sisa;
  bul = n / 1000000;
  sisa = n % 1000000;
  if (bul == 0)
  fourth (sisa);
  else if (bul == 1) {
  if (sisa == 0)
  cout<<"Satu Juta ";
  else {
  cout<<"Satu juta ";
  fourth (sisa);
  }
  }
  else {
  third (bul);
  cout<<"Juta ";
  fourth (sisa);
  }
  }
 
int main(int argc, char** argv) { 
  int n = 1;
  while (n == 1) {
  int num1;
  do {
  cout<< "";
  cin>>num1;
  } while (num1<1);
  fifth (num1);
  cout<<"\n";
  }

 return 0;
}

no 2

Program menampilkan bilangan rasional

#include <iostream>
#include <conio.h>
using namespace std;
class bil{
       friend ostream& operator<<(ostream&, bil&);
      friend istream& operator>>(istream&, bil&);
   public:
    bil();
    
   private:
     int a,b;
      };
   bil::bil(){
       cout<<"----------------------------------------"<<endl;
      cout<<"Program Bilangan Rasional "<<endl;
      cout<<"-----------------------------------------"<<endl;
      }
   istream& operator>>(istream& in, bil& mlebu){
       cout<<"masukan Bilangan Ke 1 = ";
       in>>mlebu.a;
       cout<<"masukan Bilangan ke 2 = ";
       in>>mlebu.b;
      return in;
      }
   ostream& operator<<(ostream& out, bil& metu){
       cout<<"Keluaran = ";
       out<<metu.a<<" / "<<metu.b;;
      return out;
      }
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
   main(int argc, char** argv){
       bil x;
      cin>>x;
      cout<<x;
      getch();
   return 0;
   }

Jumat, 08 April 2016

no 1

Program menampilkan jam, menit, detik

#include <iostream>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
class Konversi{
      friend istream& operator>>(istream&, Konversi&);
      friend ostream& operator<<(ostream&, Konversi&);
public:
       Konversi(){};
       int j();
       int m();
       int d();
private:
        int jam;
        int menit;
        int detik;
        int sekon;
};
        int Konversi :: j(){
        jam=sekon/3600;
        return jam;
        }

        int Konversi :: m(){
        menit=(sekon-(3600*(sekon/3600)))/60;
        return menit;
        }

        int Konversi :: d(){
        detik=((sekon-(3600*(sekon/3600)))-(((sekon-(3600*(sekon/3600)))/60)*(60)));
        return detik;
        }

istream& operator>>(istream& in,Konversi& masukan){
         cout<<"\t\tPROGRAM KONVERSI DENGAN FORMAT : JAM.MENIT.DETIK"<<endl;
         cout<<endl;
         cout<<"Masukkan Waktu Dalam Detik : ";
         in>>masukan.sekon;
         cout<<endl;
         return in;
        }
ostream& operator<<(ostream& out,Konversi& keluaran){
        out<<keluaran.j()<<" Jam - ";
        out<<keluaran.m()<<" Menit - ";
        out<<keluaran.d()<<" Detik";
        return out;
        }
int main(int argc, char** argv) {
 Konversi X;
    cin>>X;
 cout<<X;
 cout<<endl;
 cout<<endl;

    system("PAUSE");
    system("cls");
 return 0;
}

Refleksi minggu ke 2

Refleksi Pertemuan ke 2 Assalamu'alaikum w. wb., Selamat berjumpa lagi teman-teman, baik saya disini akan menuliskan tentang refl...