1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
// Demonstrate Logical Operators
#include<iostream.h>
#include<string.h>
void main()
{
int a = 5, b = 10, c = 15;
char ch,ch1, pass[20], user[25];
cout<<"Logical Operators\n"<<" 1. Logical \"OR\" Operator\n"<<" 2. Logical \"AND\" Operator \n"
<<" 3. Logical \"NOT\" Operator\n"<<"Choose anyone to see its demonstration\n";
cin>>ch;
if(ch=='1')
{
cout<<"THE LOGICAL \"OR\" OPERATOR\n";
cout<<" We know that (4 == 4) but (5 != 8). In the logical OR Operator, if any 1 test \n"
<<"expression evaluates to true then the value of the whole expression turns \n"
<<"to true i.e, 1 \n";
cout<<" a = 5, b = 10, c = 15 \n"
<< "The true expression "<< "a < b || b > c gives " << (a < b || b > c) <<"\n"
<< "The false expression "<< "a > b || b > c gives "<< (a > b || b > c) << endl;
cout<<"\nWant to restart??\n";
cin>>ch1;
}
if(ch=='2')
{
cout<<"THE LOGICAL \"AND\" OPERATOR\n";
cout<<"In this operator, both the test expressions should evaluate to true if\n"
<<"the whole expression is to be given the value of true.\n"
<<" If any-1 expression evaluates to false the complete \n"
<<"expression is given the value of false \n";
cout<<"This operator can be used for login details.....\n"
<<"the following program..........\n\n";
cout<<"Please enter login details\n";
for(int i = 0; i < 3; i++)
{
cout<<"\n Enter Username\n";
cin.getline(user,25);
cout<<"Enter Password\n";
cin.getline(pass,20);
if (((user,25) == 'abd') && ((pass,20) == 'abs'))
{
cout<<"\nAccess GRANTED\n";
}
else
{
cout<<"\nWrong username OR Password\n";
}
}
}
}
|