PSCP 1 2
PSCP 1 2
Structures
Subject Code: CS1101 LTP: 3-0-0 (3)
Syllabus:
Evaluation Schema
• Attendance: 10 Marks
• Minor-1 : 10 Marks
• MID : 30 Marks
• Minor-2 : 10 Marks
• End Exam: 40
decltype
C++11 also introduces a way to determine the type of a variable or expression.
decltype (expr) is the declared type of variable or expression expr and can be
used in declarations:
Lab Programs
WAP to calculate Total Salary of employee provided Name as First name, Middle name and Last name, Basic, HRA (18% of
basic), DA (50% of basic)
WAP to calculate CGPA of student
Notes:
Take name of employee as First name, Middle name and last name and Append Dr. salutation to name
and display as Dr. First name Middle Name and Last Name
Ex: Mr. Shiva Rama Krishna
Output: All the details along with Total Salary/CGPA
Check the bool data type functionality by assigning zero, positive and negative values. Make your observations
Take two bool variables perform addition, subtraction, multiplication using them. Make your observations
Take fixed width integers and try to store the numbers beyond the range ? Draw your observations?
Operators
Operators in C++ can be classified into 6 types:
• Arithmetic Operators
• Assignment Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Other Operators
Arithmetic Operators
• Arithmetic operators are used to perform arithmetic operations on
variables and data.
Arithmetic Operators Program
Example
The modulo operator % computes the remainder. When a = 9 is divided by b = 4, the remainder is 1.
Increment and Decrement
Operators
Example code on Increment and Decrement Operators
In the above program, we have used the ++ and -- operators as prefixes (++a and --b). However, we can also use these
operators as postfix (a++ and b--).
C++ Assignment
Operators
C++ Assignment Operators
Example on Assignment Operators
The left-shift and right-shift operators should not be used for negative
numbers.
The result of is undefined behavior if any of the operands is a negative
number. For example results of both 1 >> -1 and 1 << -1 is undefined.
Other C++
Operators
Other C++ Operators
Conditional
Statements
• to create decision making
• if,
• if...else and
• Nested if...else
In computer programming, we use the if...else statement to run one block of code under certain conditions and
another block of code under different conditions.
How if Statement Works
WAP to print positive number entered by the user
SimpleIf.cpp
Precedence Level 1 signifies operators of highest priority, while Precedence Level 17 signifies operators of the lowest priority.
C++ Operators Associativity
Also, multiple operators can have the same level of precedence (as we can see from the above
table). When multiple operators of the same precedence level are used in an expression, they are
evaluated according to their associativity.
Arrays
C++
Multidimensional
Arrays
Multidimensional Array
Initialization
Initialization of three-dimensional array
C++ Program to display all elements // of an initialised two dimensional array
Taking Input for Two Dimensional Array
Note
Three Dimensional Array
Assignment's
• WAP to perform matrix addition.
• WAP to perform matrix multiplication.
Hints:
Character Arrays
C++ Functions
C++ User-defined Function
Calling a Function
Function Parameters
C++ Library Functions
Assignements
• WAP for factorial using function
• WAP to find any table using function
• WAP to print sum of the digits of given number using function.
• WAP to
C++ Programming Default Arguments
(Parameters)
Function overloading
C++ Recursion
Working of Factorial Program
Assignements
Passing Array to a Function
in C++ Programming
Strings
Passing String to a Function