Wenn Aussagen in C + + Programm

Posted by Didi Setyapramana On 3:26 AM 0 komentar

WENN aussagen

WENN aussagen in verwenden, um auf der grundlage Entscheidungen Bedingung.Form of this Aussage Machen Konnen GIBT ES Zwei Arterielle:

• WENN Nur und

• sonst.

  in beiden Formen of this Aussage. Bedingungen verwendet Werden, um Zustand ungkapan.ungkapan ausdruck verwenden Konnen Wie Operatoren Relation == melibatakan Operatoren Oder Logische Oder Wie & & | |.
Einfache if-Anweisung
Statement, WENN einfachsten der Form:
Wenn (Bedingung)
Statement;
Zustand der verwendet WIRD, um zu bestimmen Entscheidungsprozesse
Die erklärung Kann Darin Eine erklärung oder zusammengesetzte Anweisung.
§ wenn WIRD Nur ausgeführt, sterben Bedingung Wahr (Nicht Wahr-Wert Gleich Null).

C + + immer behandeln wird der Wert nicht gleich Null ist, als die wahre und falsche Werte gleich Null.
Daher Bentu ich wie folgt:


If(bil % 2 !=0)

Cout<<”noch”<<endl;

Mai wie folgt geschrieben werden:

If(bil % 2)

Cout<<”noch”<<endl;

Application (if) zum Beispiel, eine Person bestimmen, wissen vielleicht nicht, das Kino die Show anzusehen.

Bedingungen verwendet werden, kann man die Show, wenn es 17 Jahre alt ist.
Schreiben Sie das Programm sind wie folgt:

Programm Entscheidungen mit if-Anweisungen
#include <iostream.h>
# Include <conio.h>
using namespace std;
int main ()
{
int Alter;
cout <<"Wie alt bist du?";
cin>> Alter;
if (alter <17)
cout <<"Sie sind nicht berechtigt, beobachten Sie die" <<endl;
}
Es scheint, dass, wenn die enthaltenen Alter größer oder gleich 17, das Programm nicht liefern nichts.
Wenn die Anweisung nach der Anweisung in der Form einer Verbindung, Form Dalah wie folgt:
Wenn (Bedingung)
{
Statement_1;

Statement_2;
...
Statement_3;
}
}



Achten Sie darauf, schriftlich einen solchen Vergleich die folgenden Bedingungen:

If (Ausdruck == value)

Statement;

Fehler, die häufig vorkommen, dass das Zeichen = nur einmal geschrieben ist, folgt Sperti:

If (Ausdruck = value)

Statement;

Für bedeutet = sign (einteilig) die Zuweisung von Werten, nicht-Vergleich


Least Common Multiple (LCM) in Jeliot

Posted by Didi Setyapramana On 6:34 PM 0 komentar

import jeliot.io.*;

public class kpk {
  
         
      
          int a,b,nilai;


          public void masukan() { 
          System.out.print("Menghitung KPK"); 
          
          nilai=0;
           System.out.print("Masukkan A: "); a=Input.readInt();
          System.out.print("Masukkan B: "); b=Input.readInt();
          for (int z=1; z<=b; z++) {
          nilai=nilai+a;
          if (nilai%b==0) {
          System.out.print("KPK dari ");
          System.out.print(a);
        System.out.print(" dan ");
         System.out.print(b);
          System.out.print(" adalah ");
          System.out.print(nilai);
       

          }
          }
    }

          public static void main () {
          kpk X = new kpk();  
         X.masukan();

          }

}

Jeliot Bank Account

Posted by Didi Setyapramana On 6:20 PM 0 komentar

//This example shows the possible use
//of Scanner methods, and basic object
//oriented features.
import java.util.Scanner;

//This class defines a basic bank account
class BankAccount{
  String ownerName;
  long accountID;
  double balance;

  //Default constructor that asks for missing information
  BankAccount(){
    Scanner read = new Scanner(System.in);
    this.ownerName = read.next();
    this.accountID = read.nextLong();
    this.balance = read.nextDouble(); 
  }
  //Constructor with parameters
  BankAccount(String name, long accountID, double balance){
    this.ownerName = name;
    this.accountID = accountID;
    this.balance = balance; 
  }
  //Deposit adds an amount to the balance
  public void deposit(double amount){
     this.balance += amount;
  }
  //Withdraw an amount to the balance, 
  //and returns a boolean indicating
  //the success of the operation  
  public boolean withdraw(double amount){
     boolean withdrawn = false;
     if (balance > amount){
       balance -= amount;
       withdrawn = true;
       System.out.println("Amount withdrew succesfully");
    } else {
       System.out.println("Not enough funds");
    }
    return withdrawn;
  }
}


public class MyClass {
  public static void main() {
    Scanner read = new Scanner(System.in);
    String name = read.next();
    long accountID = read.nextLong();
    double initialDeposit = read.nextDouble(); 
    BankAccount ba = new BankAccount(
            name, accountID, initialDeposit); 
    ba.withdraw(read.nextDouble());
  }
    
}

Greet Common Divisor C++

Posted by Didi Setyapramana On 6:22 AM 0 komentar

#include <cstdlib>
#include <iostream>
using namespace std;

class hitung_Gcd {
public :
     int gcd_iteratif(int c, int d);
     int gcd(int c, int d);       
private:
     int bil1, bil2;
     int hasil;      
};                     

int hitung_Gcd::gcd_iteratif(int c, int d)
{   int r;
    while (d > 0) {
    r = c % d;  
    c = d; 
    d = r;   
    }
    return (c);
}

int hitung_Gcd::gcd(int c, int d)
{   
    if (d==0) return(c);
    if (c<d) return(gcd(d,c));
    return(gcd(c-d, d));    
}

int main(int argc, char *argv[])
{
    hitung_Gcd X;
    int a = 20, b = 10;
    cout << "Gcd (iteratif) dari : " << X.gcd_iteratif(a,b) << endl;
    cout << "Gcd (rekursi) dari : " << X.gcd(a,b) << endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

Invers Matrix Program

Posted by Didi Setyapramana On 4:59 AM 2 komentar

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int n,i,j,k,l;
float a[20][20];
cout <<"Program Pencarian Invers Matriks"<<endl;
cout <<endl<<"Masukkan ordo matriks (n x n)"<<endl;
cout <<"n : ";
cin >>n;
cout <<endl;
for (i=1;i<=n;i++){
    for (j=1;j<=n;j++){
        cout <<"A("<<i<<","<<j<<") : ";
        cin >>a[i][j];
        }
    }
cout <<endl;
for (i=1;i<=n;i++){
    for (j=1;j<=n;j++)
        cout <<"    "<<a[i][j];
    cout <<endl;
    }

//Matriks sisi kanan
for (j=n+1;j<=n+n;j++){
    i=j-n;
    a[i][j]=1;
    }
for (j=n+1;j<=n+n;j++){
    for (i=1;i<=n;i++)
        if (i!=(j-n)) a[i][j]=0;
    }

//Proses penginversan
for (i=1;i<=n;i++){
    for (j=1;j<=n+n;j++){
        if (i!=j) a[i][j]=a[i][j]/a[i][i];
        }
    for (j=1;j<=n+n;j++){
        if (i==j) a[i][j]=1;
        }

    //Penjumlahan kesatu baris element
    for (l=1;l<=n;l++){
        if (i!=l) {
            for (j=i+1;j<=n+n;j++){
                a[l][j]=a[l][j]-(a[i][j]*a[l][i]);
                }
            }
        }

    //Pembuat nol disekitar matriks kiri
    for (k=1;k<=n;k++){
        if (i!=k) {
            a[k][i]=0;
            }
        }
    }

//Pencetakan
cout <<"Maka invers dari matriks adalah : "<<endl;
cout.precision(4);
cout.setf(ios::fixed);
for (i=1;i<=n;i++){
    for (j=n+1;j<=n+n;j++)
        cout <<"    "<<a[i][j];
        cout <<endl;
    }

    system("PAUSE");
    return EXIT_SUCCESS;
}

Transpose Matrix Program

Posted by Didi Setyapramana On 4:54 AM 0 komentar

Algoritma dengan pseuducode
1.    Masukkan ordo matrik(n)
2.    Input matrik di dalam array [0][0] sampai dengan array[n][n]
3.    ditampilkan matrik tersebut
4.    menukar matrik[i][j] menjadi matrik[j][i]
5.    ditampilkan hasil matrik tranpose


Deklarasi :

a[10][10]    : int
m,n,i,j        : int


Deskripsi :
Baca (m)
Baca (n)
for(i=0;i<m;i++)
        {
        for(j=0;j<n;j++)
        {
Tulis a[i][j]
Transpose :

for(i=0;i<m;i++)
    {
    for(j=0;j<n;j++)
    {
Transpose a[j][i]



Implementasi dalam bahasa C++

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
   
    int a[10][10],m,n,i,j;
    cout<<"Masukkan Jumlah Baris: ";
    cin>>m;
    cout<<"Masukkan Jumlah kolom: ";
    cin>>n;
   
    
    cout<<endl<<"Enter elements of matrix: "<<endl;
    for(i=0;i<m;i++)
    {
    for(j=0;j<n;j++)
    {
    cout<<"Enter element a"<<i+1<<j+1<<": ";
    cin>>a[i][j];
    }
    }
    cout<<endl<<"Matriks: "<<endl<<endl;
    for(i=0;i<m;i++)
    {
    for(j=0;j<n;j++)
    {
    cout<<a[i][j]<<" ";
    }
    cout<<endl<<endl;
    }
    cout<<endl<<"Transpose Matriks: "<<endl<<endl;
    for(i=0;i<m;i++)
    {
    for(j=0;j<n;j++)
    {
    cout<<a[j][i]<<" ";
    }
    cout<<endl<<endl;
    }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

C++ Program Simulation of BBM Purchase

Posted by Didi Setyapramana On 4:33 AM 0 komentar

#include <cstdlib>
#include <iostream>
using namespace std;
class SPBU{
friend ostream& operator<<(ostream&, const SPBU&);
friend istream& operator<<(istream&, SPBU&);
public:
void pilihan_liter();
void pilihan_uang();
void solar();
void premium();
void pertamax();
private:
int a,b,c;
int liter,uang;
int jumlah;
char p;
};
void SPBU::solar(){
a=4500;
cout<<"solar: "<<a<<endl;
cout<<"========================================="<<endl;
cout<<"+             Menu Pilihan              +"<<endl;
cout<<"========================================="<<endl;
cout<<"1. Satuan Liter"<<endl;
cout<<"2. Satuan uang"<<endl;
cout<<endl;
}
void SPBU::premium(){
b=4500;
cout<<"premium    : "<<b<<endl;
cout<<"========================================="<<endl;
cout<<"+             Menu Pilihan              +"<<endl;
cout<<"========================================="<<endl;
cout<<"1. Satuan Liter"<<endl;
cout<<"2. Satuan uang"<<endl;
cout<<endl;
}
void SPBU::pertamax(){
c=9000;
cout<<"pertamax    : "<<c<<endl;
cout<<"========================================="<<endl;
cout<<"+             Menu Pilihan              +"<<endl;
cout<<"========================================="<<endl;
cout<<"1. Satuan Liter"<<endl;
cout<<"2. Satuan uang"<<endl;
cout<<"masukkan jumlah liter: "<<endl;
cin>>liter;
jumlah=liter*9000;
cout<<"total yang harus di bayar: "<<jumlah;
cout<<endl;
}
void SPBU::pilihan_liter(){
cout<<"masukkan jumlah liter: ";
cin>>liter;
jumlah=liter*4500;
cout<<"total yang harus dibayar: Rp. "<<jumlah;
cout<<endl;
}
void SPBU::pilihan_uang(){
cout<<"masukkan jumlah uang: ";
cin>>uang;
jumlah=uang/4500;
cout<<"jumlah yang anda peroleh: "<<jumlah<<" liter ";
cout<<endl;
}
int main(){
SPBU X;
cout<<"================================================="<<endl;
cout<<"+          SELAMAT DATANG DI SPBU KAMI          +"<<endl;
cout<<"+                Daftar Harga BBM               +"<<endl;
cout<<"================================================="<<endl;
cout<<endl;
int p;
cout<<"Pilih jenis bbm yang anda inginkan: "<<endl;
cout<<endl;
cout<<"1. Solar"<<endl;
cout<<"2. Premium"<<endl;
cout<<"3. Pertamax"<<endl;
cout<<endl;
cin>>p;
switch(p){
case 1: X.solar();
cout<<endl;
cout<<"pilih: ";
cin>>p;
switch(p){
case 1:X.pilihan_liter();
break;
case 2:X.pilihan_uang();
break;
default: cout<<"pilihan anda salah";
break;
}
break;
case 2: X.premium();
cout<<"pilih : ";
cin>>p;
switch(p){
case 1:X.pilihan_liter();
break;
case 2:X.pilihan_uang();
break;
default: cout<<"pilihan anda salah";
break;
}
break;
case 3: X.pertamax();
cout<<"pilih : ";
cin>>p;
switch(p){
case 1:X.pilihan_liter();
break;
case 2:X.pilihan_uang();
break;
default: cout<<"pilihan anda salah";
break;
}
break;
default: cout<<"maaf pilihan yang anda masukkan salah";
}
cout<<endl<<endl;
system("PAUSE");
system("cls");
return main();
}

C + + program to find a node

Posted by Didi Setyapramana On 1:27 AM 0 komentar

# Include <cstdlib> 
# Include <iostream> 
using namespace std; 
int main (int argc, char * argv []) { 
    char g [10]; 
    int j [10]; 
    int a, b, c; 
    int d = 0; 
    
    cout <<"Enter the Number of Nodes:"; 
    cin>> a; 
    
    for (b = 0; b <a, b + +) 
    { 
         cout <<"Node Name [" <<b +1 <<"]:"; 
         cin>> g [b]; 
    } 
    for (c = 0; c <a, c + +) 
    { 
         if (c +1 <a) 
         { 
             cout <<"Distance" <<g [c] <<"With" <<g [c +1 ]<<":"; 
             cin>> j [c]; 
         } 
         else 
         { 
             cout <<"Distance" <<g [c] <<"With" <<g [0 ]<<":"; 
             cin>> j [c]; 
         } 
    d + = j [c]; 
    } 
    
    cout <<"Total Distance:" <<d; 
    cout <<endl; 
    
    system ("PAUSE"); 
    return EXIT_SUCCESS; } 

Swap Reference Java Jeliot

Posted by Didi Setyapramana On 10:13 PM 0 komentar


jeliot.io import .*;

public class Numbers {
     public Num (int x) {/ / constructor
         a = x;
     }
     public static void swap (Num a, Num b) {
          int temp;
          temp = a.a;
          a.a = b.a;
          b.a = temp;
     }
     public final void output () {
          System.out.println ("number:" + a);
     }
     private int a;

public static void main () {
        System.out.println ("\ nUsing class \ n");
        Numbers x1 = new Numbers (5);
        Numbers y1 = new Numbers (6);
        x1.output ();
        y1.output ();
        swap (x1, y1);
        System.out.println ("\ nAfter swap disposable class: \ n");
        x1.output ();
        y1.output ();
    }
}

# include <cstdlib>
# include <iostream>

using namespace std;

p_long class {
   public:
int p, l;
int area ()
{return (p * l);}

};
main () {
   p_long a;
   cout <<"Rectangle" <<endl;
   cout <<"Length of \ t:"; cin>> a.p;
   cout <<"Width \ t:"; cin>> a.l;
   cout <<"Area \ t:" <<a.Rectangle () <<endl;
  
     system ("PAUSE");
     return EXIT_SUCCESS;

C + + program to print to the form of Text

Posted by Didi Setyapramana On 8:18 PM 0 komentar

# include <cstdlib>
# include <iostream>
# include <fstream>

using namespace std;

gasoline class {
public:
POM void ();
private:
int total;
float liter;
int jumlah_yang_dibeli;
int harga_satuan;

};
void gasoline:: POM () {
cout <<"Amount purchased:";
harga_satuan = 5000;
cin>> liter;
jumlah_yang_dibeli = harga_satuan * liter;
cout <<"unit price / liter Rp. 5000" <<endl;
int <<"total it all:" <<jumlah_yang_dibeli <<endl;


ofstream txt;
txt.open ("Struk.txt", ios:: app);

txt <<"Amount purchased:" <<jumlah_yang_dibeli <<endl;
txt <<"unit price / liter Rp. 5000" <<endl;
txt <<"Total it all:" <<jumlah_yang_dibeli <<endl;
txt <<"Thank you for your visit:" <<endl;
cout <<endl;

}
int main (int argc, char * argv [])
Gasoline {x;
x.POM ();

system ("PAUSE");
return EXIT_SUCCESS;
}

programs look for combinations and permutations

Posted by Didi Setyapramana On 8:08 PM 0 komentar

# include <cstdlib>
# include <iostream>

using namespace std;

combinatorial class {
       public:
              void permutation ();
              combining void ();
       private:
              int i, n, r, p, t, a, b, c;
};

void combinatorial:: permutations () {
     cout <<"PERMUTATIONS" <<endl;
     cout <<"Enter n:";
     cin>> n;
     cout <<"Input r:";
     cin>> r;
     a = 1;
     b = 1;
     for (i = n; i> 0; i -)
     {
         a *= i;
     }
     t = n-r;
     if (t! = 0)
     {
         for (i = t; i> 0; i -)
         {
             b *= i;
         }
     }
     if (t! = 0)
     {
          p = a / b;
          cout <<"Result:" <<p <<endl;
     }
     else
     {
          cout <<a <<endl;
     }
}

void combinatorial:: combining () {
     cout <<"combining" <<endl;
     cout <<"Enter n:";
     cin>> n;
     cout <<"Input r:";
     cin>> r;
     a = 1;
     b = 1;
     c = 1;
     for (i = n; i> 0; i -)
     {
         a *= i;
     }
     t = n-r;
     if (t! = 0)
     {
         for (i = t; i> 0; i -)
         {
             b *= i;
         }
     }
     for (i = r i> 0; i -)
     {
         c *= i;
     }
  
  
     if (t! = 0)
     {
          p = a / (b * c);
          cout <<"Result:" <<p <<endl;
     }
     else
     {
          cout <<a <<endl;
     }
}
          
int main (int argc, char * argv [])
{
     combinatorial x;
     x.permutasi ();
     cout <<endl;
     x.combinasi ();
     cout <<endl;
  
     system ("PAUSE");
     return EXIT_SUCCESS;
}

Program Menentukan Kombinasi Dan Permutasi

Posted by Didi Setyapramana On 8:03 PM 0 komentar

#include <cstdlib>
#include <iostream>

using namespace std;

class kombinatorial{
      public:
             void permutasi();
             void combinasi();
      private:
             int i,n,r,p,t,a,b,c;
};

void kombinatorial::permutasi(){
    cout<<"PERMUTASI"<<endl;
    cout<<"Masukan n:";
    cin>>n;
    cout<<"Masukan r:";
    cin>>r;
    a=1;
    b=1;
    for(i=n;i>0;i--)
    {
        a *=i;
    }
    t=n-r;
    if(t!=0)
    {
        for(i=t;i>0;i--)
        {
            b *=i;
        }
    }
    if(t!=0)
    {
         p=a/b;
         cout<<"Hasil:"<<p<<endl;
    }
    else
    {
         cout<<a<<endl;
    }
}
  
void kombinatorial::combinasi(){
    cout<<"COMBINASI"<<endl;
    cout<<"Masukan n:";
    cin>>n;
    cout<<"Masukan r:";
    cin>>r;
    a=1;
    b=1;
    c=1;
    for(i=n;i>0;i--)
    {
        a *=i;
    }
    t=n-r;
    if(t!=0)
    {
        for(i=t;i>0;i--)
        {
            b *=i;
        }
    }
    for(i=r;i>0;i--)
    {
        c *=i;
    }
   
   
    if(t!=0)
    {
         p=a/(b*c);
         cout<<"Hasil:"<<p<<endl;
    }
    else
    {
         cout<<a<<endl;
    }
} 
            
int main(int argc, char *argv[])
{
    kombinatorial x;
    x.permutasi();
    cout<<endl; 
    x.combinasi();
    cout<<endl; 
   
    system("PAUSE");
    return EXIT_SUCCESS;
}

#include <iostream.h>
#include <math.h>
#include <conio.h>
class squreroot {
    friend ostream& operator<<(ostream&, squreroot&);
    friend istream& operator>>(istream&, squreroot&);
public:
    squreroot();
    int disk() { return B*B-4*A*C; }
    float squreroot1() {return -B+sqrt(disk())/(2*A); }
    float squreroot2() {return -B-sqrt(disk())/(2*A); }
    void arithmetic_squreroot();
    void print_disk() { cout << "diskriminan = " << disk() << endl; }
    void print_squreroot() {
        cout << "x1 = " << squreroot1() << endl;
        cout << "x2 = " << squreroot2() << endl;
    }
private:
    int A, B, C;   // input
    float x1, x2;  // squreroot 1 and squreroot 2
};

ostream& operator<<(ostream& out, squreroot& output) {
    output.print_disk();
    if (output.disk() >= 0) output.print_squreroot();
    else out << "Squreroot imajiner";
    return out;
}

istream& operator>>(istream& in, squreroot& input) {
    cout << "Coefficient of rank2   : "; in >> input.A;
    cout << "Coefficient of rank1   : "; in >> input.B;
    cout << "Coefficient of rank0   : "; in >> input.C;
    return in;
}

squreroot::squreroot() {
    cout << "arithmetic squreroot quadratic equation\n";
}

void squreroot::arithmetic_squreroot() {
     if (A == 0) {
        cout << "not a quadratic equation.\n";
        cout << "Value squreroot = " << -C/B; }  else {
          if (disk() > 0) {
             x1 = squreroot1();
             x2 = squreroot2();
          }  else if (disk() == 0) {
                    x1 = squreroot1();
                    x2 = x1;
             }
     }
}

main() {
    squreroot kasus;
    cin >> kasus;
    kasus.arithmetic_squreroot();
    cout << kasus;
    getch();
    return 0;
}

Program C++ Mencari Akar Imajiner

Posted by Didi Setyapramana On 8:26 PM 0 komentar


#include <iostream.h>
#include <math.h>
#include <conio.h>
class Akar {
public:
    Akar();
    float akar1() {return -B+sqrt(disk())/(2*A); }
    float akar2() {return -B-sqrt(disk())/(2*A); }
    //void cetak_akar();
private:
    int A, B, C;   // input
    int disk() { return B*B-4*A*C; }
    float x1, x2;  // akar 1 dan akar 2
};    
    
Akar::Akar() {
     cout << "Koefisien pangkat 2   : "; cin >> A;
     cout << "Koefisien pangkat 1   : "; cin >> B;
     cout << "Koefisien pangkat 0   : "; cin >> C;
     if (A == 0) {
        cout << "bukan pers. kuadrat.\n";
        cout << "Harga akar = " << -C/B; }  else {          
          if (disk() > 0) {      
             x1 = akar1();
             x2 = akar2();
             cout << "diskriminan = " << disk() << endl;
             cout << "x1 = " << x1 << endl;
             cout << "x2 = " << x2 << endl;
          }  else if (disk() == 0) {  
                    x1 = akar1();   
                    x2 = x1;
             cout << "diskriminan = 0\n";
             cout << "x1 = " << x1 << endl;
             cout << "x2 = " << x2 << endl;
             } else cout << "Akar imajiner";
     }
}

main() {
    Akar kasus;
    getch();
    return 0;
}


#include <iostream.h>
#include <conio.h>
class Banding {
    friend istream& operator>>(istream&, Banding&);
public:
    Banding() {}; 
    void bandingkan() {
       if (A > B) 
            cout << "Bilangan terbesar : " << A;
       else 
            cout << "Bilangan terbesar : " << B;
    }       
private:
    int A, B;
};

istream& operator>>(istream& in, Banding& bilangan){
     cout << "Bilangan pertama  = "; 
     in >> bilangan.A;
     cout << "Bilangan kedua    = "; 
     in >> bilangan.B;
     return in;
};

main() {
     Banding bilangan;
     cin >> bilangan;
     bilangan.bandingkan();
     getch();
     return 0;
}

String dalam Bahasa C

Posted by Didi Setyapramana On 12:06 AM 0 komentar

Contoh kasus String adalah sebagai berikut :
1. Konversi kata dalam huruf besar menjadi kata dalam huruf kecil

Jawab:
a. Algoritma dengan pseuducode

input(besar)
n=len(besar)
for i=1 to n do
posisi=ord(besar[i])
kecil=chr(posisi+32)
output(kecil)
endfor


b. Implementasi dalam bahasa C/C++

/* KONVERSI HURUF BESAR MENJADI HURUF KECIL */
#include<stdio.h>
#include<string.h>
#define m 25
main()
{
char besar[m];
char kecil[m];
int i,n;
printf("Konversi huruf besar menjadi huruf kecil \n");
printf("Masukkan kata dengan huruf besar : ");
scanf("%s",besar);
n=strlen(besar);
for(i=0;i<n;i++)
{
kecil[i]=besar[i]+32;
printf("%c", kecil[i]);
}
}


Tampilan Program :

Konversi huruf besar menjadi huruf kecil
Masukkan kata dengan huruf besar : PEMROGRAMAN
p e m r o g r a m a n




2. Konversi kata dalam huruf kecil menjadi kata dalam huruf besar

Jawab :
a. Algoritma dengan pseuducode

input(kecil)
n=len(kecil)
for i=1 to n do
posisi=ord(kecil[i])
kecil=chr(posisi-32)
output(besar)
endfor


b. Implementasi dalam bahasa C/C++

/* KONVERSI HURUF KECIL MENJADI HURUF BESAR */
#include<stdio.h>
#include<string.h>
#define m 25
main()
{
char besar[m];
char kecil[m];
int i,n;
printf("Konversi huruf kecil menjadi huruf besar \n");
printf("Masukkan kata dengan huruf kecil : ");
scanf("%s",kecil);
n=strlen(kecil);
for(i=0;i<n;i++)
{
besar[i]=kecil[i]+-2;
printf("#%c", besar[i]);
}
}

Tampilan Program :

Konversi huruf kecil menjadi huruf besar
Masukkan kata dengan huruf kecil : pemrograman
P E M R O G R A M A N

e-sourcesinformatics

Statistik Java Jeliot

Posted by Didi Setyapramana On 9:06 PM 0 komentar

import jeliot.io.*;

public class Statistik {

public static int nilai_Maksimum(int data[]) {
    int maks = data[0];
    int n = data.length;
    int modus;
    
    for (int i=1; i<n; i++)
        if (maks < data[i]) { 
            maks = data[i];
            modus = i;        
        }
    System.out.println("Modusnya adalah " + modus);
    return maks;
}

public static void hitung_Frekuensi() {
     int data[] = {1,1,2,2,2,2,2,3,3,4,5,5,5,5};
     int i, n = data.length;     
     int [] f = new int[10];
     int nilai_terbesar;

     for (i=0; i<n; i++) ++f[data[i]];
     for (i=0; i<10; i++) 
         System.out.println("Data " + i + " sebanyak " + f[i]);
     nilai_terbesar = nilai_Maksimum(f);
     System.out.println("Dengan frekuensi = " + nilai_terbesar);
}

    public static void main() {
    hitung_Frekuensi();

    }
}







Menentukan Modus dengan Jeliot

Posted by Didi Setyapramana On 8:49 AM 0 komentar

import java.util.scaner.io.*;

public class modus{
public static void main(String[]args){
    int banyak;
    int data[];
    int temp;
    int jumlah = 0;

    System.out.print("Banyaknya data : ");
    banyak =Input.nextInt();
    data = new int[banyak];
    for(int i=0;i<=banyak-1;i++){
        System.out.print("Data ke-"+(i+1)+": ");
        data[i]=Input.nextInt();
    }
    
    System.out.print("Data sudah diurut : ");
    for(int i=0; i<=banyak-1; i++) {
        System.out.print(data[i]+" ");
        jumlah=jumlah + data[i];
    }

    int hasil=0;
    int besar=0;
    for (int i=0; i<data.length ;i++){
        if(data[i]==banyak){
        System.out.print(data[i]+" ");
        System.out.print(++temp);
            if(temp>besar){
                besar=temp;
                hasil=banyak;
            }
        }
        else{
            banyak=data[i];
            temp=1;
            System.out.print(data[i]+" ");
            System.out.print(temp);
            }
        }
        System.out.print("Modus ="+hasil);
    }
}

Marge Sort in Java jeliot

Posted by Didi Setyapramana On 8:45 AM 0 komentar

import jeliot.io.*;

public class mergeSort{
  public static void main(String a[]){
    int i;
    int array[] = {12,9,4,7,15,1,3,10};
    System.out.println("\n\n       RoseIndia\n\n");
    System.out.println("       Merge Sort\n\n");
    System.out.println("Values Before the sort:\n");
    //for(i = 0; i < array.length; i++)
      //System.out.print( array+"  ");
    System.out.println();
    mergeSort_srt(array,0, array.length-1);
    System.out.print("Values after the sort:\n");
    for(i = 0; i <array.length; i++)
      System.out.print(array+"  ");
    System.out.println();
    System.out.println("PAUSE");
  }

  public static void mergeSort_srt(int array[],int lo, int n){
    int low = lo;
    int high = n;
    if (low >= high) {
      return;
    }

    int middle = (low + high) / 2;
    mergeSort_srt(array, low, middle);
        mergeSort_srt(array, middle + 1, high);
    int end_low = middle;
    int start_high = middle + 1;
    while ((lo <= end_low) && (start_high <= high)) {
      if (array[low] < array[start_high]) {
        low++;
            } else {
        int Temp = array[start_high];
        for (int k = start_high- 1; k >= low; k--) {
          array[k+1] = array[k];
        }
                array[low] = Temp;
                low++;
                end_low++;
                start_high++;
            }
        }
    }  
}

Selection Sort in Jeliot

Posted by Didi Setyapramana On 8:42 AM 0 komentar

import jeliot.io.*;

public class Sorting {
    public static void main() {
       
int []a = new int [20];
int cur,x,temp,cur2,temp2;

System.out.print("Banyak Data : ");
x=Input.readInt();
    for(int i=0;i<x;i++){
    System.out.print("Data [");
    System.out.print(i+1);
    System.out.print("] : ");
    a[i]=Input.readInt();
    }
    for(int i=0;i<x;i++){
    cur=i;
    cur2=x;
    for(int k=i+1;k<x;k++){
            if(a[cur]>a[k]){
            cur=k;
            }
    }
    for(int t=x;t<x;t--){
            if(a[cur2]<a[t]){
            cur2=t;
            }
    
    temp2=a[t];
    a[t]=a[cur2];
    a[cur2]=temp2;
    }
    
    temp=a[i];
    a[i]=a[cur];
    a[cur]=temp;
    }
    for(int i=0;i<x;i++){
    System.out.print(" ");
    System.out.print(a[i]);
    }

System.out.print(" \n ");



    }
}

Quick Sort in Java Jeliot

Posted by Didi Setyapramana On 8:34 AM 0 komentar

import jeliot.io.*;

public class QuickSort{
  public static void main(String a[]){
    int i;
    int array[] = {12,9,4,29,7,1,3,10};
    System.out.println("Values Before the sort:\n");
    //for(i = 0; i < array.length; i++)
      //System.out.print( array+"  ");
    System.out.println();
    quickSort(array,0,7);
    System.out.print("Values after the sort:\n");
    for(i = 0; i <array.length; i++)
      System.out.print(array+"  ");
    System.out.println();
    System.out.println("PAUSE");
  }

 public static int partition(int arr[], int left, int right) { 
      int i = left, j = right; 
      int tmp; 
      int pivot = arr[(left + right) / 2]; 

      while (i <= j) { 
            while (arr < pivot) 
                  i++; 
            while (arr[j] > pivot) 
                  j--; 
            if (i <= j) { 
                  tmp = arr; 
                  arr = arr[j]; 
                  arr[j] = tmp; 
                  i++; 
                  j--; 
            } 
      }; 
      return i; 
    } 

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

class Perkalian {
    friend ostream& operator<<(ostream&, const Perkalian&);
    friend istream& operator>>(istream&, Perkalian&);
public:   
    Perkalian();
    void hitung_perkaliannya(){ hasil = (a * b); }
private:
    int a,b;
    int hasil;
};

Perkalian::Perkalian() {
    cout << "Program mengalikan 2 integer\n";
    cout << "Selamat berkarya\n";
}

istream& operator>>(istream& in, Perkalian& masukan) {
    cout << "Masukkan nilai a : ";
    in >> masukan.a;
    cout << "Masukkan nilai b : ";    
    in >> masukan.b;
    return in;
}
    
ostream& operator<<(ostream& out, const Perkalian& keluaran) {
    out << "Nilai a : " << keluaran.a << endl;    
    out << "Nilai b : " << keluaran.b << endl;        
    out << "Hasil kali integer di atas : " << keluaran.hasil << endl;
    return out;
}

main() {
     Perkalian X;
     cin >> X;
     X.hitung_perkaliannya();
     cout << X;
     getch();
     return 0;
}


Search Engine Submission - AddMe


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

void bola()
{
    float  l,phi,r;

   cout<<"Masukan Jari-jari Bola:";
   cin>>r;

   phi=3.14;
   l=4*phi*r*r;
   cout<<"Luas Bola adalah:";
   cout<<l;
}

void tabung()
{
    float phi,r,t,l;

   cout<<"Masukan Jari-jari Tabung:";
   cin>>r;
   cout<<"Masukan tinggi Tabung:";
   cin>>t;

   phi=3.14;
   l=(phi*r*2)*(t*r);
   cout<<"Luas Tabung adalah:";
   cout<<l;
}

void ketupat()
{
   float l,d1,d2;

   cout<<"Masukan diagonal 1:";
   cin>>d1;
   cout<<"Masukan diagonal 2:";
   cin>>d2;

   l=1.5*d1*d2;
   cout<<"Luas Belah Ketupat adalah:";
   cout<<l;
}

int main()
{
    cout<<"Menghitung luas bola:";
   cout<<endl;
    bola();
   cout<<endl<<endl;
   cout<<"Menghitung luas tabung:";
   cout<<endl;
   tabung();
   cout<<endl<<endl;
   cout<<"Menghitung luas belah ketupat:";
   cout<<endl;
   ketupat();

getch();
return 0;
}

#include <iostream.h>
#include <conio.h>
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<<"*********************************************************"<<endl;
         cout<<endl;
         cout<<"* PROGRAM KONVERSI detik MENJADI FORMAT jam:menit:detik *"<<endl;
         cout<<endl;
         cout<<"*********************************************************"<<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(){
Konversi X;
cin>>X;
cout<<X;
cout<<endl;
cout<<endl;

    system("PAUSE");
    system("cls");
    return main();

}

Decimal to Octal Conversion in C++

Posted by Didi Setyapramana On 8:06 PM 0 komentar


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

to_Oktal void (int n)
{
  char * oktal_list [] = {"0", "1", "2", "3", "4", "5", "6", "7"};
  if (n> 7)
  {
   to_Oktal (n / 8);
  }
  cout <<oktal_list [n% 8];
  getch ();
}

int main ()
{
  int a;
  cout <<"Enter a number to be converted:";
  cin>> a;
  cout <<a <<"in octal is:";
  to_Oktal (a);
}

Decimal to Binary Conversion in C++

Posted by Didi Setyapramana On 7:34 PM 0 komentar

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

toBiner void (int n)
{
  if (n> 1)
  {
  toBiner (n / 2);
  }
  cout <<n% 2;
  getch ();
}

int main ()
{
  int a;
  cout <<"Enter a number to be converted:";
  cin>> a;
  cout <<a <<"in binary is";
  toBiner (a);

  return 0;
}

reversing words in C + +

Posted by Didi Setyapramana On 7:22 PM 0 komentar

# include <iostream>
# include <conio.h>
  return class {
        public:
               void reversed();
        private:
                char word [50];
};


void return:: reversed () {
      cout <<"enter the word that will be reversed";
      cin>> word;
      cout <<"\ n \ n";
      strrev (word);
      cout <<"Word After reversed:" <<word;
      }


int main ()
{
  return X;
  X.reversed ();

  getch ();
  return 0;
}

Selection Sort C++

Posted by Didi Setyapramana On 7:09 PM 0 komentar

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

class Sorting{
      friend istream& operator>>(istream& in, Sorting& a);
      friend ostream& operator<<(ostream& out, Sorting& a);
public:
       void selection_sort();
       int pencarianBiner(int low, int high);
       void minimum(int, int, int&);
        void tukar(int& , int&);
private:
        
        int data [10];
        int n,a,b;
};

istream& operator>>(istream& in, Sorting& masukan){
         cout<<"Banyak data : \n";
         in>>masukan.n;
         for(int i=0; i<masukan.n; i++){
              cout<<"Data ke - "<<i+1<<" = ";
              in>>masukan.data[i];
              }
              return in;
         }  

ostream& operator<<(ostream& out, Sorting& keluaran){
        for(int i=0; i<keluaran.n; i++){
              out<<keluaran.data[i]<<" ";
              out<<"\n";
              }
              return out;
         }  
                 

void Sorting::minimum(int dari, int n, int &tempat){
     int min=data[dari];
     tempat=dari;
     int max=data[dari];
     for(int i= dari+1; i<n; i++)
     if(data[i] < min){
                min=data[i];
                tempat=i;
                }
     
    
     } 

void Sorting::tukar(int &a, int &b){
     int temp=a;
     a=b;
     b=temp;
     }

void Sorting::selection_sort(){
     int t;
     for(int i=0; i<n; i++){
             minimum(i,n,t);
             tukar(data[i],data[t]);
     }
}


int main(){
    Sorting x;
    cin>>x;
    cout<<endl;
    cout<<x;
    x.selection_sort();
    cout<<endl;
    cout<<x;
    getch();
    return 0;
}
   

Buble Sort C++

Posted by Didi Setyapramana On 7:02 PM 0 komentar

#include <cstdlib>
#include <iostream>

using namespace std;
void baca_data(int A[], int n){
     int i;
     for(i=0; i<n; i++)
     { cout<<"Data ke-"<<i+1<<" : ";
     cin>> A[i];
               }
               }
     void cetak_data(const int A[], int n){
          int i;
          for(i=0; i<n; i++)
          cout<<A[i]<<" ";
          cout<<"\n";
          }
     void tukar (int *a, int *b)
     {
     int temp;
     temp= *a;
     *a= *b;
     *b= temp;
     }
void tampil_data(int data[], int n)
{
     int i;
     for(i=0; i<n; i++){
     cout << data[i] << " ";
     cout << "\n";
     }
}

void bubble_sort(int data[], int n)
{
     int fase;
     int j;
     int temp;
     int tukar_data;
     fase = 1;
     tukar_data = 1;
      while (fase < n-1 && tukar_data){
      tukar_data = 0;
      for (j=0; j<n-fase; j++)
      if (data[j] > data[j+1]){
         tukar_data = 1; 
         temp = data[j];
         data[j] = data[j+1];
         data[j+1] = temp;
         }
         cout << "Fase " << fase << " : ";
         tampil_data(data, n);
         fase++;
         }
         }
     


int main(int argc, char *argv[])
{
    int data[10], n;
    cout<<"Banyak data : ";
    cin>>n;
    baca_data(data,n);
    cetak_data(data,n);
    bubble_sort(data,n);
    cetak_data(data,n);
    cout << "Hasil Pengurutan : ";
    tampil_data(data, n);
    system("PAUSE");
    return EXIT_SUCCESS;
}

Array Loping keyboard

Posted by Didi Setyapramana On 3:35 PM 0 komentar

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

int main()
{

   int data[100];
   int n;
   float jumlah=0, rata;

   cout<<"Masukan Jumlah data: ";
   cin>>n;
   cout<<endl;

   for(int i=0;i<n;i++)
   {
      cout<<"Masukan Data["<<i+1<<"]:";
      cin>>data[i];
   }

   cout<<endl;

   for(int i=0;i<n;i++)
   {
      cout<<"Nilai a["<<i+1<<"]:";
      cout<<data[i]<<endl;
      jumlah +=data[i];
   }
   rata=jumlah/n;
   cout<<"Jumlah:"<<jumlah<<endl;
   cout<<"rata:"<<rata<<endl;

getch();
return 0;

Definition of Data Structures

Posted by Didi Setyapramana On 7:39 AM 0 komentar

The data structure is a way of storing or representing data in the computer to be used efficiently. While the data is a representation of real world facts. Facts or description of a reality that is stored, recorded or represented in the form of text, sounds, images, signals or symbols.

Broadly speaking, the type of data can be categorized into:
Simple data type.

Simple single data type, eg Integer, real, boolean and character.
Simple data type compound, misalnyaString

Data structures, including:

Simple data structures, eg arrays and records.
Compound data structures, which consist of:

Linear: Stack, Queue, and Multilist sertaList
Non-Linear: Binary Tree and Graph

Use proper data structures in the programming process will produce an algorithm that is more clear and precise, making the overall program more efficient and simpler.
Standard data structure that is usually used in the field of informatics are:
* List the linear (Linked List) and its variations
* Multilist
* Stack (Piles)
* Queue (Queue)
* Tree (Tree)
* Graph (Graf)

REVIEW RECORD (RECORD)
Compiled by one or more fields. Each field stores data from a certain base types or from other types of formations that have been defined previously. The name of the recording is determined by the programmer.

Records also called structured types.

Definition of Data Structures

Posted by Didi Setyapramana On 7:37 AM 0 komentar

The data structure is a way of storing or representing data in the computer to be used efficiently. While the data is a representation of real world facts. Facts or description of a reality that is stored, recorded or represented in the form of text, sounds, images, signals or symbols.

Broadly speaking, the type of data can be categorized into:
Simple data type.

Simple single data type, eg Integer, real, boolean and character.
Simple data type compound, misalnyaString

Data structures, including:

Simple data structures, eg arrays and records.
Compound data structures, which consist of:

Linear: Stack, Queue, and Multilist sertaList
Non-Linear: Binary Tree and Graph

Use proper data structures in the programming process will produce an algorithm that is more clear and precise, making the overall program more efficient and simpler.
Standard data structure that is usually used in the field of informatics are:
* List the linear (Linked List) and its variations
* Multilist
* Stack (Piles)
* Queue (Queue)
* Tree (Tree)
* Graph (Graf)

REVIEW RECORD (RECORD)
Compiled by one or more fields. Each field stores data from a certain base types or from other types of formations that have been defined previously. The name of the recording is determined by the programmer.

Records also called structured types.

Introduction To Data Structures C++

Posted by Didi Setyapramana On 7:26 AM 0 komentar

DATA TYPE:
Data type variable is the set of values ​​that variables can assume.

Basic Data Type in C:
int, char, float, double
Basic Data Types in PASCAL:
integer, real, char, boolean
 
ABSTRACT DATA TYPE:
ADT is a set of elements with a collection of well-defined operations.
1) The operation can take operands from not only examples of ADT, but other types of operands or examples of other ADTs.
2) Similarly, the results do not need examples of the ADT.
3) At least one operand or the result is of type ADT is concerned.

Object Oriented languages ​​like C + + and Java provide support explicite way to express Class ADTs.


DATA STRUCTURE:
A data structure is an implementation of ADT.That is a translation of the ADT to the report of the programming consists of language.It
1) Statement that defines the variable to be a type of ADT.
2) The operation is defined in the ADT (using the procedure of programming languages).

Choose ADT implementations of data structures to represent the ADT.
Each data structure is built from the basic data types of the underlying programming language using the available data structuring facilities, such as
arrays, records (structures in C), pointer, file, sets, etc.

Example:
A "Queue" is an abstract data type that can be defined as a sequence of elements with such operations Enqueue (x, T), Dequeue (Q).
This can be implemented using data structures such as
1) Array
2) a list of its own related
3) linked list of doubles
4) Circular array

Simple Calculator Using C + +

Posted by Didi Setyapramana On 7:19 AM 0 komentar

#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

class kalkulator{      
      public:
             void menu();
             void tambah();
             void kurang();
             void kali();
             void bagi();
             void pangkat();
             void akar();
             void persen();
             void sinx();
             void cosx();
             void tanx();
             void logx();
            
      private:
              float nilai1,nilai2;
              float jumlah;
      };
      
      void kalkulator::menu(){
           cout<<"===================================================="<<endl;
           cout<<"====    SELAMAT DATANG DI PROGRAM KALKULATOR     ==="<<endl;
           cout<<"===================================================="<<endl;
           cout<<endl;
           cout<<endl;
           cout<<"****************************************************"<<endl;
           cout<<"***  SILAHKAN PILIH OPERATOR YANG ANDA INGINKAN  ***"<<endl;
           cout<<"********                                 ***********"<<endl;
           cout<<"********            1. Penjumlahan       ***********"<<endl;
           cout<<"********            2. Pengurangan       ***********"<<endl;
           cout<<"********            3. Perkalian         ***********"<<endl;
           cout<<"********            4. Pembagian         ***********"<<endl;
           cout<<"********            5. Pangkat           ***********"<<endl;
           cout<<"********            6. Akar              ***********"<<endl;
           cout<<"********            7. Persen (%)        ***********"<<endl;
           cout<<"********            8. Sin               ***********"<<endl;
           cout<<"********            9. Cos               ***********"<<endl;
           cout<<"********           10. Tan               ***********"<<endl;
           cout<<"********           11. Logaritma         ***********"<<endl;
           cout<<"****************************************************"<<endl;
           cout<<endl;
           }
           
      void kalkulator::tambah(){
           cout<<"**************************************"<<endl;
           cout<<"******  Menghitung Penjumlahan  ******"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilia b: ";
           cin>>nilai2;
           jumlah=nilai1+nilai2;
           cout<<endl;
           cout<<"Nilai penjumlahan a dan b adalah: "<<jumlah;
           cout<<endl;
           }
           
      void kalkulator::kurang(){
           cout<<"**************************************"<<endl;
           cout<<"******  Menghitung Pengurangan  ******"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilia b: ";
           cin>>nilai2;
           jumlah=nilai1-nilai2;
           cout<<endl;
           cout<<"Nilai pengurangan a dan b adalah: "<<jumlah;
           cout<<endl;
           }
           
      void kalkulator::kali(){
           cout<<"**************************************"<<endl;
           cout<<"******   Menghitung Perkalian   ******"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilia b: ";
           cin>>nilai2;
           jumlah=nilai1*nilai2;
           cout<<endl;
           cout<<"Nilai perkalian a dan b adalah: "<<jumlah;
           cout<<endl;
           }
           
      void kalkulator::bagi(){
           cout<<"**************************************"<<endl;
           cout<<"******   Menghitung Pembagian   ******"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilia b: ";
           cin>>nilai2;
           jumlah=nilai1/nilai2;
           cout<<endl;
           cout<<"Nilai pembagian a dan b adalah: "<<jumlah;
           cout<<endl;
           }
              
      void kalkulator::pangkat(){
           cout<<"**************************************"<<endl;
           cout<<"********  Menghitung pangkat  ********"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           jumlah=1;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilai b: ";
           cin>>nilai2;
           for(int a=0;a<nilai2;a++){
                   jumlah*=nilai1;
                   }
           cout<<endl;
           cout<<"Nilai "<<nilai1<<" pangkat "<<nilai2<<" adalah: "<<jumlah;
           cout<<endl;
           cout<<endl;
           }
           
      void kalkulator::akar(){
           cout<<"**************************************"<<endl;
           cout<<"*********   Menghitung akar  *********"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           cout<<endl;
           cout<<"Hasil dari akar: "<<nilai1<<" adalah:  "<<sqrt(nilai1);
           cout<<endl;
           cout<<endl;
           }
        
      void kalkulator::persen(){
           cout<<"*************************************"<<endl;
           cout<<"********  Menghitung persen  ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=nilai1/100;
           cout<<endl;
           cout<<"Nilai persen dari: "<<nilai1<<" adalah:  "<<jumlah<<" % ";
           cout<<endl;
           cout<<endl;
           }   

      void kalkulator::sinx(){
           cout<<"*************************************"<<endl;
           cout<<"********    Menghitung sin   ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=sin(nilai1);
           cout<<endl;
           cout<<"Nilai dari sin: "<<nilai1<<" adalah:  "<<jumlah;
           cout<<endl;
           cout<<endl;
           }    
           
      void kalkulator::cosx(){
           cout<<"*************************************"<<endl;
           cout<<"********    Menghitung cos   ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=cos(nilai1);
           cout<<endl;
           cout<<"Nilai dari cos: "<<nilai1<<" adalah:  "<<jumlah;
           cout<<endl;
           cout<<endl;
           }   
           
      void kalkulator::tanx(){
           cout<<"*************************************"<<endl;
           cout<<"********    Menghitung tan   ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=tan(nilai1);
           cout<<endl;
           cout<<"Nilai dari tan : "<<nilai1<<" adalah:  "<<jumlah;
           cout<<endl;
           cout<<endl;
           }   
           
       void kalkulator::logx(){
            cout<<"*************************************"<<endl;
           cout<<"********    Menghitung Log    ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=log10(nilai1);
           cout<<"Nilai dari log: "<<nilai1<<" adalah "<<jumlah;
           cout<<endl;
           cout<<endl;
           }
           
int main()
{
    int pil;
    char y;
             kalkulator X;
             X.menu();
             cout<<endl;
             cout<<"Masukkan pilihan Anda: ";
             cin>>pil;
             cout<<endl;
             switch(pil){
             case 1:X.tambah();     
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                      
             break;
             
             case 2:X.kurang();     
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                      
             break;             

             case 3:X.kali();       
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                      
             break;             

             case 4:X.bagi();       
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                 
             break;       

             case 5:X.pangkat();    
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                      
             break;

             case 6:X.akar();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;             
             break;

             case 7:X.persen();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;
             break;

             case 8:X.sinx();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;             
             break;

             case 9:X.cosx();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                                    
             break;

             case 10:X.tanx();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                                    
             break;

             case 11:X.logx();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                                    
             break;

             
             default:cout<<"Maaf pilihan yang anda masukkan salah";
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;             
             break;
             }
                    
    system("PAUSE");
    return EXIT_SUCCESS;
}

Kalkulator Sederhana Menggunakan C++

Posted by Didi Setyapramana On 6:52 AM 1 komentar

#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

class kalkulator{      
      public:
             void menu();
             void tambah();
             void kurang();
             void kali();
             void bagi();
             void pangkat();
             void akar();
             void persen();
             void sinx();
             void cosx();
             void tanx();
             void logx();
            
      private:
              float nilai1,nilai2;
              float jumlah;
      };
      
      void kalkulator::menu(){
           cout<<"===================================================="<<endl;
           cout<<"====    SELAMAT DATANG DI PROGRAM KALKULATOR     ==="<<endl;
           cout<<"===================================================="<<endl;
           cout<<endl;
           cout<<endl;
           cout<<"****************************************************"<<endl;
           cout<<"***  SILAHKAN PILIH OPERATOR YANG ANDA INGINKAN  ***"<<endl;
           cout<<"********                                 ***********"<<endl;
           cout<<"********            1. Penjumlahan       ***********"<<endl;
           cout<<"********            2. Pengurangan       ***********"<<endl;
           cout<<"********            3. Perkalian         ***********"<<endl;
           cout<<"********            4. Pembagian         ***********"<<endl;
           cout<<"********            5. Pangkat           ***********"<<endl;
           cout<<"********            6. Akar              ***********"<<endl;
           cout<<"********            7. Persen (%)        ***********"<<endl;
           cout<<"********            8. Sin               ***********"<<endl;
           cout<<"********            9. Cos               ***********"<<endl;
           cout<<"********           10. Tan               ***********"<<endl;
           cout<<"********           11. Logaritma         ***********"<<endl;
           cout<<"****************************************************"<<endl;
           cout<<endl;
           }
           
      void kalkulator::tambah(){
           cout<<"**************************************"<<endl;
           cout<<"******  Menghitung Penjumlahan  ******"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilia b: ";
           cin>>nilai2;
           jumlah=nilai1+nilai2;
           cout<<endl;
           cout<<"Nilai penjumlahan a dan b adalah: "<<jumlah;
           cout<<endl;
           }
           
      void kalkulator::kurang(){
           cout<<"**************************************"<<endl;
           cout<<"******  Menghitung Pengurangan  ******"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilia b: ";
           cin>>nilai2;
           jumlah=nilai1-nilai2;
           cout<<endl;
           cout<<"Nilai pengurangan a dan b adalah: "<<jumlah;
           cout<<endl;
           }
           
      void kalkulator::kali(){
           cout<<"**************************************"<<endl;
           cout<<"******   Menghitung Perkalian   ******"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilia b: ";
           cin>>nilai2;
           jumlah=nilai1*nilai2;
           cout<<endl;
           cout<<"Nilai perkalian a dan b adalah: "<<jumlah;
           cout<<endl;
           }
           
      void kalkulator::bagi(){
           cout<<"**************************************"<<endl;
           cout<<"******   Menghitung Pembagian   ******"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilia b: ";
           cin>>nilai2;
           jumlah=nilai1/nilai2;
           cout<<endl;
           cout<<"Nilai pembagian a dan b adalah: "<<jumlah;
           cout<<endl;
           }
              
      void kalkulator::pangkat(){
           cout<<"**************************************"<<endl;
           cout<<"********  Menghitung pangkat  ********"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           jumlah=1;
           cout<<"Masukkan nilai a: ";
           cin>>nilai1;
           cout<<"Masukkan nilai b: ";
           cin>>nilai2;
           for(int a=0;a<nilai2;a++){
                   jumlah*=nilai1;
                   }
           cout<<endl;
           cout<<"Nilai "<<nilai1<<" pangkat "<<nilai2<<" adalah: "<<jumlah;
           cout<<endl;
           cout<<endl;
           }
           
      void kalkulator::akar(){
           cout<<"**************************************"<<endl;
           cout<<"*********   Menghitung akar  *********"<<endl;
           cout<<"**************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           cout<<endl;
           cout<<"Hasil dari akar: "<<nilai1<<" adalah:  "<<sqrt(nilai1);
           cout<<endl;
           cout<<endl;
           }
        
      void kalkulator::persen(){
           cout<<"*************************************"<<endl;
           cout<<"********  Menghitung persen  ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=nilai1/100;
           cout<<endl;
           cout<<"Nilai persen dari: "<<nilai1<<" adalah:  "<<jumlah<<" % ";
           cout<<endl;
           cout<<endl;
           }   

      void kalkulator::sinx(){
           cout<<"*************************************"<<endl;
           cout<<"********    Menghitung sin   ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=sin(nilai1);
           cout<<endl;
           cout<<"Nilai dari sin: "<<nilai1<<" adalah:  "<<jumlah;
           cout<<endl;
           cout<<endl;
           }    
           
      void kalkulator::cosx(){
           cout<<"*************************************"<<endl;
           cout<<"********    Menghitung cos   ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=cos(nilai1);
           cout<<endl;
           cout<<"Nilai dari cos: "<<nilai1<<" adalah:  "<<jumlah;
           cout<<endl;
           cout<<endl;
           }   
           
      void kalkulator::tanx(){
           cout<<"*************************************"<<endl;
           cout<<"********    Menghitung tan   ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=tan(nilai1);
           cout<<endl;
           cout<<"Nilai dari tan : "<<nilai1<<" adalah:  "<<jumlah;
           cout<<endl;
           cout<<endl;
           }   
           
       void kalkulator::logx(){
            cout<<"*************************************"<<endl;
           cout<<"********    Menghitung Log    ********"<<endl;
           cout<<"*************************************"<<endl;
           cout<<endl;
           cout<<"Masukkan nilai: ";
           cin>>nilai1;
           jumlah=log10(nilai1);
           cout<<"Nilai dari log: "<<nilai1<<" adalah "<<jumlah;
           cout<<endl;
           cout<<endl;
           }
           
int main()
{
    int pil;
    char y;
             kalkulator X;
             X.menu();
             cout<<endl;
             cout<<"Masukkan pilihan Anda: ";
             cin>>pil;
             cout<<endl;
             switch(pil){
             case 1:X.tambah();     
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                      
             break;
             
             case 2:X.kurang();     
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                      
             break;             

             case 3:X.kali();       
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                      
             break;             

             case 4:X.bagi();       
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                 
             break;       

             case 5:X.pangkat();    
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                      
             break;

             case 6:X.akar();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;             
             break;

             case 7:X.persen();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;
             break;

             case 8:X.sinx();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;             
             break;

             case 9:X.cosx();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                                    
             break;

             case 10:X.tanx();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                                    
             break;

             case 11:X.logx();
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar (Y / Q)= ";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;                                    
             break;

             
             default:cout<<"Maaf pilihan yang anda masukkan salah";
             cout<<"Tekan Y untuk kembali tekan Q untuk keluar";
             cin>>y;
             if(y=='y')
             return main();
             else return EXIT_SUCCESS;             
             break;
             }
                    
    system("PAUSE");
    return EXIT_SUCCESS;
}