C++ coding practice
C++ coding practice
Asst. Prof. Dr SALAHUDDIN, School of Humanities and Sciences (S H & S), NUST, PAF Asghar Khan Academey,
Input variable in C++
SYNTAX
cin >> Variable >> Variable . . . ;
Asst. Prof. Dr SALAHUDDIN, School of Humanities and Sciences (S H & S), NUST, PAF Asghar Khan Academey,
Input variable in C++
cin >> x;
cin >> y;
Asst. Prof. Dr SALAHUDDIN, School of Humanities and Sciences (S H & S), NUST, PAF Asghar Khan Academey,
Constants in C++
Constants in C++ refer to variables with fixed values that
cannot be changed. Once they are defined in the program, they
remain constant throughout the execution of the program. They
are generally stored as read-only tokens in the code segment
of the memory of the program. They can be of any available
data type in C++ such as int, char, string, etc.
Example
const int myNum = 15; // myNum will always be 15
myNum = 10; // error: assignment of read-only variable
'myNum'
Asst. Prof. Dr SALAHUDDIN, School of Humanities and Sciences (S H & S), NUST, PAF Asghar Khan Academey,
Example # 1: Write a C++ program to find the
perimeter and area of a rectangle.
Pseudocode describes the
Pseudo Code: distinct steps of an algorithm
in a way that’s easy for
1. C++ program for perimeter & area. anyone with to understand.
It is the representation of code
2. Initially all variables (Length, width, Perimeter and which can be understood by
Area) will be defined of float type. even a layman with some
school level programming
3. Input values will be obtained from the user by knowledge.
Asst. Prof. Dr SALAHUDDIN, School of Humanities and Sciences (S H & S), NUST, PAF Asghar Khan Academey,
Source Code:
Asst. Prof. Dr SALAHUDDIN, School of Humanities and Sciences (S H & S), NUST, PAF Asghar Khan Academey,
OUTPUT:
Asst. Prof. Dr SALAHUDDIN, School of Humanities and Sciences (S H & S), NUST, PAF Asghar Khan Academey,
LAB EXERCISE 3: “Area and Circumference
code”
Asst. Prof. Dr SALAHUDDIN, School of Humanities and Sciences (S H & S), NUST, PAF Asghar Khan Academey,