ITC C++ Programming LAB7
ITC C++ Programming LAB7
Farhan Memon
Electrical Engineering Introduction to Computers & C++
Mehran University of Engineering Year 1ST Semester 1st
& Technology Batch 17 Duration 03
Jamshoro Hours
Outlines
· Variables
· Fundamental Data Types
· Escape Sequences
· Constants
· Lab tasks
Requirements
· Code::Block IDE
1
VARIABLES
A variable as a named portion of memory to store a value.
a = 5;
b = 2;
result = a - b;
Each variable (sometimes identifiers) needs a name that identifies it and distinguishes it
from the others.
-The name of a variable can be composed of letters, digits, and the underscore
character.
Variable declaration
Each variable must be declared with data type:
int a;
int b;
float result;
OR
int a,b;
float result
Variable Initialization
We initialize the variables with assigning some values to them:
float result=a/b;
2
Example
Fundamental data types are basic types, they can mainly be classified into:
Character types: They can represent a single character, such as 'A' or '$'. The most basic
type is char, which is a one-byte character.
Numerical integer types: They can store a whole number value, such as 7 or 1024.
Floating-point types: They can represent real values, such as 3.14 or 0.01.
Boolean type: The boolean type, known in C++ as bool, can only represent one of two states,
true or false.
3
The table shows the variable type, how much memory it takes to store the value in memory,
and what is maximum and minimum value which can be stored in such type of variables.
4
5
ESCAPE SEQUENCES
Example
6
CONSTANTS
Constants refer to fixed values that the program may not alter and they are called literals.
Constants can be of any of the basic data types : Integer, Numerals, Floating-Point Numerals,
Characters, Strings and Boolean Values.
Examples
7
LAB TASKS
1. Write a program to calculate Circumference and area of a circle. Where:
Value of radius it will take during run time.
Use the value pi = 3.141593, as a constant.
A = pi *r*r;
C = 2 * pi * r;
2. Write a program to calculate the area of rectangle and take width and height as
input.
3. Write down a program that adds two numbers/variables of type float and stores the
result in variable of type integer.
SUBMISSION:
In Hard-Format (manual along with exercise), will be checked in the next Lab
The End