Monday, April 24, 2017

C++ PROGRAM

Salam & welcome back guys!
How are you guys doing? we hope that you guys are doing fineπŸ˜ƒ

In this entry, we would like to share on the C++ program.  According to wikipedia, C++ is a general purpose programming language. Basically there are 6 basic elements in this program:


  1.  Simple C++ program
  • The simple C++ program is can be done at πŸ‘‰ click here and then choose C++ in the language search
  • The format and example is:
1 // Writing my age 
πŸ‘‰ 1st line is called comment line that describe the purpose of the program
πŸ‘‰ Must begin with //

3 #include <iostream>
πŸ‘‰ Is the processor directive
πŸ‘‰ Must begin with #
πŸ‘‰ <iostream> is the library of function, symbols and operators

4 using namespace std; 
πŸ‘‰ To give instruction to the compiler to use function in standard library.
6 int main() 
πŸ‘‰ The main function of the program

7 { 
πŸ‘‰ Code starts { 

8 int age; // input - age 
10 // Get data on age 

11 cout << "Enter your age => ";
πŸ‘‰ An interactive message which the program asking for data from the user as input data is called a prompt

12 cin >> age;
πŸ‘‰ The variable name has to be defined earlier

13 
14 //Display message 

15 cout << "I am " << age << " years old" << endl; 
πŸ‘‰ endl is used to terminate a line of output and starts a new one

16 return 0; 
πŸ‘‰ indicates that the program has ran normally

17 } 
πŸ‘‰ ends of the code

  • the coding is as shown below:


  • The input will be:

Enter your age =>  19
I am 19 years old
  

      2. Data Types
  • Numbers
- Floating point numbers
   πŸ‘‰ Numbers with fractional part or decimal place
- Integers
   πŸ‘‰ Exact numbers without decimal place

  • Characters
- Store single characters 
- Written as char
- The characters is enclosed in single quotes

  • Strings
- Double quotes is used to enclose a string’s value 

      3. Arithmetic expression
  • Multiple operators
- Parentheses of complex sub-expression. eg:
p / –q + ( r – s + t ) * n => ( p / (-q) ) + ( ( r – s + t ) * n )
 
  • Operators / and % 
- Calculate the integer quotient (/) & remainder (%)

  • Rounding
- If you want to round a positive value of the float to the nearest integer, add 0.5 before explicitly converting to an int to avoid loss of the value’s fractional part

      4. Additional Operators
- Besides, + - * / , C++ program also can provides predefined units called functions for operators 
- The list of names and descriptions of some of the most commonly used functions are as shown below:


Well, that's all  what we had learnt in the past class. Till then, thank you guys for constantly reading our blog!πŸ’‹πŸ˜˜



No comments:

Post a Comment