Data-Types
Data-Types
Data Types
– Refer to the kinds of data that variable can assume, hold or take
on in a programming language and for which operations are
automatically provided.
Boolean
– A boolean data type represents two states: true and false.
– it can also accept values 0 and 1; wherein 0 can represent false,
and 1 as true.
Example:
bool result = true;
correct declaration
bool result2 = false;
Integer
– integer can only hold whole numbers; numbers with decimal
points will be converted into whole numbers.
Example:
int num = 10;
Types of Integers:
– int can only contain values ranging from -2,147,483,648 to
2,147,483,647… but it has different types:
Character
– A character data type represents a single character.
– it must have its value enclosed in single-quotes.
Example:
char letter = ‘a’; correct declaration
char x = 0;
char y = qwerty; wrong declaration
char z = “asdf”;
char a = ‘abcde’;
Programming Data Types
String
– A string data type represents a series of characters.
– it must have its value enclosed in double-quotes.
Example:
string name = “mark”; correct declaration
string x = ‘0’;
wrong declaration
string y = 1;
Programming Data Types
Floating point
– A floating point data type represents number with decimal point.
– has two types: float and double.
Example:
double number = 3.5;
Example:
cout<<“Hello, World!”<<endl;
Programming cin and cout
Example:
int x;
cin>>x;
Programming cin and cout sample program
Sample Program:
Output:
Programming cin and cout sample program
Sample Program:
Output:
Flowchart
• Flowchart
are a visual outlining tool. They can be used to
represent an algorithm.
• Algorithm
The sequence of steps necessary to solve any
problem.
Symbols used in Flowcharting
Symbols used in Flowcharting
Sample Program:
Sample Flowchart:
Flowchart
#include<iostream.h>
start TERMINAL
using namespace std; SYMBOL
int main(){
no1, no 2
INPUT
int no1, no2;
int sum;
sum = no1+no2 PROCESS
cout<<“Please Type in First Integer:”;
cin>>no1;
cout<<“Please Type in Second Integer:”; no1, no2,
sum OUTPUT
cin>>no2;
sum = no1+no2;
cout<<“The sum of” <<no1 <<“and”<<no2
end TERMINAL
<<“is:”<<sum<<endl;
SYMBOL
}
Operators
Operators
Arithmetic Operators
int main(){
int num1;
int num2;
}
Output
Operators
Operator Use
Description
Operator Use
Description
#include<iostream.h>
using namespace std;
int main(){
int a = 23;
int b = 24;
int c = 22;
cout<<"Number 1 ="<<++a<<endl;
cout<<"Number 2 ="<<b++<<endl;
cout<<"Number 2 = "<<b<<endl;
cout<<"Number 3 ="<<--c<<endl;
}
Output
Number 1 = 24
Number 2 = 24
Number 2 = 25
Number 3 = 21