IPC Lecture 2
IPC Lecture 2
Datatypes
C++ Character Set
● The character set is a combination of English
language comprising of the Alphabets and the
White spaces and some symbols from the
mathematics including the Digits and the Special
symbols.
Stores fractional numbers, containing one or more decimals. Sufficient for storing 6-7
float 4 bytes
decimal digits
Stores fractional numbers, containing one or more decimals. Sufficient for storing 15
double 8 bytes
decimal digits
N* Store multiples characters, often in double quotes, with an escape character \0 at the end
string
1byte+1byte of those characters. Basic string size is determined by number of character in it.
Constants
● Constants are type of variables that would not change during the
execution/running of a program.
● We use the keyword const to declare such variables.
● this will declare the variable as "constant", which means unchangeable and
read-only
C++ Assignment Operator
● In C++ the equal sign = is used as an assignment
operator.
● Example 1: int num1 = 20; means “… create an integer
variable called num1 and store the integer 20 in it …”
● Example 2:
int num1 = 20; int num2 = 10;
int sum = num1 + num2;
The assignment is used in an expression. Simple
meaning add num1 and num2 and store the result in
the variable called sum.
C++ Arithmetic Operators
● C++ arithmetic operators are used to perform operations on
variables and values. The following is a list of some C++
arithmetic operators.
Relational Operators
● relational operators are used to compare two values (or variables). This is important
in programming, because it helps us to find answers and make decisions.
● The return value of a relational is either 1 or 0, which means true (1) or false (0).
These values are known as Boolean values, and you will learn more about them in
the Booleans and If..Else chapter.
Logic Operators
● As with relational operators, you can also test for true (1) or
false (0) values with logical operators.
● Logical operators are used to determine the logic between
variables or values:
IPC Class Activity 2
● Class Activity 1: Write a C++ Program to take as input the following:
fullname
Gender
DoB (Full Data of Birth)
● Then calculate the real Age of a person, which include years and months.
● Finally display the following:
if user is male:
"Hello Mr [fullname]. You are [age] years and [months] Old. Your date of
birth is [day/month/year]."
else gender is female:
"Hello Ms [fullname]. You are [age] years and [months] Old. Your date of
birth is [day/month/year]."