0% found this document useful (0 votes)
21 views6 pages

Lab#4

Uploaded by

Mugheera Malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

Lab#4

Uploaded by

Mugheera Malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB NO.

4 DD/MM/YYYY

OPERATORS IN C++
Lab outcomes:
After completing this lab, students will be able to:
 Implement the arithmetic operators.
 Implement the unary operators.
 Implement the relational operators.
 Implement the logical operators.
 Implement the assignment operators.

Corresponding CLO and PLO:


 CLO-1, PLO-2 (Engineering Knowledge)
Theory:
C++ is a programming language that provides a variety of operators to perform different types of
operations on variables and values. These operators can be broadly categorized into several
types, including arithmetic, unary, relational, logical, and assignment operators. Here's a brief
description of each:
1. Arithmetic Operators: These operators are used to perform mathematical calculations
on numerical values. The arithmetic operators in C++ include:
 Addition (+): Adds two values together.
 Subtraction (-): Subtracts one value from another.
 Multiplication (*): Multiplies two values together.
 Division (/): Divides one value by another.
 Modulus (%): Finds the remainder when one value is divided by another.
2. Unary Operators: These operators are used to perform operations on a single operand.
The unary operators in C++ include:
 Increment (++): Increases the value of a variable by one.
 Decrement (--): Decreases the value of a variable by one.
 Negation (-): Changes the sign of a numerical value.
 Logical NOT (!): Inverts the logical value of a boolean expression.
3. Relational Operators: These operators are used to compare two values and return a
boolean result. The relational operators in C++ include:
 Equal to (==): Checks if two values are equal.
 Not equal to (!=): Checks if two values are not equal.
 Greater than (>): Checks if one value is greater than another.
 Less than (<): Checks if one value is less than another.
 Greater than or equal to (>=): Checks if one value is greater than or equal to
another.
 Less than or equal to (<=): Checks if one value is less than or equal to another.
4. Logical Operators: These operators are used to combine boolean expressions and return
a boolean result. The logical operators in C++ include:
 Logical AND (&&): Returns true if both boolean expressions are true.
 Logical OR (||): Returns true if at least one boolean expression is true.
 Logical NOT (!): Inverts the logical value of a boolean expression.
5. Assignment Operators: These operators are used to assign a value to a variable. The
assignment operators in C++ include:
 Simple assignment (=): Assigns a value to a variable.
 Addition assignment (+=): Adds a value to a variable and assigns the result to the
variable.
 Subtraction assignment (-=): Subtracts a value from a variable and assigns the result
to the variable.
 Multiplication assignment (*=): Multiplies a variable by a value and assigns the
result to the variable.
 Division assignment (/=): Divides a variable by a value and assigns the result to the
variable.
 Modulus assignment (%=): Computes the remainder of a variable divided by a
value and assigns the result to the variable.

Activities:
Activity 3.1: Write a program in C++ that takes two numbers as input and print their sum,
difference, product, and quotient using the arithmetic operators.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.
Activity 3.2: Write a program in C++ that takes an integer as input and print its square
and cube using the multiplication operator.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.
Activity 3.3: Write a program in C++ that takes an integer as input and prints its value
after incrementing and decrementing it using the unary operators.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.
Activity 3.4: Write a program in C++ that takes two numbers as input and prints whether
the first number is greater than, less than, or equal to the second number using the
relational operators.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.
Activity 3.5: Write a program in C++ that takes a character as input and print whether it is
a vowel or a consonant using the logical operators.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.
Activity 3.6: Write a program in C++ that takes an integer as input and compute its
factorial using the multiplication and assignment operators.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.

Observations:
Please write your observation after conducting this lab, you have to write in few lines, what did
you learn in this lab.
Rubrics
Absent Student is Student can Student has Student has Student
unable to understand followed constructed perfectly
follow the the provided instructions the implemented
provided laboratory to construct functional/ a working
instructions instructions the working model/
properly. and familiar fundamental schematic/ logic/
The student with the lab schematic/ model/ circuit/
can name environment block block block
the (Trainer/ diagram/ diagram/ diagram/
hardware or software/ code/ model code, and code and
Demonstration simulation IDE), but on the have successfully
platform, cannot protoboard/ successfully executed the
but unable implement trainer/ executed lab objective
to on the simulation the in Realtime
implement platform software. program/ or in a
anything practically run circuit simulation
practically or on the on software environment
or on the software platform and
software produced the
desired
results
Category Ungrade Very Poor Poor Fair Good Excellent
d
Percentage [0] [1-20] [21-40] [41-60] [61-80] [81-100]
Marks 0.0 0.01 - 0.20 0.21 - 0.40 0.41 - 0.60 0.61 - 0.80 0.81 - 1.0
Date Total Instructor’s Signature
Marks

Report Plagiarize Requirement Observation Appropriate Correctly


not d content s are listed s are computation drawn
submitte presented and recorded s or conclusio
d or experimental along with numerical n with
Laborator incomplet procedure is detailed analysis is exact
y e presented procedure performed results
Reports submissio and
n complete
report in
all
respects
Category Ungrade Very Poor Fair Good Excellent
d Poor
Percentage [0] [1-20] [21-40] [41-60] [61-80] [81-100]
Marks 0.0 0.01 - 0.21 - 0.40 0.41 - 0.60 0.61 - 0.80 0.81 - 1.0
0.20
Date Total Instructor’s Signature
Marks

You might also like