Kamis, 07 April 2011

Program konversi bilangan biner ke desimal dengan java


berikut ini adalah sebuah program sederhana yang berfungsi untuk konversi bilangan dari bilangan biner ke bilangan desimal dengan bahasa pemrograman java. 

public class konversi
{
public static void main (String[] args)
{
String bil = “110111″;
int[] arr_bil= new int[1000];
String[] st= new String[1000];
double hasil=0,result=0;
int a=0;
char t;
for(int i=0;i
{
t = bil.charAt(i);
st[i]=Character.toString(t);
}
for(int i=bil.length()-1; i>=0;i–)
{
arr_bil[a]=Integer.parseInt(st[i]);
hasil= arr_bil[a]* (Math.pow(2,a));
result=result+hasil;
a++;
}
{
int resultIn = (int)result;
System.out.println(”Bilangan integer : “+bil);
System.out.println(”Bilangan Desimal : “+resultIn);
}
}
}

dan ketika program di running, maka akan menampilkan :
Bilangan integer : 110111
Bilangan Desimal : 55

Minggu, 03 April 2011

Algorithm program to print a number that is divisible by 3 and 5 between 1 to 100


1. program will display the statement "a simple program displays a number between 1-100 is divisible by 3 and 5" to the user.
2. after the program returns to call the function process.
3. function check process will be repeated from 100-100 numbers are depleted in the 3 and 5. If the 1-100 number is divisible by 3 and 5 the remainder is o, then the program will display the number and save it as a number. If not the program will ignore these numbers. Repeated until the number 100 in checks. And reverse the total value to the main function as the number of numbers which can be divided into 3 and 5.
4. function reverses the process of value to the function main.
5. program displays the output to the user.


PROGRAM NYA:
#include <iostream.h>
 #include <conio.h>
 class bil{
 public:
 int proses();
 private:
 int total;
 };
 int bil::proses()
 {
 total=0;
 for(int i=1;i<100;i++){
 if(i%3==0 && i%5==0)
 {
 cout<<i<<endl<<endl;
 total+=1;
 }
 }
 cout<<"dan total bilangan ada : ";
 cout<<total;
 return total;
 }
 int main()
 {
 cout<<"program sederhana menampilkan bilangan antara 1-100 yang habis dibagi 3 dan 5"<<endl<<endl;
 getch();
 bil bagi;
 bagi.proses();

 return 0;
            }



simulation program to purchase fuel


task group:
1. Fadlillah mukti ayudewi (10018052)
2. Franecia Kartika (10018078)
3. Peni Sukma Nur Pratiwi (10018034)

simulation buy fuel with specifications:
Input form:
money / how many liters that will be purchased
Type of fuel to be purchased
Indicators will continue (increasing 0.1liter) for the total price / number of liters of fuel purchased not exceed demand
Output states:
The number of liters purchased (if the input in the form of money)
Total money to be paid (if the input in the form liter)

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

using namespace std;

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

class spbu (){
friend ostream& opreator<<(ostream&,spbu&); friend istream& operator>>(istream&,spbu&);
public :
void banyak();
void pilihan();
void hitung_liter();
void hitung_harga();
private :
int harga;
int Biaya;
int a,b ;
float hasil ;
float premium ;
float solar ;
float pertamax ;
};
void banyak::liter(){
cout<<"Masukkan berapa liter yang dibutuhkan : "; cin>>x;
}
void banyak::pilihan(){
cout<<"pilih 1 untuk premium\n"<<<"pilih 2 untuk solar\n"<<<"pilih 3 untuk pertamax\n"<<<"Masukkan pilihan : "; cin>>y;
}
void banyak::hitung_liter(){
float i = 0.0;
while(i <= x){
i = i + 0.1;
cout<<
}
}
void banyak::hitung_harga(){
float hasil = 0.0;
float premium = 4500;
float solar = 6000;
float pertamax = 8000;
if(y == 1)
hasil = x * premium;
else if(y == 2)
hasil = x * solar;
else if(y == 3)
hasil = x * pertamax;
cout<<"harga : "<<
}
void main(){
spbu :
banyak.banyak();
banyak.harga();
banyak.hitung_liter();
banyak.hitung_harga();


system("PAUSE");
return EXIT_SUCCESS;
}

java program to calculate the factorial


Award as the value of factorial is the result of the multiplication of positive integers less than or equal to the value N. Writing is usually a factorial: n!

berikut programnya :

import jeliot.io.*;


public class faktorial
{
public static void main (String[ ] args)
{
long limit = 20; // menghitung faktorial integer daeri 1 – 20
long faktorial = 1; // pendefinisian variabel faktorial

for (int i = 0; i <= limit; i++)
{
faktorial = 1;

for (int faktor = 2; faktor <= i; faktor ++)
faktorial *= faktor;
System.out.println (i + "!" + " adalah " + faktorial);
}
}
}

Sabtu, 02 April 2011

Menampilkan abjad A - Z dengan FOR dan DO-WHILE dalam C++

Pernyataan do-while juga dapat digunakan untuk menampilkan huruf abjad dari
a - z. Tentu saja ini termasuk kedalam perulangan. Perulangan juga dapat digunakan untuk hal seperti ini. Contoh dari program ini dapat kita  lihat pada syntax program berikut ini:

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

void main()
{
 char abjad = 'A';

 do
 {
  cout<<abjad<<" ";
  abjad+=1;
 }while(abjad <= 'Z');
 getch();
}


Selain menggunakan do-while, perulangan juga dapat digunakan dengan menggunakan pernyataan for. Perulangan menggunakan for, untuk menampilkan urutan abjad dari a sampai z. Contohnya dapat kita  lihat pada contoh syntax dibawah ini:

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

void main()
{
 char abjad;

 for(abjad = 'A'; abjad <= 'Z'; abjad++)
 {      
   cout<<abjad<<" ";
 }
 getch();
}

Semoga materi ini berguna buat kita semua.

simple C++ program

Let's use the code below to find what makes up a very simple C++ program - one that simply prints "Hello World!" and stops. Adjust your browser so you can see the text window below the code. Then point your mouse at different statements in the program.
Top of Form



            cout << "Hello World!" << endl;
            return 0;
     
Bottom of Form
You may wish to copy this program into your C++ programming editor and compile it, just for practice. Because this is a special display program, it is somewhat more tricky to copy than others in this tutorial. And if you are using Arachnophilia, be sure to use the new edit menu function "Paste Text." Note: You may notice I use the following line in most programs in this tutorial:
using namespace std;
   
This line disables the C++ namespace feature. Namespaces are an important feature of C++, but for tutorial purposes I have decided the clarity of the program listings is more important. Later on, the topic of namespaces will be discussed.
Discussion
Each C++ program consists of one or more functions. The function above, main(), is the only function that is required to be present in your program. Functions may or may not return a value. Although you may write a function to return anything or nothing --
string answerQuestion(string q)
{
            string a;
            if(q == "Please?") {
                        a = "Okay!";
            }
            else {
                        a = "You forgot the magic word!";
            }
            return a;
}
   
— the special function main() must return an integer.
Within functions, there are program statements. Here is a statement:
            a = "You forgot the magic word!";
   
Statements may be grouped together with braces ("{","}"). The braces identify groups of statements that are meant to be executed as a unit.