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:
- 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 //
2
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.
5
6 int main()
π The main function of the program
7 {
π Code starts {
8 int age; // input - age
9
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
Enter your age => 19 I am 19 years old
- 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!ππ



























