Sabtu, 16 April 2011

KALKULATOR SEDERHANA

Assalamu'alaikum wr wb....
How are you friends.
... I hope you fine like me...
Ok this time i will posting my individual assignment that
is about a simple calculator. ok just we see the results.

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

class calculator{
      public :
         void sederhana();
         void hitung();
      private :
         int pilih;
         int z;
         int x, y;
         double hasil;
};

void calculator::sederhana(){
     cout<<"Program Kalkuator"<<endl;
     cout<<"Yang Saya Buat"<<endl;
     cout<<endl;
     cout<<"Operator Yang Tersedia:"<<endl;
     cout<<"1  =  Tambah"<<endl;
     cout<<"2  =  Kurang"<<endl;
     cout<<"3  =  Kali"<<endl;
     cout<<"4  =  Bagi"<<endl;
     cout<<"5  =  Pangkat"<<endl;
     cout<<"6  =  Akar"<<endl;
     cout<<"7  =  Cosinus"<<endl;
     cout<<"8  =  Sinus"<<endl;
     cout<<"9  =  Tangen"<<endl;
     cout<<"10 =  Log"<<endl;
     cout<<"11 =  Exponen"<<endl;
     cout<<"12 =  Kuadrat"<<endl;
     cout<<"13 =  Modulus"<<endl;
     cout<<endl;
     cout<<"Silahkan Masukkan Pilihan Menu Operator Yang Anda Inginkan : ";
     cin>>pilih;
     cout<<endl;
     }
void calculator::hitung(){

if(pilih==1){
     cout<<"Penambahan"<<endl;
     cout<<"Masukkan angka pertama : ";
     cin>>x;
     cout<<"Masukkan angka kedua   : ";
     cin>>y;
     hasil=x+y;
     cout<<x<<" + "<<y<<" = "<<hasil<<endl;
      }

else if(pilih==2){
     cout<<"Pengurangan"<<endl;
     cout<<"Masukkan angka pertama : ";
     cin>>x;
     cout<<"Masukkan angka kedua   : ";
     cin>>y;
     hasil=x-y;
     cout<<x<<" - "<<y<<" = "<<hasil<<endl;
     }

else if(pilih==3){
     cout<<"Perkalian"<<endl;
     cout<<"Masukkan angka pertama : ";
     cin>>x;
     cout<<"Masukkan angka kedua   : ";
     cin>>y;
     hasil=x*y;
     cout<<x<<" X "<<y<<" = "<<hasil<<endl;
     }

else if(pilih==4){
     cout<<"Pembagian"<<endl;
     cout<<"Masukkan angka pertama : ";
     cin>>x;
     cout<<"Masukkan angka kedua   : ";
     cin>>y;
     hasil=x/y;
     cout<<x<<" : "<<y<<" = "<<hasil<<endl;
     }

else if(pilih==5){
     cout<<"Perpangkatan"<<endl;
     cout<<"Masukkan angka         : ";
     cin>>x;
     cout<<"Masukkan angka pangkat : ";
     cin>>y;
     hasil=pow(x,y);
     cout<<x<<" pangkat "<<y<<" = "<<hasil<<endl;
     }

else if(pilih==6){
     cout<<"Akar"<<endl;
     cout<<"Masukkan angka : ";
     cin>>x;
     hasil=sqrt(x);
     cout<<"Akar dari "<<x<<" = "<<hasil<<endl;
     }

else if(pilih==7){
     cout<<"cosinus"<<endl;
     cout<<"Masukkan angka : ";
     cin>>x;
     hasil=cos(x);
     cout<<"Hasil cos dari "<<x<<" = "<<hasil<<endl;
     }

else if(pilih==8){
     cout<<"sinus"<<endl;
     cout<<"Masukkan angka : ";
     cin>>x;
     hasil=sin(x);
     cout<<"Hasil sin dari "<<x<<" = "<<hasil<<endl;
      }

else if(pilih==9){
     cout<<"tangen"<<endl;
     cout<<"Masukkan angaka : ";
     cin>>x;
     hasil=tan(x);
     cout<<"Hasil tan dari "<<x<<" = "<<hasil<<endl;
     }

else if(pilih==10){
     cout<<"Log"<<endl;
     cout<<"Masukkan angka : ";
     cin>>x;
     int hasil=(log(x))/2;
     cout<<"Hasil log dari "<<x<<" = "<<hasil<<endl;
     }

else if (pilih==11){
      cout<<"exponen"<<endl;
     cout<<"Masukkan angka : ";
     cin>>x;
     int hasil = (exp(x));
     cout<<"Hasil Exponen dari "<<x<<" = "<<hasil<<endl;
     }
else if (pilih==12){
      cout<<"kuadrat"<<endl;
     cout<<"Masukkan angka : ";
     cin>>x;
     int hasil = x*x;
     cout<<"Hasil Kuadrat dari "<<x<<" = "<<hasil<<endl;
     }
else if (pilih==13){
      cout<<"modulus"<<endl;
     cout<<"Masukkan angka : ";
     cin>>x;
     cout<<"Masukkan angka kedua : ";
     cin>>y;
     int hasil = fmod(x,y);
     cout<<"Hasil modulus dari "<<x<<" = "<<hasil<<endl;
     }
}
int main()
{
    int ulangi;
    awal:
    calculator I;
    I.sederhana();
    I.hitung();
    cout<<endl;
    cout<<"Apakah Anda Ingin Mengulangi? <1=Ya> <2=Tidak> : ";
    cin>>ulangi;
    if(ulangi==1){

    goto awal;

}
else {
     cout<<"KALKULATOR SEDERHANA"<<endl;
}

    getch();
    return 0;
}
 

The above program using #include <math.h> because there are mathematical operations.Using data types integer and variable x,y,z,pilih,hasil.Void calculator::hitung for deklaration hitung.

Jumat, 15 April 2011

TEAM WORK

New Team

  1. Desmala Dewi          (10018061)
  2. Dian Seli Anggraini (10018084)
  3. Sit Eka Chotimah     (10018081)
  4. Tutik Lestari             (10018070)

A.ITERATIVE TO REKURSIVE CONVERSION
    
    Iterative Step:
       for(int i=0;i<5;i++)
       cout<<“mencoba rekursi\n”;
    Rekursive Step:
      void coba(int i)
      {if(i==5)
     {}
     else
     cout<<“mencoba rekursi\n”;coba i+1;
     }
     main()
    {int i=0;
    coba(i);
    }

B.REKURSIVE TO ITERATIVE

   Rekursive Step:
    void coba(int i)
    {if(i==5)
    {}
    else
    cout<<“mencoba rekursi\n”;coba i+1;
    }
    main()
    {int i=0;
    coba(i);
    }
   Iterative Step:
    for(int i=0;i<5;i++)
    cout<<“mencoba rekursi\n”;
 
C. ANALISIS

For example, the function is called with value i = 0 so for the first we must check is i = 5 {if(i==5) or not, and if its have a same value its will be out.
In reality, i is not same with 0 so, please add i with 1. And the condition now become i = 2.
In next line, we show the value of i. Next, called rekursive function with value i = 2.
That steps is repeating until rekursive function calling with value i = 5. 
For now, the if condition is true and that make the function out (return) and continue the command after calling rekursive function with i = 5. Then print out value i.
After print out value i then rekursive function will be out again, and go a head to the command after calling rekursive function where the value before is i = 4. And thats repeating until the value i = 0, thats the first calling rekursive function.

This is the calling rekursif function ilustrated in Indonesia: 
Langkah ke :
1. i = 4 ; mencoba rekursi
2. i = 3 ; mencoba rekursi
3. i = 2 ; mencoba rekursi
4. i = 1 ; mencoba rekursi
5.i  = 0 ; mencoba rekursi
Jika di panggil i=5 akan keluar,sebaliknya dengan operasi rekursif ke iteratif
 

Selasa, 12 April 2011

WEEKLY ASSIGNMENT

Assalamu'alaikum friends....how are you???
i hope you fine like me....

Ok this time I will be posting jeliot program calculates 
area of ​​a circle and volume of the ball .. If still there is
something wrong, please help my friends to fix it ... ok let's see

import jeliot.io.*;
public class luas {
public static void main ()
{
int r;
float luas;
System.out.print("Masukkan jari-jari:");
r = Input.readInt();
luas = (float) 3.14*r*r;
System.out.print("luas llingkaran=");
System.out.print(luas);
float volume;
volume = (float)4/3*(float)3.14*r*r*r;
System.out.print("volume bola=");
System.out.print(volume);
}
}


little explanation of my..

int r; is a variable declaration.
I use a float data type because it uses decimal. With Input.readInt();
we can enter the numbers that we want..from  luas = (float) 3.14*r*r;
System.out.print("luas llingkaran=");
System.out.print(luas);
float volume;
volume = (float)4/3*(float)3.14*r*r*r;
System.out.print("volume bola=");
System.out.print(volume); 
there was a wide circle and volume calculations ball..

That's a little explanation of my :))

Rabu, 06 April 2011

KASUS 5.5 MINGGU KE-5

Di bawah ini adalah program fungsi faktorial secara rekursif untuk
mencari n!...

Programnya adalah sebagai berikut:

#include<iostream>
float factorial(float n)
{

if(n>1)
return n*factorial(n-1);
else
return 1;
}
main()
{

float fac,n;
cout<<"\t\tMENCARI FAKTORIAL\n";
cout<<"input angka = ";cin>>n;
cout<<"\nMasukkan sebuah angka:\n ";
cin>>n;
cout<<"Faktorialdari "<<n<<" adalah "<<factorial(n)<<endl;
return 0;
}

Program diatas hanya terdiri dari 2 fungsi:
- factorial(float n)
- main()

Program di atas menggunakan user input, yaitu nilai-nilai di inputkan sendiri oleh user.
Pada baris ke empat (n > 1) statement fungsi, diperiksa apakah n lebih besar dari 1. Jika ya, maka fungsi factorial akan memangil dirinya sendiri dengan argumen n-1. Hal ini akan dilakukan secara terus menerus selama n lebih besar dari 1. Setelah n mencapai 1, maka kondisi if(n>1) ini bernilai salah dan fungsi factorial memberikan return value 1.

KASUS 5.2 MINGGU KE-5

Di bawah ini saya akan mencoba mengerjakan kasus 5.2 minggu ke-5 
 yaitu menentukan nilai terbesar dari 2 bilangan bulat.

Fungsi maksimum 2 (input a,b : integer):integer
Deskripsi
     if(a > b) then return a
     else return b

Programnya adalah sebagai berikut:

#include<iostream.h>
 double terbesar(double x,double y)
 {
 double maksimum = x;
 if (maksimum > y)
     maksimum = x;
     return (maksimum);
     }
 int main()
 {
 double a,b;
 a = terbesar(5.5, 10);
 b = terbesar(5,2);

 cout<< "a = " << a << endl;
 cout<< "b = " << b << endl;
 return (0);
 }

Program di atas memiliki dua buah argmen bertipe double dan memberikan
nilai balik bertipe double berupa bilangan terbesar diantara kedua argumennya.




TUGAS 3 PROGRAM MINGGUAN

Assalamu'alaikum teman-teman..
apa kabar...
semoga kalian selalu dalah lindungan Allah  SWT amien..
Kali ini saya akan memposting 3 program sederhana.
Yaitu cara menghitung:
  • volume balok
  • volume tabung,dan 
  • volume bola
Yang pertama yaitu cara  menghitung volume balok:
Program ini menggunakan Borland C++..
Di sini tipe data yang dipake adalah int atau integer.
Menggunakan cin dengan simbol >> karena kita 
menentukan angkanya sendiri dari keyboard.
Untuk menampilkan hasilnya kita menggunakan cout.

Contoh proramnya adalah sebagai berikut:

#include<iostream>
#include<conio>

int main()
{
int p,l,t,v;
cout<<"Masukkan Panjang = "; cin>>p;
cout<<"Masukkan Lebar = "; cin>>l;
cout<<"Masukkan Tinggi = "; cin>>t;
cout<<"Panjang balok = "<<p<<endl;
cout<<"Lebar balok = "<<l<<endl;
cout<<"Tingi balok = "<<t<<endl;
v=p*l*t;
cout<<"Volume balok = "<<v;
getch();
}


Yang kedua adalah volume tabung:
Sama seperi penjelasan diatas..
Hanya saja yang membedakan adalah rumusnya.

Contoh programnya adalah sebagai berikut:

#include<iostream>
#include<conio>
#define phi 3.14//untuk konstanta
//#include<math> untuk mengaktifkan pow (pangkat)

int main()
{
//const float phi=3.14; bisa juga konstanta seperti ini
float d,t,vol,r;
cout<<"Program mencari volume tabung\n";
cout<<"Masukkan diameter tabung = "; cin>>d;
cout<<"Masukkan tinggi tabung = "; cin>>t;
r=d/2;
cout<<"Jari-jari tabung = "<<r<<endl;
cout<<"tinggi tabung = "<<t<<endl;
vol=phi*r*r*t; //bisa juga di tulis vol=phi*pow(r,2)*t;
cout<<"Volume tabung = "<<vol;
getch();
}


Yang ketiga yaitu menghitung volume bola:
Penjelasannya juga masih sama yang diatas hanya saja beda rumusnya.

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

int main(){
float r,k,l,m, hasil;
cout<<"masukkan jari-jari:";
cin>>r;


cout<<"jadi volume bola adalah : ";
hasil = (3.14)*(4/3)*r*r*r;
cout<< hasil;


 getchar ();
 }

Itulah contoh-contoh sederhana program menghitung volume..
Apa bila ada yang salah mohon bantuan teman-teman untuk 
memperbaikinya yy...
Soalnya saya juga masih belajar..
:-)

Wassalamu'alaikum wr wb...












Minggu, 03 April 2011

Fuel Programming

This program is about to find out how much that you must pay or how many liter when you buy some fuel.
The simply explanation about this program is about choose the option. Then named the function like in step 8 to 11. In private you must declared the data types and the variables that you want (step 13 and 14). Closing the pombensin class with }; like in step 15.
In step 17, the statement that must choosing is in here. Its explaned about which one that user must be choose.
In step 25 if else statement is occurred. Its about which one that must choose, in liter or rupiah?
Then if user choose in liter, go to all of step 31 but if in rupiah then go to all of step  40. Finally result is depend on step 51 in int main.


1 #include <cstdlib>
2 #include <iostream>
3
4 using namespace std;
5
6 class pombensin{
7 public:
8 void awal();
9 void proses();
10 void liter();
11 void rupiah();
12 private:
13 int pilih;
14 double masukan,keluaran;
15 };
16
17 void pombensin::awal(){
18 cout<<”Pilihan anda :\n”;
19 cout<<”1. LITER\n”;
20 cout<<”2. RUPIAH\n”;
21 cin>>pilih;
22 proses();
23 }
24
25 void pombensin::proses(){
26 if(pilih==1){system(“cls”);liter();}
27 else if(pilih==2){system(“cls”);rupiah();}
28 else{cout<<”Pilihan tidak ada,!\n”;}
29 }
30
31 void pombensin::liter(){
32 cout<<”\n\nLITER\n\n”;
33 cout<<”Mau beli berapa liter,?\n”;
34 cout<<”-> “;
35 cin>>masukan;
36 keluaran=masukan*4500;
37 cout<<”Uang yang harus dibayar : “<<keluaran<<” rupiah”<<endl;
38 }
39
40 void pombensin::rupiah(){
41 cout<<”\n\nRUPIAH\n\n”;
42 cout<<”Mau beli berapa rupiah,?\n”;
43 cout<<”-> “;
44 cin>>masukan;
45 keluaran=masukan/4500;
46 cout<<”Anda membeli bensin : “<<keluaran<<” liter”<<endl;
47 }
48
49 int main(int argc, char *argv[])
50 {
51 pombensin pastipas;
52 pastipas.awal();
53
54 system(“PAUSE”);
55 return EXIT_SUCCESS;
56 }
Such a simple program, isn’t it? You can try in your stuff…..:))

PERSONAL TASK

This time I will be posting a program that prints the number is divisible by 3 and 5 between 1 to 100.

This program
#include <cstdlib>
#include <iostream>

using namespace std;

class angka{                                                            //the name of class

public:

int cara();                                                            //declared the data type and public name

private:

int hasil;                                                            //declared data type in private

};

int angka::cara(){                                           //data type of class::contructor

hasil=0;                                                           //for additional is zero

for(int i=1;i<100;i++){                                   //the loop

if(i%3==0 && i%5==0) {                              //If statement for the option

cout<<i<<endl;

hasil+=1;                                                      //write the formula

}

}

cout<<”Semua angkanya adalah: “<<hasil<<”buah”<<endl;
return hasil;                                                    //return to hasil function
}


int main(int argc, char *argv[])
{

cout<<”Bilangan antara 1-100 yang habis dibagi 3 dan 5 adalah:”<<endl;

angka agk;                                                                       //class name and objek
agk.cara();                                                                      //objek.cara

system(“PAUSE”);
return EXIT_SUCCESS;
}


Jumat, 01 April 2011

PERULANGAN FOR

secara umum bentuk pernyataan for adalah sebagai berikut:
for (inisialisasi_pencacah; pemutakhiran_pencacah)
{
pernyataan_1;
...
pernyataan_2;
}

Tanda {} bisa dibuang kalau hanya ada satu pernyataan yang berbeda di dalamnya.

contoh programnya adalah sebagai berikut:

#include <iostream.h>

int main()
{
int bilangan;

for (bilangan = 1; bilangan < 11; bilangan++)
cout << bilangan << endl;

return (0);
}

PERULANGAN DO WHILE

Pengulanan ini adalah kelanjutan dari posting sebelumnya yaitu tentang pengulangan,
yaitu tentang pengulangan Do While.
Secara umum bentuk umumnya sebagai berikut

do {
pernyataan_1;
...
pernyataan_2;
}while (kondisi);

Pada bentuk seperti ini bagian pernyataan yang berada dalam {} di jalankan
paling tidak sekali. Setelah dieksekusi, kondisi diuji. Pengulangan berakhir
setelah kondisi bernilai salah.

Contohnya adalah sebagai berikut:

#include <iostream.h>
int main()
{
int bilangan;
bilangan = 1;
do {
cout<< bilangan  << endl;
bilangan = bilangan  + 1;
}while (bilangan < 20);

return (0);
}