ertemuan

Jumat, 08 April 2016

Bab 2

1.        

#include <iostream>
#include <conio.h>

using namespace std;
class waktu{
       friend ostream& operator<<(ostream&, waktu&);
      friend istream& operator>>(istream&, waktu&);
   public:
    waktu();
      void jam(){ja=de/3600; sisa=de%3600;}
      void menit(){me=sisa/60; sisa2=sisa%60; }
      void detik(){de=sisa2;}
   private:
                                int ja,me;
                    int de,sisa,sisa2;
      };
   waktu::waktu(){
       cout<<"----------------------------------------"<<endl;
      cout<<"Program Menampilkan Jam "<<endl;
      cout<<"-----------------------------------------"<<endl;
      }
   istream& operator>>(istream& in, waktu& mlebu){
       cout<<"masukan Detik = ";
       in>>mlebu.de;
      return in;
      }
   ostream& operator<<(ostream& out, waktu& metu){
       cout<<"Keluaran = ";
       out<<metu.ja<<" : "<<metu.me<<" : "<<metu.de;
      return out;
      }
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

   main(int argc, char** argv){
       waktu x;
      cin>>x;
      x.jam();
      x.menit();
      x.detik();
      cout<<x;
      getch();
   return 0;
}

2.        

#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;
   }

3.        

#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;
}

4.        

#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;
}

5.        

#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;
}

Tidak ada komentar:

Posting Komentar