Friday, March 26, 2021

Title: Implement a class Complex which represents the Complex Number data type. Implement the following operations: 1. Constructor (including a default constructor which creates the complex number0+0i). 2. Overloaded operator+ to add two complex numbers. 3. Overloaded operator* to multiply two complex numbers. 4. Overload << and >> to print and read Complex Numbers.

 #include<iostream>

using namespace std;

class complex

{

public:

    float real,img;

    complex()

    {

    real=0;

    img=0;

    }

    complex operator +(complex);

    complex operator *(complex);

    friend ostream &operator<<(ostream&,complex&);

    friend istream &operator>>(istream&,complex&);

};


complex complex::operator +(complex obj)

{

    complex temp;

    temp.real=real+obj.real;

    temp.img=img+obj.img;

    return (temp);

}


complex complex::operator *(complex obj)

{

    complex temp;

    temp.real=(real*obj.real)-(img*obj.img);

    temp.img=(real*obj.img)+(img+obj.img);

    return (temp);

}


istream &operator>>(istream& is,complex& obj)

{

    is>>obj.real;

    is>>obj.img;

    return is;


}


ostream &operator<<(ostream& os,complex& obj)

{

    os<<obj.real;

    os<<"+"<<obj.img<<"i";

    return os;

}


int main()

{

    complex a,b,c,d;

    //cout<<"\n Enter first complex number"<<endl;

    cout<<"\n Enter real and imaginary part of first complex number:";

    cin>>a;


    //cout<<"\n Enter second complex number"<<endl;

    cout<<"\n Enter real and imaginary part of second complex number:";

    cin>>b;


    cout<<"\n Arithmetic operations are :";

    c=a+b;

    cout<<"\n Addition is:"<<c;

   

    d=a*b;

    cout<<"\n Multiplication is:"<<d<<"\n";

    return 0;

}


*****************OUTPUT***************************

Enter real and imaginary part of first complex number:3 

3


 Enter real and imaginary part of second complex number:4

5


 Arithmetic operations are :

 Addition is:7+8i

 Multiplication is:-3+23i

Monday, March 22, 2021

to compute 1:square root of a numnber 2:square of a number 3:cube of a number 4)Check for prime 5)factorial of a number6)Prime factor of a number

To accept the number and compute using python

a)Square root a Number

>>> num = float(input('Enter a Number:'))

Enter a Number:77

>>> num_sqrt = num ** 0.5

>>> print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))

The square root of 77.000 is 8.775

>>> 

b)Squar of a Number

>>> num = float(input('Enter a Number:'))

Enter a Number:12

>>> square = num * num

>>> print('The square of %0.3f is %0.3f'%(num ,square))

The square of 12.000 is 144.000

>>>

c)Cube of a Number

>>> num = float(input('Enter a Number:'))

Enter a Number:4

>>> cube= num * num *num

>>> print('The cube of %0.3f is %0.3f'%(num ,cube))

The cube of 4.000 is 64.000

d)Check for Prime Number

>>> num = int(input("Enter a number: "))

Enter a number: 23

>>> if num > 1:

...     for i in range(2, num):

...             if(num % i) == 0:

...                     print(num,"IS NOT APRIME NUMBER")

...                     break

...             else:

...                     print(num,"IS A PRIME NUMBER")

...     else:

...             print(num,"IS NOT A PRIME NUMBER")

...

23 IS A PRIME NUMBER

5) factorial of number

>>> num = int(input('Enter a Number:'))

Enter a Number:23

>>> f = 1

>>> if(num < 0):

...     print("THE NUMBER IS NEGATIVE")

... elif(num == 0):

...     print("The factorial of 0 is 1")

... else:

...     for i in range (1, num + 1):

...             f =f * i

...     print("the factorial of",num,"is",f)

...

the factorial of 23 is 25852016738884976640000

>>>

6)Prime Factore of a Number
>>> Number = int(input(" Please Enter any Number: "))
 Please Enter any Number: 23
>>> i = 1
>>> while(i <= Number):
...     count = 0
...     if(Number % i== 0):
...             j = 1
...             while(j <= i):
...                     if(i % j== 0):
...                             count = count + 1
...                     j = j+ 1
...             if(count == 2):
...                     print("%d is a Prime Factor of a Given Number %d" %(i, Number))
...     i = i + 1
...
23 is a Prime Factor of a Given Number 23
>>>

Sunday, March 21, 2021

 Addiition of two Number using cpp


#include<iostream.h>

using namespace std;

int main()

{

        int a,b,c;

        cout<<"Enter the value of a:"<<endl;

        cin>>a;

        cout<<"Enter the value of b:"<<endl;

        cin>>b;

        c=a+b;

        cout<<"The addition of a and b is:"<<endl;

        cin>>c;

        return 0;

}