Share

[Buat wdget]
0

SKA


oin bullet...

Menghabiskan waktu bersama melakukan hal-hal yang disukai secara kolektif adalah ciri sebuah komunitas. Yang paling penting adalah adanya kesamaan yang membuat lebih dari satu manusia berinteraksi, satu sama lain dan menjadi sebuah kelompok dan menghasilkan sesuatu yang dapat dimanfaatkan bagi diri sendiri ataupun orang lain. Manusia butuh berkelompok, sudah dari sananya. Band adalah salah satu kesempatan untuk memuaskan keinginan manusia untuk berkelompok.



Noin Bullet adalah band Ska yang berasal dari kota kembang, noone can change that! Ini adalah band yang bersama sejak tahun 1997. Waktu itu, sahabat karib; Herul dan Tomi Londok terlalu sering jalan bareng menghabiskan waktu sampai berpikir yang ngga-ngga; bikin band! Damn, reality bites baby, berawal dari kesepakatan bahwa being in the band is cool, dan tau-tau sudah 7 tahun terlewati. Pada masa pencarian jati diri, line-up awal hanya tahu untuk membuat lagu, sampai akhirnya mentok ke arah musik seperti yang dimainkan 311. Setelah diperkenalkan teman-teman di komunitas punk rock Bandung kepada band thirdwave Mighty-Mighty Bosstones, band ini semakin yakin dengan apa yang mereka inginkan yaitu bermain musik ska. Mulai ditemukannya jati diri band ini diikuti oleh masuknya Hadi, sebagai vokalis kedua, yang tak lain merupakan adik kandung Herul sendiri.



1997 : Kemunculan Noin Bullet

Ketika itu musik mereka hanya berada di sekitar up-stroke picking gitar dan sudah merasa cukup ska. Semakin lama bersama, semakin mereka meng-eksplore arah musikal mereka. Saat itu mulai terasa dibutuhkannya brass section dan mereka pun merekrut beberapa pemain alat musik tiup. Lagu-lagu awal mereka adalah Yesterday Cookies dan Bakakak Hayam. Tawaran show pun berdatangan luar biasa, panggung demi panggung pun mereka lewati.



1998 : All Can “SKA” Can All (Debut Album indie Noin Bullet)

Orang-orang mulai demam musik ska, dan Noin Bullet pun menjadi tokoh sentral di tanah air pada saat itu. Demo tape mereka yang dipasang di GMR FM saat itu menjadi tonggak hingga mereka sampai ke pencapaian mainstream. Pada tahun ini, Noin Bullet dapat menghasilkan sebuah mini album ALL CAN SKA CAN ALL yang yang di produseri oleh Herul dan tanpa ampun terjual hingga 1500 keping dalam waktu 3 minggu. Tak lama, Warner Music Indonesia tertarik dan menawarkan kontrak melalui Richard Mutter dan Ambar sang legenda dan merekapun menandatangani perjanjian dengan perusahaan rekaman dengan network yang sangat luas itu.



1999 – 2000 : BEBAS (Album pertama Noin Bullet di major label)

Pada tahun 1999 album major label debut mereka rilis dan album BEBAS yang laris manis di pasaran membuat akhir pekan personil Noin Bullet tak pernah kosong. Mereka hidup di jalan. Walhasil, Noin Bullet adalah grup musik yang sangat diperhitungkan. Seperti biasa industri melakukan eksploitasi habis-habisan, mumpung saat itu ska sedang bisa dijual dan Noin Bullet pun selain mendapat keuntungan tentunya mendapat imbas negatif. Antipati mulai muncul di panggung-panggung mereka, meski pelakunya minor, tetapi tetap menganggu. Kebayang, kamu yakin betul dengan apa yang kamu lakukan tetapi tiba-tiba muncul manusia yang bahkan kamu tidak kenal marah bahkan sangat marah atas apa yang kamu lakukan. Apapun alasan mereka, tetap saja terasa menyakitkan. Sepertinya semua yang kita lakukan tidak ada yang benar dan hidup kita ini salah. Tetapi sebaliknya, pasar merespon dengan sangat manis dan album BEBAS terjual hingga 65.000 kopi.



Tour yang mereka lakukan sepanjang masa promosi benar-benar luar biasa. Kota besar dan kota kecil mereka kerjakan sampai habis. Sebutlah Cirebon, Solo, Semarang, Jogja, Surabaya, Malang, Bali, Medan, Tegal, Tasikmalaya, Sukabumi, Purwakarta, Cianjur dan tentunya Jakarta sudah merasakan semangat Noin Bullet. Jadi mereka sudah cukup melanglang buana, imbas positif dari eksploitasi ska besar-besaran di industri musik Indonesia. Di tahun 2000 mereka juga menandatangani kontrak perjanjian dengan perusahaan pakaian lisensi dari Australia, Quiksilver yang membantu mereka memberikan outfit untuk penampilan mereka.



Anak-anak ini begitu sibuk dan menikmati manisnya menjadi band yang dipanggil manggung dimana-mana sampai tidak sadar bahwa deadline album kedua sudah hampir tiba. Seluruh tenaga yang tersisa dikumpulkan untuk menghasilkan album berdurasi 50 menit yang diharapkan layak untuk dijual menurut kacamata industri. Dalam waktu 2 bulan terciptalah seluruh materi untuk album baru mereka di tengah-tengah kesibukan manggung dan kegiatan promosi lainnya. Produksi album dimulai pada akhir tahun 2000.



2001 : MANUSIA (Album kedua Noin Bullet di major label, are we cursed ?)

Di tahun ini album kedua mereka yang berjudul MANUSIA rilis ke pasaran, album yang terasa lebih dalam dalam penggarapannya ini tidak diikuti oleh respon pasar. Ternyata pasar sudah kembali ke orbitnya semula. Bahkan sepertinya mereka tidak pernah mengenal musik ska, mereka tidak suka ska. Walhasil album ini hanya bisa terjual 15.000 kopi saja. Label pun sudah ogah-ogahan memberikan support promosi. Serangan dan tekanan bertubi-tubi itu diikuti oleh permintaan panggung yang tiba-tiba turun. Jika sudah begini, pada akhirnya band yang selalu disalahkan, selalu begitu… are we cursed?



Setelah sampai di masa tersebut, anak-anak yang sudah sempat menjadi seperti keluarga ini mulai jenuh berkumpul karena kurangnya kegiatan. Mereka mulai mencari kesibukan sendiri. Mereka bosan. Dampak dari penonton ricuh masih terasa begitu menyakitkan. Penghasilan band pun sedikit demi sedikit berkurang dan akhirnya sampai satu persatu personil menyatakan mengundurkan diri dari band. Tahun 2001 adalah tahun suram untuk ska, tahun suram untuk Noin Bullet. Sepertinya benar, ska mati.



2002 – 2004 : Single Ngga Usah Rusuh, dari Noin Bullet untuk PERSIB dan Viking

Ketika semua sedang lesu tiba-tiba datang tawaran untuk ikut serta dalam kompilasi A Tribute To Persib, klub sepakbola kecintaan warga Bandung. Personil yang tersisa setuju untuk ikut serta. Dan terciptalah single Ngga Usah Rusuh. Lagu ini memberikan lonjakan musikal yang cukup signifikan. Dub dan reggae sebagai elemen musikal yang sangat penting bagi lahirnya musik ska sangat berpengaruh pada terciptanya lagu ini. Bersamaan dengan single ini pula Noin Bullet membuktikan bahwa ska itu masih hidup dan ska bukan hanya masalah brass section dan up-stroke picking guitar. Ada keyakinan bahwa band mau memainkan musik apa saja, meskipun sudah tidak ‘in’ tetapi jika band itu memiliki sesuatu, akan tetap stand out di tengah-tengah band dan gejolak musik yang baru muncul. Mengapa band ini ikut di kompilasi tersebut, alasannya? Kangen nge-band. Sesimple itu untuk member yang lain kecuali Herul. Herul yang juga dipanggil ‘mas’ inipun terus berjuang untuk menyelamatkan Noin Bullet. Herul terus saja menciptakan lagu untuk Noin Bullet. Hasil dari eksplorasinya mengantarkan kepada kenyataan bahwa dub bukan soul dari Noin Bullet. Noin Bullet bukan anak pantai, Noin Bullet anak gunung. Noin Bullet itu bukan dub, Noin Bullet itu ska.



Untuk memperkaya khasanah musikalnya, Herul terus saja menambahkan vibe dari musik lain ke dalam lagu-lagu ciptaannya, seperti swing yang juga sangat mempengaruhi band-band klasik ska dan two tone, seperti sang legenda, The Specials. Kemudian juga mencampurnya dengan nuansa dub dari band seperti Long Beach Dub Allstar dan 311. Noin Bullet semakin yakin dengan ska dan semakin menemukan alasan yang tepat untuk mencampurkan aransemen musik ska klasik hingga modern menjadi musik Noin Bullet sekarang ini. Ada proyek skankin’ yang harus diselesaikan, Noin Bullet yang akan menyelesaikannya.



2006 – 2011 : RISE UP 3-Nation Compilation

Walaupun ditahun ini nama Noin Bullet seakan tenggelam. Ternyata lagu “Pagi Hari” dan “Sambutlah” dapat menjadi bagian tak terpisahkan dalam track list album RISE UP 3-Nation Compilation yang di produksi oleh Subciety Records bersama dua rekan dari Bandung yaitu Subkultur dan Dirty Dolls, serta Apollo 10 dari Yogyakarta. Ada juga 3 band dari luar negeri yaitu The Palookas dari Belanda dan juga Open Season dan Plenty Enuff dari Swiss.



Dengan minimal personil yang tersisa, Noin Bullet ternyata mencoba tetap bertahan dengan ska khas Noin Bullet. Pada Maret 2011 yang lalu, Noin Bullet kembali mengisi track list dalam kompilasi yang di produksi oleh NEPS Sound Bandung dengan lagu Aku Dan Kamu, yang segera di rilis melalui jalur indie. Bukti eksistensi mereka juga tercurah dalam event “Mari Berdanska” di Setiabudi Bandung pada Desember 2011 lalu bersama thePAPS, Monkey Boots, Don Lego dan banyak lagi.

0

Orkestra Ska ala Bandung


Orkestra Ska ala Bandung

Megah dan ramai, itulah yang pertama bakal kesebut kalau kita ngedenger band yang satu ini. Band Ska asal Bandung ini banyak mendapat influence dari TSPO (Tokyo Ska Paradise Orchestra) yang emang mengedepankan instrument dan nuansa orsektra di setiap aksinya.

Band yang berisi 9 orang ini merupakan kumpulan anak-anak muda yang awalnya adalah penikmat Ska di generasi sebelumnya dan akhirnya memunculkan diri sebagai pelaku Ska. Riksa (Vokal), Endrow (Gitar), Ebef (Bass), Rundie (Drum), Ferdi (Trumpet), Ndik (Trombone), Apink, Ivan serta Opik (Alto Saxophone) adalah pemain-pemaion yang meramaikan band ini.

Tahun 2006 Inikami lahir disaat Melodik Punk sedang booming di Bandung. Awalnya inikami masuk pada jajaran kelas 3rd wave tapi makin lama mereka lebih nunjukin sisi instrumennya. Untuk kedepan punya cita-cita buat memasukan unsur blues dan keroncong di formasi barunya ini.

“Kita sih pede aja sama setiap penampilan kita. Pede sama band ini pokonya pede ajalah. Kita nggak pernah pesimis sama scene Ska yang naik atau turun. Pokonya konsisten aja lah” cerita Ndik

Lagu berjudul Get Ska yang jadi single band ini sempet jadi nomer satu di radio-radio anak muda di Bandung selama beberapa minggu. Sekarang ini lagu-lagu baru berjudul Jarak Jauh, Kupu-kupu Kaca dan Revolusi Diri siap digelontorkan untuk para fans mereka. Buat mereka saat musik mereka di apresiasi maka mereka udah nunjulin eksistensi mereka dan dengan bangga menyebut “Inikami”

0

ska rocksteady


Rocksteady

Rocksteady adalah musik anak laki-laki kasar Jamaika pada pertengahan 1960-an, ketika The Wailers dan The Clarendonians mendominasi tangga lagu. Desmond Dekker "007" membawa perhatian internasional untuk genre baru. Campuran menitikberatkan inovasinya pada garis bass, sebagai lawan bagian tanduk kuat ska, dan ritme gitar mulai bermain pada optimis. Sesi musisi seperti Supersonics, Vendor Soul, Jets dan Jackie Mittoo (dari Skatalites) menjadi populer selama periode ini.
http://arrafibluefire.blogspot.com/
0

Empat Cara Terampuh Menebak Siapa yang Kentut


Empat Cara Terampuh Menebak Siapa yang Kentut


Di suatu siang yang cerah, kamu baru aja balik makan siang sama temen-temen kamu. Terus kamu sekarang ceritanya lagi naek lift/mobil atau apapun pokoknya yang berupa ruangan sempit dan tertutup. Keadaan saat itu lagi menyenangkan. Kamu asik mengobrol dan bersenda gurau dengan teman-teman. Dunia rasanya indah sekali. Namun tiba-tiba….




Muncul bau busuk yang sangat memuakkan dan memualkan. Entah dari mana asalnya, tanpa suara, dan tanpa bentuk. Senyum di muka kamu dan teman-teman langsung terhapus dan tergantikan oleh dahi yang mengerenyit, mata yang memicing, dan napas yang ditahan. Semua diam tak ada yang bersuara, tak ada yang berkomentar, namun kalian semua tahu, bahwa salah satu dari kalian baru saja kentut.
Sebelum kalian saling menuduh, menunjukkan jari dan memaki yang akhirnya akan menghancurkan persahabatan kalian, mendingan baca dulu nih, MBDC bakal ngasi tau gimana caranya mengetahui siapa yang barusan kentut. Enjoy…

1. Analisa BauHirup aroma kentut yang memenuhi udara sekitar kamu dalam-dalam, dan coba cerna, bau apakah itu ? Lalu ingat-ingatlah temen kamu tadi abis makan apa aja. Kentut orang yang abis makan pecel lele tentu beda dengan yang abis makan nasi padang. Apalagi yang abis makan ubi atau pete.
Cara analisa bau ini adalah cara yang paling ampuh, tapi juga paling susah. Ada beberapa orang yang memang terlahir dengan daya penciuman yang tajam, tapi kalo kamu cuma orang biasa jangan putus asa, kamu bisa berlatih dengan menganalisa kentut kamu sendiri, setelah makan makanan yang berbeda.

2. Puji KentutnyaSiapa sih yang nggak seneng dipuji. Orang yang kalo dipuji trus malah marah juga sebenernya dalem hati seneng. Nah, pujian juga bisa jadi cara yang ampuh untuk mengetahui siapa yang kentut. Pujian buat kentut seseorang juga bermacam ragam, misalnya ada bau-bau comberan campur kecoa mati, trus kamu komentar aja:

“Eh siapa yang barusan nyemprot pewangi ruangan? Kok tau-tau bau mahogany lavender gini?”atau..

“Ini parfum siapa nih tau-tau kecium? Baunya ngingetin gue ama kebun bunga pas gue liburan kemaren”Dengan memuji kentut seseorang, dia pasti bakal merasa senang, dan mungkin bakal ngaku. Kalo nggak ngaku sekalipun, pasti dia bakal senyum-senyum sendiri, sumringah gitu gara-gara kentutnya dipuji. Terus kamu bisa tau sendiri siapa yang kentut.
Cara ini sebaiknya jangan sering-sering dilakuin, karena bisa jadi yang kentut malah kegeeran, terus dia malah kentut terus-terusan.

3. InterogasiPasti diantara temen-temen kamu, ada yang terkenal jorok dan yang udah-udah sih kalo ada kasus kentut-lari (kentut terus kabur nggak ngaku -red) biasanya dia tersangka utama atau terdakwanya. Kamu coba aja interogasi temen-temen kamu, sok-sok detektif gitu. Tanyain apakah mereka abis makan sesuatu yang bikin lambung penuh gas, atau ada yang emang lagi masuk angin. Coba inget-inget kejadian yang terjadi sampai keluarnya kentut tersebut, ada yang tiba-tiba diam dan merubah posisi pantat atau enggak. Apakah temen-temen kamu punya alibi yang bisa dipertanggung jawabkan. Apakah temen kamu punya motif untuk kentut, dan sebagainya.
Banyak variasi dari cara interogasi ini. Kamu bisa coba cara good cop bad cop dengan temen kamu yang kamu percaya banget bukanlah oknum yang kentut. Ato kamu juga bisa fokusin interogasi sama satu orang, dan kamu galakin dia sampe nangis-nangis gitu, nanti yang kentut akhirnya merasa iba dan ngaku karena nggak tega. Gitu deh.

4. Pura-Pura PingsanJelas lah ya. Kamu pura-pura pingsan aja gitu gara-gara saking baunya itu kentut. Terus nanti yang kentut bakal ngerasa bersalah dan ngaku. Lebih seru lagi kalo kejadian kentutnya di mobil, dan kamu yang nyetir. Nanti kamu pura-purang pingsan dan akhirnya kecelakaan. Terus nanti bisa adegan dramatis a la sinetron gitu “GARA-GARA KENTUT LO, KITA SEMUA KECELAKAAN !” Wuih. Seru kan.
Nah, sekarang udah tau kan cara nebak siapa yang kentut. Sekarang terserah kamu, mau diapain tuh yang kentut sembarangan


0

C++

C++

Input Validation Using While Loop and Do While Loop

Looping is also used for input validation. Input validation is a process where you check whether the user is inputting the valid data or not. A user may input anything and that can make the program to behave unexpectedly.
For eg. If you create a program that takes various subject's marks as input from user and then calculates and displays total and average of those marks. Suppose that every subject was of 100 marks and so the student can score anything from 0 to 100. So if the user starts inputting more than 100 marks or less than 0 marks then the result of this will be unexpected.

The user may do mistake unintentionally or intentionally. If he does unintentionally then we should show him his mistake and then tell him to correct it . If he does intentionally then he will see that our program is smart enough to understand his mistakes.
Input validation is also necessary for security reasons as well and it can be very lengthy in real world programs, where each input is tested with various conditions. However, here i present you some easy programs to make you understand how we can make use of while and do while loop for input validation. The below three programs will accept input from user only if the numbers are from 1 to 9. Greater than 9 and less than 1 will not be accepted. To understand these programs, you must know The Difference Between While Loop And Do-While Loop

/* A c++ program example that uses while loop for input validation */


// Program 1

#include <iostream>

using namespace std;

int main ()
{
    int number;

    cout << "Enter a number from 1 to 9: ";
    cin >> number;

    while (! (number >=1 && number <= 9 ))
    {
        cout << "Invalid Input. Try Again." << endl;
        cout << "Enter a number from 1 to 9: ";
        cin >> number;
    }

    cout << "Your Input Is Valid." << endl;

    return 0;
}

/* A c++ program example that uses do-while loop for input validation */


// Program 2

#include <iostream>

using namespace std;

int main (){
    int number;

    do
    {
        cout << "Enter a number from 1 to 9: ";
        cin >> number;

        if (! (number >=1 && number <=9 ))
        {
            cout << "Invalid Input. Try Again." << endl;
        }
    } while (! (number >=1 && number <=9 ));
  
    cout << "Your Input Is Valid." << endl;

    return 0;
}

/* A c++ program example that uses do-while loop with data-type bool for input validation */


// Program 3

#include <iostream>

using namespace std;

int main ()
{
    int number;
    bool isValid = false;

    do
    {
        cout << "Enter a number from 1 to 9: ";
        cin >> number;
        isValid = ( number >=1 ) && ( number <=9 );

        if (isValid)
        {
            cout << "Your Input Is Valid." << endl;
            break;
        }

        else
        {
            cout << "Invalid Input. Try Again." << endl;
        }
    } while (!isValid);

    return 0;
}

Explanation And Clarification

while (! (number >=1 && number <= 9 )) can also be written as:
while (! (number > 0 && number < 10 ))
Since, 'greater than zero' is same as 'greater than or equal to 1'.
And, 'less than 10' is same as 'less than or equal to 9'.

The above while loop condition was written using AND with NOT operator. It can also be written using OR operator and will work same as above.
while (number <= 0 || number >=10 )
OR
while (number < 1 || number > 9 )






Please do comment if you don't understand any part or want to know more or just want to say thanks. I love programming and love to teach my friends. Your suggestions and appreciation will make this blog much better.
Want to learn more? View List Of All Chapters 

Tuesday, November 15, 2011


The goto statement in c++

The goto statement in c++


We have gone through the while loopfor loop and do-while loop. The another way to do loop in c++ is through using the goto statement. The goto statement was used in olden days but it is not suitable for creating modern applications. But since c++ supports it, you should have knowledge about it, as you may encounter a c++ source code containing goto statements, in that case you will know what it is and how it works.

How the goto statement works?


It consist of label and statements that comes under that label. A label is named by you and it is followed by a colon sign (:). During execution of program, when goto is encountered, it jumps to the statements that comes under the label specified by goto statement. To get a clear idea, analyze the below program example.

/* A c++ program example that uses goto statement to display number from 0 to 9 */



#include <iostream>

using namespace std;

int main ()
{
    int i=0;

loop:
    cout << i << endl;
    i++;

    if (i<10)
        goto loop;

    return 0;
}

Why goto should not be used?


The use of goto should be `voided to make the program more readable and reliable. The goto statement can cause the program execution to jump to any location in source code and in any direction backward or forward. This makes the program hard to read and understand and also makes it difficult to find bugs.
Since now we have more tightly controlled and sophisticated loops like while loopfor loop and do-while loop, the use of obsolete statement like goto is not at all recommended in creating loops.

Tuesday, October 25, 2011


Repetition Statement: The Do-While Loop in c++

Repetition Statement: The Do-While Loop in c++


We have already gone through The While Loop and The For Loop. Now its time for The Do-While Loop.

/* A c++ program example that uses do-while loop to display number from 0 to 9 */


// Program 1

#include <iostream>

using namespace std;

int main ()
{
    int i = 0;
    do
    {
        cout << i << endl;
        i++;
    } while (i < 10);
    return 0;
}



The do-while loop works just like the for loop and while loop but with one exception. Unlike the for loop and while loop, the do-while loop will execute at least once.
The for loop and the while loop checks the condition and then the body of loop executes but in case of do-while, the body is executed first and then it checks the condition.

/* A c++ program example that demonstrates how do-while loop distinguishes from the for loop and while loop */


// Program 2

#include <iostream>

using namespace std;

int main ()
{

    // The while loop
    int i = -1;
    while (i != -1)
    {
        cout << "Inside the while loop. " << endl;
        cout << "Please enter a number or -1 to quit: ";
        cin >> i;
    }

    // The for loop
    int j = -1;
    for (; j != -1; )
    {
        cout << "Inside the for loop. " << endl;
        cout << "Please enter a number or -1 to quit: ";
        cin >> j;
    }

    // The do-while loop
    int k = -1;
    do
    {
        cout << "Inside the do-while loop. " << endl;
        cout << "Please enter a number or -1 to quit: ";
        cin >> k;
    } while (k != -1);

    return 0;

When you run the above program, only the body of do-while gets executed and others do not. The initial value is set to -1 and the condition is such that the value should not be equal to -1. The for loop and while loop checks the condition first and hence their body is not executed, the do-while loop executes the body first and hence it gets executed even though the condition is false, as it checks the condition after executing the body.

Use Do-While when you want the body of the loop to execute at least once, even if the condition is false at the start or else you could make use of the for loop and while loop.

Thursday, June 23, 2011


Repetition Statement: The For Loop in c++

Repetition Statement: The For Loop in c++


To understand this you must first go through The While loop in c++.
The below program, Program 1 does the same thing that the Program 1 of previous chapter The While Loop does. An integer i is declared and then three expression of the loop: initializer, loop-test and counting expression, all are passed as parameters in for loop. The variable i is initialized to 0 then it will test the condition whether the value of i is less than 10. If the condition is true, the body of loop will execute. The incrementation statement will be last statement to be executed by the for loop.

/* A c++ program example that uses for loop to display number from 0 to 9 using incrementation in the loop */


// Program 1

#include <iostream>

using namespace std;

int main ()
{
    int i;

    for (i=0; i<10; i++)
    {
        cout << i << endl;
    }

    return 0;
}

If you are just going to use the variable within the body of loop, then better declare it in the for loop itself. This will make your program more reliable. The below programs declare variable in the for loop.

/* A c++ program example that uses for loop to display multiplication of 8*/


// Program 2

#include <iostream>

using namespace std;

int main ()
{
    for (int i=8; i<=80; i+=8)
        cout << i << endl;

    return 0;
}

/* A c++ program example that tells you whether the number is even or odd. Number ranges from 1 to 20. */


// Program 3

#include <iostream>

using namespace std;

int main ()
{
    for (int i=1; i<=20; i++)
    {
        if (i%2==0)
            cout << i << "is an even number." << endl;

        else
            cout << i << "is an odd number." << endl;
    }

    return 0;
}

The operator "%" is called the remainder/modulo operator as already been described in Mathematical Operators. The statement i%2==0 simply means that the remainder of i divided by 2 equals to 0.

/* A c++ program example that uses for loop to diplay the square root and cube of numbers from 1 to 10. */


// Program 4

#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
    cout << "Number " << "Square " << "Cube" << endl;

    for (long i=1; i<=10; i++)
    {
        cout << setw (2) << i << setw (8)
        << i*i << setw (8) << i*i*i << endl;
    }

    return 0;
}

/*A c++ program example that displays multiplication table of a number provided by the user.*/


// Program 5

#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
    int number;

    cout << "Enter a number to get its multiplication table: ";
    cin >> number;
    cout << endl;
    cout << "-------------" << endl;

    for (int i=1; i<=10; i++)
  :  {
        cout << number << " x " << setw (2) << i << " = "
        << setw (3) << number*i << endl;
        cout << "-------------" << endl;
    }

    return 0;
}

Monday, May 23, 2011


Repetition Statement: The While Loop in c++

Repetition Statement: The While Loop in c++


The fundamental to programming are control statements. You must learn to have good command over control statement, if you want to program.
Sequence, selection and repetition are three types of control statement. It specifies the order in which the statement are executed.

(1) Sequence Structure: The sequence structure is built into c++. The c++ statement are executed in sequence, that is one after the other if not directed otherwise. Hope you know this. If not then remember from now on.

(2) Selection Statement: Selection statement are of three types: if, if-else and switch statement. We have already learned these in previous chapters.

(3) Repetition Statement: Repetition statement are of three types: while loop, for loop and do-while loop. We have to learn about these in this and coming chapters.

In programming, often the situation arises in which you have to repeatedly execute a particular code or set of codes. Suppose you want to print your name to the console five times. What you will do? If you have no knowledge of repetition statement, you will write your name in cout 5 times. Something like below:

/* A c++ program example that should have been written using repetition statements */


// Program 1

#include <iostream>

using namespace std;

int main ()
{
    cout << "Mohammed Homam" << endl;
    cout << "Mohammed Homam" << endl;
    cout << "Mohammed Homam" << endl;
    cout << "Mohammed Homam" << endl;
    cout << "Mohammed Homam" << endl;

    return 0;
}

But what if you have to print it 100 or 1000 times? It would be bothersome and also the code will be too lengthy if we use the above method. To simplify such task we use repetition statement.

The While Loop



/* A c++ program example that uses while loop to print the name 5 times using incrementation in the loop */


// Program 2

#include <iostream>

using namespace std;

int main ()
{
    int i = 0;
    while (i < 5)
    {
        cout << "Mohammed Homam" << endl;
        i++;
    }


    return 0;
}

Now lets analyse that what's happening in the above program. Look at the program while reading the each statement of explanation. We declared an integer i and intialised it to 0. After that while loop checks whether i is less than 5. Currently the value of i is 0 and hence the condition i<5 is true. Since the condition is true, the body of while is executed. The body of while loop contains two statement: one that displays the name and other that increments the value of i by 1. After executing the increment statement, now the new value of i is 1. The while loop will again check the condition and since 1 is less than 5 the body of while will execute again. This will go on until the value of i is incremented to 5. Once the value of i is 5, the condition will become false as a result of which the body of loop won't execute and will terminate.

What's the use of increment statement in the above program?
If you don't increment the value of i in the above program, then value of i will always be 0 and hence the condition i < 5 will also be always true. It means your loop will never stop, it will go on and on. This is called infinite loop. Try this by removing i++; from above program. Compile and run it again. Press ctrl+c to terminate the program.

/* A c++ program example that uses while loop to print the name 5 times using decrementation in the loop */


// Program 3

#include <iostream>

using namespace std;

int main ()
{
    int i = 5;
    while (i > 0)
    {
        cout << "Mohammed Homam" << endl;
        i--;
    }

    return 0;
}


The above program does the same thing as its above program. The logic used is different. Here we gave the intial value to i as 5. Now the condition is, that i must be greater than 0. As the body of while loop is executed each time, the value of i is decremented by 1. The loop terminates when the value of i becomes 0.

/* A c++ program example that uses while loop to print number from 0 to 9 using incrementation in the loop */


// Program 4

#include <iostream>

using namespace std;

int main ()
{
    int i = 0;
    while (i < 10)
    {
        cout << i << endl;
        i++;
    }

    return 0;
}

/* A c++ program example that uses while loop to print number from 0 to 9 using decrementation in the loop */


// Program 5

#include <iostream>

using namespace std;

int main ()
{
    int i = 9;
    while (i >= 0)
    {
        cout << i << endl;
        i--;
    }

    return 0;
}

The above program were simplest one's to get started into looping. In the next chapter we will learn about the for loop.

Thursday, December 9, 2010


Conditional (Ternary) Operator in c++ [? :]

Conditional (Ternary) Operator in c++ [? :]


The condional operator can often be used instead of the if else statement. Since it is the only operator that requires three operands in c++, it is also called ternary operator.

For example, consider the assignment statement :
x = y > 3 ? 2 : 4;
If y is greater than 3 then 2 will be assigned to variable x or else the value 4 will be assigned to x.

/* A simple c++ program example to demonstrate the use of ternary operator. */


// Program 1


#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
    int first, second;

    cout << "Enter two integers." << endl;

    cout << "First" << setw (3) << ": ";
    cin >> first;

    cout << "Second" << setw (2) << ": ";
    cin >> second;

    string message = first > second ? "first is greater than second" :
                                "first is less than or equal to second";

    cout << message << endl;

    return 0;
}


Compare the above "Program 1" and below "Program 2" with "Program 2" and "Program 3" of Selection Statement (if-else if-else) in c++ respectively, for better understanding.

/* A c++ program example to demonstrate the use ternary operator.*/


// Program 2


#include <iostream>
#include <:iomanip>

using namespace std;

int main ()
{
    int first, second;

    cout << "Enter two integers." << endl;

    cout << "First" << setw (3) << ": ";
    cin >> first;

    cout << "Second" << setw (2) << ": ";
    cin >> second;

    string message = first > second ? "first is greater than second" :
                                first < second ? "first is less than second" :
                                "first and second are equal";

    cout << message << endl;

    return 0;
}

Saturday, November 27, 2010


The switch statement in c++

The switch statement in c++


The program that we create should be readable. To increase the readability of the program we should use tools that is simple to read and understand. When possible use switch statement rather than if else statement, as it can be more readable than if else statement. But switch statement has limitation. It can't replace if else completely but can be helpful at certain situation. It can't do everything thing that if else statement can do. For example, switch statement can take only int or char datatype in c++. The following programs will help you to understand the switch statement.

/* A simple c++ program example that demonstrate the use of switch statement in c++ by taking character input.*/


// Program 1


#include <iostream>

using namespace std;

int main ()
{
    char permit;

    cout << "Are you sure you want to quit? (y/n) : ";
    cin >> permit;

    switch (permit)
    {
        case 'y' :
            cout << "Hope to see you again!" << endl;
            break;
        case 'n' :
            cout << "Welcome back!" < < endl;
            bbreak;
        default:
            cout << "What? I don't get it!" << endl;
    }

    return 0;
}

/* A c++ program example that demonstrate the use of switch statement in c++ by taking integer input. */


// Program 2

#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
    const int CHEESE_PIZZA = 11;
    const int SPINACH_PIZZA = 13;
    const int CHICKEN_PIZZA = 14;

    cout << " *********** MENU ***********" << endl;
    cout << setw (9) << "ITEM" << setw (20) << "PRICE" << endl;
    cout << " (1) Cheese Pizza" << setw (8) << "$"
            << CHEESE_PIZZA << endl;
    cout << " (2) Spinach Pizza" << setw (7) << "$"
            << SPINACH_PIZZA << endl;
    cout << " (3) Chicken Pizza" << setw (7) << "$"
            << CHICKEN_PIZZA << endl;
    cout << endl;

    cout << "What do you want? ";
    int option;
    cin >> option;

    cout << "How many? ";
    int quantity;
    cin >> quantity;

    int price;

    switch (option)
    {
        case 1:
            price = CHEESE_PIZZA;
            break;
        case 2:
            price = SPINACH_PIZZA;
            break;
        case 3:
            price = CHICKEN_PIZZA;
            break;
        default:
            cout << "Please select valid item from menu. " << endl;
            return 1;
    }

    int amount = price * quantity;
    cout << "Your Bill: $ " << amount << endl;

    return 0;
}

Explanation for the above program:


In the above program we take an integer value from the user which is stored in 'option' variable. We pass this value to switch statement. The switch statement has 3 cases: case 1, case 2 and case 3. The case 1: is similar to if (option == 1). This is the advantage of switch statement over if else statement. You don't need to type the name of variable again and again if you are doing selection operation on same variable. You just put the variable name on switch statement and then just specify the value after 'case'. One more thing to be noted is that it requires 'break' statement at the end of each 'case'. If you remove the break statement then it will jump to the case that follows it. Try it and check by yourself. The 'default' is same as else in if else statement.
 
Copyright © Mahesa Jabbar Arraafi