Week 2

2nd Week(1st March 2013)

Okaii, let’s see what I’ve learnt this week. Note that this is the 2nd week since the start of this lovely and sophisticated course. As a guideline, these are the main topics of what I’ve learnt; the format of a program, the definitions and purposes of ‘function’, ‘declaration of variable’, ‘identifier’, types of identifier and lastly the basic commands of C++ programming.

Firstly, we have the format of a C++ program in which we include the library for C++ program, ‘cstdlib’ and the header file for the input or output commands, ‘iostream’. Followed by the ‘int main ()’ function which is considered to be the first instruction for the C++ compiler to follow. After that, the insert of opening of statement blocks, ‘{‘. The next step is to input the desired code of C++ program. Basically, this is the main focus of any computer programming and what we will have to learn to insert or write on our own. (I put ‘we’ because I think the same goes for the rest of my course mates). According to our lecturer, it is better to break up a long code into smaller parts via the ‘void’ key phrase. By keying in ‘void’, the code will be separated into each function of its own. Yet, this is optional for the programmer’s part as I’ve read that every seasoned programmers has developed a style of their own. It is optional but highly encouraged to be used.

Subsequently, ‘function’ is defined as a segment of the program which carries out a specific task assigned by the programmer and it is also used hand-in-hand with ‘void’. A variable is to be inputted next to void and this variable is to be defined later within its own function or segment of the program. An example for this format will be copied and pasted shamelessly from a PowerPoint Presentation created by our lecturer, Md Yazid B. Mohd Saman, entitled, Pengaturcaraan C++: Arahan Asas C++;

#include <cstdlib>

#include <iostream>

using namespace std;

void beriSalam();

void selamatDatang();

// Komen: Fungsi utama

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


beriSalam();   // panggil fungsi#1

selamatDatang(); // panggil fungsi#2


return 0;   // satu cara lain


// Komen: Fungsi pengguna #1

void beriSalam()


cout << “Assalamu alaikum\n”;

cout << ” dan salam sejahtera”;


// Komen: Fungsi pengguna #2

void selamatDatang()


cout << ” Selamat Datang ke”

<< ” UMT”;


(Slide 4, 2013)

Then, we have ‘data’ in the C++ program along with the ‘data identifier’ which identifies integer and string types of data. There are many more types of data but for now, we have learnt of these two only. More elaborations of ‘data’ will be posted at a later time. For now, no.

Finally, we learnt six basic commands of C++ program. There are input, output, assignment, loops, conditional statements and function calls. The keyword for the programmer to place an input in the C++ program is ‘cin’ while the output is ‘cout’. Output is to display a value of data via a medium output. Meanwhile, input is to accept an input of value for a variable of data. Furthermore, ‘assignment’ (=) is used to set a value to a variable. For instance, x=0, giving a value of 0 to x. Besides, ‘loops’ are represented by the keyword ‘for’. Some codes that utilise ‘for’ is accompanied by ‘increment’ (++) which increases the input value by 1 continuously unless it is accompanied by a key word that stops it from increasing the input value infinitely. Additionally, the conditional statements are represented by ‘while’. Last but not least, function call is where we put a meaningful name to a function.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s