0% found this document useful (0 votes)
13 views17 pages

Reminder: Library File Has To Discuss Later Procedural and Object Oriented Programming Have To Discuss Later

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

Reminder: Library File Has To Discuss Later Procedural and Object Oriented Programming Have To Discuss Later

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

Reminder

● Library file has to discuss later


● Procedural and object oriented programming
have to discuss later
Complex number
#include<iostream>
#include<cmath>
#include<complex>
using namespace std;
int main(){
float x,y;
complex<float>c1,c2,c;
c1=complex<float> (2.0,4.0);
cout<<"Enter the real and imaginary parts of a complex
number\n";
cin>>x>>y;
c2=complex<float>(x,y);
c=c1+c2;
cout<<"Summation of complex number is"<< c;
return 0;}
Output of the above code
Enter the real and imaginary parts of a complex number
24
Summation of complex number is(4,8)
Operation of complex variable
● If we add the following code
float x1=real(c);
float x2=imag(c);
cout<<"The real part of the complex sum is"<<x1<<"\n";
cout<<"The imaginary part of the complex sum is"<<x2<<"\n";
Output
Enter the real and imaginary parts of a complex number 29 8
Summation of complex number is(31,12)
The real part of the complex sum is31
The imaginary part of the complex sum is12
cout<<"Absolute value is:" << abs(c)<<"\n";
cout<<"Phase angle is:" << arg(c) <<"\n";

Output:
Absolute value is:13.9284
Phase angle is:1.20362
cout << "Norm value is:"<< norm(c) <<"\n";
cout << "Complex conguate is:" << conj(c) <<"\n";

Output:
Norm value is:194
Complex conguate is:(5,-13)
cout <<"Square root is: "<< sqrt(c) << "\n";
cout << " 3rd power of complex number is :"<<pow(c,3) <<"\
n";

cout << "Exponential of complex number is :" << exp(c) <<"\


n";
cout << "Log of complex number is :" << log(c) << "\n";

Output:
Square root is: (3,2)
3rd power of complex number is :(-2035,-828)
Exponential of complex number is :(125.239,-79.6345)
Log of complex number is :(2.56495,1.17601)
Complex variable operation
● Trigonometric and hyperbolic function of
complex variable ---self studys
Logical variable
● Boolean variable studied as bool variable
Relational Operators
In C++ Programming, the values stored in two
variables can be compared using following
operators and relation between them can be
determined.
● Various C++ relational operators available are-
● Operator, Meaning
● > ,Greater than
● >= , Greater than or equal to
● == , Is equal to
● != , Is not equal to
● < , Less than or equal to <=
Now if the result after comparison of two
variables is True, then if statement returns
value 1.

And if the result after comparison of two variables


is False, then if statement returns value 0.
#include<iostream>
using namespace std;
int main()
{
int a=10,b=20,c=10;
if(a>b)
cout<<"a is greater"<<endl;
if(a<b)
cout<<"a is smaller"<<endl;
if(a<=c)
cout<<"a is less than/equal to c"<<endl;
if(a>=c)
cout<<"a is less than/equal to c"<<endl;
Return 0;}
a is smaller
a is less than/equal to c
a is greater than/equal to c
Logical Operator
● Logical Operators are used if we want to
compare more than one condition.
● Depending upon the requirement, proper logical
operator is used.
● Following table shows us the different C++
operators available.
● Example
&& AND Operator Binary
|| OR Operator Binary
! NOT Operator Unary
According to names of the Logical Operators, the
condition satisfied in following situation and
expected outputs are given
● Operator Output
● AND Output is 1 only when conditions on
both sides of Operator become True
● OR Output is 0 only when conditions on
both sides of Operator become False
● NOT It gives inverted Output
#include<iostream>
using namespace std;
int main() {
int num1=30;
int num2=40;
if(num1>=40 || num2>=40)
cout<<"OR If Block Gets Executed"<<endl;
if(num1>=20 && num2>=20)
cout<<"AND If Block Gets Executed"<<endl;
if(!(num1>=40))
cout<<"NOT If Block Gets Executed"<<endl;
return 0;}
output
OR If Block Gets Executed
AND If Block Gets Executed
NOT If Block Gets Executed
For loop
#include <iostream>
using namespace std;
int main() {
int j;
for(j=0; j<15; j++)
cout << j * j << “ “; //displaying the square of j
cout << endl;
return 0;
}
Output:
0 1 4 9 16 25 36 49 64 81 100 121 144 169 196

You might also like