Saturday, 22 April 2017

Now Journey to The C++

Welcome back buddies 😊😉😃 this week we had learn about C++ with Dr Azni, our beautiful lecturer. Hope so you guys will enjoy our post this week 😗


First ,  example of  " Simple C++ Program


Let us see what we learn 💓 

1. comment line

- 1st line is a comment line which describe the purpose of the program.

- Begin with a double slash (//)

- Ignored by compiler, only used to assist the reader of the program

2. #include <iostream>

- preprocessor directive

- begin with symbol #

- <iostream> is called library – header file name enclosed in bracket

- library is a collection of useful functions, operators and symbols that may be accessed by a program

- <iostream> library defines the names cin and cout the operators >> and <<

3. using namespace std;

- to give instruction to the compiler to use function in standard library.

- allows the program to access all the names that are grouped as the collective named std.

4. statement

- one or more lines of code ends with a semicolon ;

5.  int main ()

- main function of the program

- consist of one or more statement enclosed in curly bracket { }

6. Names and keyword

 Names:
- use to define constants and variables
- sensitive to upper and lower cases
- use underscore for two or more words
- can contain digit but cannot begin with digit

Keyword:
- several collection of letters cannot be use as names for constants or variables since they have been reserve for special purposes in the language as listed in Figure 1.1

                                 Figure 1.1: C++ Keywords (Appendix F Hanly 2002)

7. cout <<

- format: cout << “ ”;

- statement enclosed in qoutes (“ ”) display the message on the screen

- an interactive message which the program asking for data from the user as input data is called a           prompt

8. Insertion operators (<<)

- cout refers to the output stream of the associated in the program’s output device, typically the screen

- output stream is an output destination for a continous stream of characters

- the insertion operator (<<) inserts characters in an output stream

9. cin >>

- format: cin >> variable name;

- copy the value type by user –variable input

- the variable name has to be defined earlier

10. Extraction operators (>>)

- the program can also views the characters typed at the keyboard as a stream

- cin is the name of the input stream associated with the standard input device, typically the keyboard

- the extraction operator (>>) extracts one or more characters from the input stream for storage as a data value

11. endl;

- terminates a line of output and starts a new one

12. return 0;

- the final line of a program

- by returning (0) indicates that the program has ran norm

💗 All above have shown in the picture above 💗


This is the simple C++ that we learn

    Figure 2.1 The coding 


We also have done an exercise about C++ 

Here we are 😁

       Figure 3.1 The exercise 

Fuhh lastly this is the end... We struggle a lot when doing this exercise..😌😌

Wait for us next week 💕💕😍

No comments:

Post a Comment