C++ Elements

a. Identifier
Identifier is a name commonly used in programming for declare variables, constants, data type, and function. Rules for writing the identifier together with the rules in pascals, among others:
- It should not be initiated by non-letter characters
- There should be no spaces
- Not allowed to use the characters  ~! @ # $% ^ & * () + `- = {} []:"; '<>?,. /
- Not allowed to use reserved words on c++

b. Data type
Data types used in c + + programming include:
Rounded number data type:
- char
- int (integer)
- short (short integer)
- long (long integer) 
Real number data type:
- float (real)
- double (real double)
- long double
 
Unsigned data type:
- unsigned char
- unsigned int (integer)
- unsigned short (short integer)
- unsigned long (long integer)

Unsigned data types which are not similar to unsigned. The difference is the data type unsigned does not recognize negative numbers (its value is always positive).
c. AssignmentAssignment process is the process of giving value to a variable that has been declared.
Here are examples of assignments:
Number = 10;
Price_unit= 23 456;
James= 'B';
Dean= '2 ';

 
Here's an example program that illustrates the declaration of variables and assignment.
#include <iostream.h>
#include <conio.h>
void main()
{
int var1, var2, var3;
char karakter;
var1 = 10;
var2 = 5;
var3 = var1 + var2;
karakter = ‘D’;
cout << “Value of var3 = ” << var3 << “\n”;
cout << “Value of character  = ” << karakter;
getch();
}
For next example, we can create program with precision statement
#include "conio.h";
#include "iostream.h";
#include "iomanip.h";
void main()
{
clrscr();
double real;
real = 182.2182713674821746;
cout << setprecision(12);
cout << "Value of real = " << real;
getch();
}



0 comments



Recent Entries