waktu(clocklink.com)

01 December 2014

Tutorial C++ : How to select channel

In this session, i will discuss very simple program, it's about how to select channel. I use C++ to make this program and use switch case to solve this problem.

Okey,let's see the source code :


#include<iostream>

using namespace std;

int main()
{
    int channel;
    cout<<"input number of channel: ";
    cin>>channel;
   
    switch(channel)
    {
                   case 1:
                   cout<<"TVRI\n";
                   break;
                   case 2:
                   cout<<"RCTI\n";
                   break;
                   case 3:
                   cout<<"SCTV\n";
                   break;
                   case 4:
                   cout<<"ANTV\n";
                   break;
                   case 5:
                   cout<<"METRO TV\n";
                   break;
                   default :
                   cout<<"no signal in that channel\n";
                   break;
                 
                 
    }
system("pause");
return 0;
}

---***-----
this is the analysis of codes:
#include<iostream>              //is library to determine cin(input) and cout(output)
int main()                              //this is the main program that will be execute
int channel;                                   //type is integer(number) and the name of variable is channel
cout <<"input number of channel: ";     //display "input number of channel: " to screen


cin>>channel;                              //if user enters number, the program scan that number as "channel"
switch(channel)                           //the variable that determines result is channel
case 1:
                   cout<<"TVRI\n";
                   break;                         //if input is 1,the output is TVRI
case 2:
                   cout<<"RCTI\n";
                   break;                         //if input is 2,the output is RCTI
case 3:
                   cout<<"SCTV\n";
                   break;                         //if input is 3,the output is SCTV
case 4:
                   cout<<"ANTV\n";     //if input is 4,the output is ANTV
                   break;
case 5:
                   cout<<"METRO TV\n";
                   break;                         //if input is 5,the output is METRO TV
default :
                   cout<<"tidak ada sinyal station tv di channel itu\n";
                   break;                         //if input is not between 1-5, output is "no signal in that channel"

system ("PAUSE");             //system will pause until user press a key
return 0;                        //it will end main function and the return value is 0(the program run correctly)

}


run this program and this is the result:


yeah,you got it?

27 November 2014

Tutorial C++ : How to determine positive, zero or negative number

In this session, i will discuss very simple program, it's about how to determine number. I use C++ to make this program and use if condition(if...else) to solve this problem.

Here is the source code :

#include<iostream>

using namespace std;

int main()
{
    int bil;
    cout<<"input number: ";
    cin>>bil;
   
    if (bil<0)
              {
              cout<<"negative\n";
              }
    else if (bil==0)
              {
              cout<<"zero\n";
              }
    else
              {
              cout<<"positive\n";
              }
       
system ("PAUSE");
return 0;

}

---***-----

i will analyze the meaning of that code.
#include<iostream>              //is library to determine cin(input) and cout(output)
int main()                              //this is the main program that will be execute
int bil;                                   //type is integer(number) and the name of variable is bil
cout <<"input number: ";     //display "input number: " to screen
cin>>bil;                              //if user enters number, the program scan that number as "bil"
 if (bil<0)
              {
              cout<<"negative\n";
              }
// if value of bil is less than 0, program will display negative

else if (bil==0)
              {
              cout<<"zero\n";
              }
// if value of bil is 0, program will display zero

else
              {
              cout<<"positive\n";
              }
// if value of bil is other, program will display positive to the screen.

system ("PAUSE");             //system will pause until user press a key
return 0;                        //it will end main function and the return value is 0(the program run correctly)

}

run this program and this is the result:



hope this tutorial is useful. . Keep trying!

24 November 2014

Tutorial Matlab


Kali ini saya akan membahas sedikit tentang cara menggunakan matlab. .Matlab ini saya gunakan untuk praktikum Aljabar Vektor Matriks. Langsung saja ke aplikasinya aja ya.

Misalnya saja membuat sebuah program,apabila kita menginputkan m=5 dan n=5 akan menghasilkan output :

1          2          3          4          5
2          4          5          6          4
3          5          6          7          3
4          6          7          8          2

5          4          3          2          1

Untuk menghasilkan output seperti itu, pertama-tama kita buka matlab, lalu masukkan source code m.file-nya seperti ini :


Agar lebih memahami maksud source code tersebut, mari kita analisis.Bila kita memasukkan nilai m=5 dan n=5, lalu kita lihat outputnya.

Pada baris pertama elemen-elemen matriks adalah 1 2 3 4 5
Untuk mendapatkan hasil tersebut,kita gunakan perintah  
                  if i==1  (pada baris pertama)
                          a(i,j) = j;  (nilainya sama dengan nomor kolom)
Pada baris terakhir  kita gunakan perintah
                  elseif i==m  (pada baris terakhir)
                          a(i,j) = n-v;  (nilainya sama dengan jumlah kolom dikurangi v)
                          v=v+1;  (v bertambah setelah perulangan)
akan tetapi,kita tentukan dahulu nilai v-nya yaitu  0.Ini artinya apabila kita memasukkan nilai m=5 maka pada
Eksekusi pertama n-v=5-0=>5      (baris 1 kolom 1)
setelah itu,bisa kita lihat ada perintah selanjutnya v=v+1 =0+1==>1, v sudah berubah menjadi 1 bukan lagi 0
Eksekusi kedua n-v=5-1=>4                     (baris 1 kolom 2)
Eksekusi itu berulang jadi pada eksekusi-eksekusi selanjutnya v berubah menjadi 2,3 lalu 4.dan ini menyebabkan nilai pada baris terakhir menjadi
5 4 3 2 1

Pada kolom pertama,hasilnya adalah
1
2
3
4
5
Untuk mendapatkan hasil tersebut,kita gunakan perintah 
                  if j==1
                          a(i,j) = i;
Pada kolom terakhir  kita gunakan perintah
                  elseif j==n
                          a(i,j)=  n-w;
                          w=w+1;
akan tetapi,kita tentukan dahulu nilai w-nya yaitu  1.Ini artinya apabila kita memasukkan nilai m=5 maka pada
Eksekusi pertama n-w=5-1=>5     (baris 2 kolom 5)karena baris 1 kolom 5 sudah terisi oleh perintah sebelumnya.
setelah itu,bisa kita lihat ada perintah selanjutnya w=w+1 =1+1==>2,w sudah berubah menjadi 2 bukan lagi 1
Eksekusi kedua n-w=5-2=>3                    (baris 3 kolom 5)
Eksekusi ini juga berulang jadi pada eksekusi-eksekusi selanjutnya w berubah menjadi 4.dan ini menyebabkan nilai pada kolom terakhir menjadi
5
4
3
2
1

Pada elemen-elemen matriks bagian tengah,bila kita amati nilainya adalah jumlah elemen matriks i dengan j,jadi kita gunakan perintah :
      else i==j
                  a(i,j) = i+j;

Semoga tutorial singkat ini bisa memberikan pencerahan. .