Rabu, 13 April 2011

Program C + + To Determine Passed / Not Passed

Ex matter: 1. create a program to determine whether a student is "Passed" or "No Pass" on the basis of Value Theory and Practice Value entered by the user. Terms of students would graduate if the average value of at least 60 and minimum value of Practice 55. Eg = 100 Value Theory, Practice Value = 50 then the result = Disqualified. For example, Value Theory = 40, Value Practice = 90 then the result is Passed. Seeing the above question, then we know that there are two inputs namely Value Theory and Practice Value. Students will be based on two things: the average value and value theory. So first we must find the average value of first is by adding up the value of theory and practice and then divided by two. Program C + + more to answer the questions above are as follows: # Include <iostream> # Include <conio.h>
void main () {clrscr (); float the theory, practice, rata2;
 
court <<"Enter the value of theory:";
 
cin>> theory;
 
court <<"Enter the value of practice:";
  
cin>> practice;
  
rata2 = (theory + practice) / 2;
 
if (rata2> = 60 & & practices> = 55) {
 
court <<"Passed";} else {
 
court <<"No Pass";}
 
getch ();}
Program Explanation: First we create 3 pieces of variables, namely the theory, practice and rata2, the three of us make with the float type data type can store fractional values. This is to anticipate when will the results of the division produces a float value. Furthermore, the program will ask for input from the user to the theory and practice. The next step the program will calculate the value rata2 ie the number of theory and practice are divided in two. Then by using the IF statement, the program will perform testing whether rata2 value of at least 60 and practice at least 55. Remember here in the IF part of the test using the operators AND, so the two expressions must be TRUE.
If the result is correct, it will display "Passed" and vice versa if it is wrong it will display the "No Passing".

Minggu, 10 April 2011

CASE 5.5 WEEK TO-5

Below is the program for the factorial function recursively
search n! ...

The program is as follows:

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

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

float fac, n;
court <<"\ t \ tMENCARI factorial \ n";
court <<"input number ="; cin>> n;
court <<"\ nEnter a number: \ n";
cin>> n;
court <<"Faktorialdari" <<n <<"is" <<factorial (n) <<endl;
return 0;
}

The above program consists of only 2 functions:
- factorial (float n)
- main ()

The program above using the user input, ie the values ​​in the fed itself by the user.
In the fourth row (n> 1) a statement of function, check if n is greater than 1. If yes, then the factorial function will memangil itself with the argument n-1. This will be done continuously for n greater than 1. Once n reaches 1, then the condition if (n> 1) This is false and the factorial function returns the value 1.

case of 5.2-5 weeks

case of 5.2-5 weeks
  which determines the largest value of 2 integers.

Maximum function 2 (input a, b: integer): integer
Description
      if (a> b) then return a
      else return b

The program is as follows:

# include <iostream>
  The biggest double (double x, double y)
  {
  double maximum = x;
  if (maximum> y)
      maximum = x;
      return (maximum);
      }
  int main ()
  {
  double a, b;
  a = largest (6.5, 20);
  b = largest (4.5);

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


The program above has two argmen of type double and give
the return value of type double form the largest number among the second argument.

Program C++ Untuk Menentukan Lulus/Tidak Lulus


Ex soal :
1.   buatlah program untuk menentukan apakah seorang mahasiswa “Lulus” atau “Tidak Lulus” berdasarkan Nilai Teori dan Nilai Praktek yang diinputkan oleh user. Syarat mahasiswa akan Lulus jika nilai rata-rata minimal 60 dan Nilai Praktek minimal 55.
Misal Nilai Teori = 100, Nilai Praktek = 50 maka hasilnya = Tidak Lulus. Misalnya Nilai Teori = 40, Nilai Praktek = 90 maka hasilnya Lulus.
Melihat soal diatas, berarti kita mengetahui bahwa inputnya ada dua yaitu Nilai Teori dan Nilai Praktek. Mahasiswa akan berdasarkan dua hal yaitu nilai rata-rata dan nilai teori. Jadi sebelumnya kita harus mencari nilai rata-rata terlebih dahulu yaitu dengan menjumlahkan nilai teori dan praktek lalu dibagi dua. Program C++ selengkapnya untuk menjawab pertanyaan diatas adalah sebagai berikut :
#include <iostream.h>
#include <conio.h>

void main(){    clrscr();
float teori, praktek, rata2;
 cout<<"Masukkan nilai Teori : ";
 cin>>teori;
 cout<<"Masukkan nilai Praktek : ";
  cin>>praktek;
  rata2 = (teori + praktek) / 2;
 if(rata2 >= 60 && praktek >= 55)    {
 cout<<"Lulus";    }    else    {
 cout<<"Tidak Lulus";    }
 getch();}

Penjelasan Program :
Pertama-tama kita membuat 3 buah variabel yaitu teori, praktek dan rata2, ketiganya kita buat dengan tipe float yaitu tipe data yang dapat menyimpan nilai pecahan. Hal ini untuk antisipasi jika nanti hasil pembagian menghasilkan nilai pecahan. Selanjutnya program akan meminta inputan dari user untuk teori dan praktek.
Langkah selanjutnya program akan menghitung nilai rata2 yaitu jumlah teori dan praktek dibagi dua. Lalu dengan menggunakan pernyataan IF, program akan melakukan pengujian apakah nilai rata2 minimal 60 dan praktek minimal 55. Ingat disini bagian pengujian pada IF menggunakan operator DAN, jadi kedua ungkapan harus bernilai TRUE.

Jika hasilnya benar, maka akan ditampilkan “Lulus” dan sebaliknya jika salah maka akan ditampilkan “Tidak Lulus”.

Sabtu, 09 April 2011

Contoh Pernyataan For Sederhana Dalam Program C++


Dalam bahasa pemrograman C++ untuk melakukan perulangan (looping) yang paling umum digunakan adalah pernyataan For. Pernyataan For berguna untuk melakukan perulangan (looping) terhadap satu atau sejumlah pernyataan.
Contoh sederhana adalah untuk menampilkan tulisan echa sebanyak 8 kali, seperti contoh program dibawah ini :
01
#include <iostream.h>
02
#include <conio.h>
03

04
void main()
05
{
06
    clrscr();
07
    int i;
08
    for(i=0; i<8; i++)
09
    {
10
        cout<<"echa"<<endl;
11
    }
12
    getch();
13
}
Penjelasan Pernyataan For Sederhana Dalam Program C++ diatas :
Mula-mula kita membuat sebuah variabel baru yaitu i dengan tipe integer. Dalam pernyataan for, i diberi nilai awal yaitu 0. Kemudian dilakukan pengujian apakah i<8, karena hasilnya true maka pernyataan di dalam For dijalankan. Kemudian dilakukan increment terhadap i dalam pernyataan i++. Selanjutnya dilakukan pengujian lagi apakah i<8. Jika iya (true) maka pernyataan di dalam For dijalankan, jika tidak maka program dilanjutkan ke bawah For. Begitu seterusnya hingga pengujian i<8 bernilai false.

Outputnya :


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