ITC C++ Programming LAB8
ITC C++ Programming LAB8
Farhan Memon
Electrical Engineering Introduction to Computers & C++
Mehran University of Engineering Year 1ST Semester 1st
& Technology Batch 17 Duration 03
Jamshoro Hours
Outlines
· Operators
· Arithmetic Operators
· Increment/Decrement Operators
· Arithmetic Assignment Operators
· Relational Operators
· Logical Operators
· Lab tasks
Requirements
· Code::Block IDE
1
OPERATORS
Operators are used to perform calculations or operations on the operands.
Operators in c++:
Arithmetic Operators
Increment/Decrement Operators
Relational Operators
Logical Operators
ARITHMETIC OPERATORS
Arithmetic operators are operators used to perform basic mathematical operations.
2
Program
#include <iostream>
int main()
double x, y;
cout << "The average of the two numbers is: " << (x + y)/2.0 << endl;
return 0;
INCREMENT/DECREMENT OPERATORS
++i is incremented first and the new value of i is then applied (prefix)
--i is decremented first and the new value of i is then applied (prefix)
3
Program
#include <iostream>
int main()
return 0;
z = 7.5;
y = z;
x = 2.0 + 4.2 * z;
i += 3; is equivalent to i = i + 3;
i *= j + 2; is equivalent to i = i * (j+2)
4
Program
#include <iostream>
int main ()
int a=3;
a+=2;
return 0;
RELATIONAL OPERATORS
These operators establish a relationship between operands and are used to compare two
operands.
5
Program
#include <iostream>
int a = 21;
int b = 58;
if(a>b)
{
cout << " a is greater than b" << endl ;
}
else
{
cout<<"b is greater than a" <<endl;
}
return 0;
}
LOGICAL OPERATORS
They are used to combine two different expressions together. The logical operators are AND
(&&) , OR (||) and NOT (!).
6
Program
#include <iostream>
int main() {
int age;
else
{ cout << "Sorry, Your Age is not in the Range" << endl; }
return 0;
7
LAB TASKS
1. Write down a program using OR (||) operator in which a user enters a character at
run-time to find either the given character is vowel or not.
(Hint: use if-else structure).
2A person enters the bank and stands in the queue to get his salary. When his turn
comes, he requests the cashier that I need my salary with minimum notes and coins.
Write a program in C++ for the cashier that first asks the cashier to enter the salary
amount and then displays the number of notes and coins of (Rs. 5000, Rs. 1000, Rs. 100,
Rs. 50, Rs. 20, Rs. 10, Rs. 5, Rs. 2 and Re. 1).
SUBMISSION:
In Hard-Format (manual along with exercise), will be checked in the next Lab
The End