#include
<iostream> using namespace std;
main()
{
cout<<"\tCS201 Assignment 1 Solution" <<endl;
cout<<"\t\t Spring 2021"<<endl;
cout<<"\tby
Abdul Hadi E Services \n" <<endl <<endl;
//Solving
Expression
int
x, y, Z; x=2, y = 1;
Z = (x*x)+(2*x*y)-(x/y);
cout<<"After
evalution of given expression the value of z = "<<Z <<endl;
// Student ID and Anylizing string ID = "BC" ;
int id2 =
2000201127;
string
Name = "Moazzam Ali"; int lastdigit;
int Gotnumber;
///Evaluation
of ID lastdigit = id2 % 10;
cout<<"Last
digit of my vu ID is "<<lastdigit <<endl; Gotnumber = Z +
lastdigit;
Logical
Operators
There are many occasions when we face complex
conditions to make a decision. This means that a decision depends upon more
than one condition in different ways. Here we combine the conditions with AND or
OR. For example, a boy can be selected in basket ball team only if he is more
than 18 years old and has a height of 6 feet. In this statement a boy who wants
to be selected in the basket ball team must have both the conditions fulfilled.
This means that AND forces both the conditions to be true. Similarly we say
that a person can be admitted to the university if he has a BCS degree OR BSC
degree. In this statement, it is clear that a person will be admitted to the
university if he has any one of the two degrees. In programming we use logical operators (
&& and || ) for AND and OR respectively with relational operators.
These are binary operators and take two operands. These operators use logical
expressions as operands, which return TRUE or FALSE.
The && operator has a higher precedence than
the || operator. Both operators associate from left to right. An expressions
containing && or || is evaluated only until truth or falsehood is
known. Thus evaluation of the
expression (age > 18) && (height > 6) will stop immediately if age > 18 is false
(i.e. the entire expression is false) and continue if age > 18 is true (i.e.
the entire expression could still be true if the condition height > 6 is
true ).
There is another logical operator that is called
logical negation. The sign ! is used for this operator. This operand enables a
programmer to ‘reverse’ the meaning of a condition. This is a unary operator
that has only a single condition as an operand. The operator ! is placed before
a condition. If the original condition (without the ! operator) is false then
the ! operator before it converts it to true and the statements attached to
this are executed. Look at the following expression if ( ! (age > 18 )) cout << “ The age is less than 18”;
Here the cout statement will be executed if the original condition (age >
18) is false because the ! operator before it reverses this false to true.
0 Comments
Please do not enter any spam link in the comment box.