Skip to main content

Complex Nos

Include:
iostream.h
conio.h
stdlib.h

class complex
{
float x,y;

public:

complex()
{
}
complex(float real,float imaginary)
{
x=real;
y=imaginary;
}

complex operator+(complex c);
complex operator-(complex c);
complex operator*(complex c);
complex operator/(complex c);

void display()
{
cout<
}
};


// Overloading Operator " - "
complex complex::operator-(complex c)
{
complex temp;
temp.x=x-c.x;
temp.y=y-c.y;
return temp;
}

// Overloading Operator " * "
complex complex::operator*(complex c)
{
complex temp;
temp.x=x*c.x;
temp.y=y*c.y;
return temp;
}

// Overloading Operator " + "
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return temp;
}

// Overloading Operator " / "
complex complex::operator/(complex c)
{
complex temp;
temp.x=x/c.x;
temp.y=y/c.y;
return temp;
}



void main()
{
float a,b,c,d;
int ch;
clrscr();

complex c1,c2,c3;
cout<<"\n--------Operation on Complex Numbers-------";


do
{
cout<<"\n1.Default operation";
cout<<"\n2.Addition";
cout<<"\n3.Substraction";
cout<<"\n4.Multiplication";
cout<<"\n5.Division";
cout<<"\n6.Exit" ;
cout<<"\n\nEnter Your Choice : ";
cin>>ch;

switch(ch)
{

case 1: c1=complex(2.1,3.3);
c2=complex(3.4,5.8);
cout<<"\nEquation 1 : ";
c1.display();

cout<<"\nEquation 2 : ";
c2.display();

cout<<"\nAddition : ";
c3=c1+c2;
c3.display();

cout<<"\nsubstraction : ";
c3=c1-c2;
c3.display();

cout<<"\nMultiplication : ";
c3=c2*c1;
c3.display();

cout<<"\nDivision : ";
c3=c1/c2;
c3.display();
break;

case 2: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;
c1=complex(a,b);
c2=complex(c,d);

cout<<"\nEquation 1 : ";
c1.display();

cout<<"\nEquation 2 : ";
c2.display();

cout<<"\nAddition : ";
c3=c1+c2;

c3.display();
break;

case 3: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;

c1=complex(a,b);
c2=complex(c,d);

cout<<"\nEquation 1 : ";
c1.display();

cout<<"\nEquation 2 : ";
c2.display();

cout<<"\nSubstraction : ";
c3=c1-c2;
c3.display();

break;


case 4: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;

c1=complex(a,b);
c2=complex(c,d);

cout<<"\nEquation 1 : ";
c1.display();

cout<<"\nEquation 2 : ";
c2.display();

cout<<"\nMultiplication : ";
c3=c2*c1;
c3.display();

break;

case 5: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;

c1=complex(a,b);
c2=complex(c,d);
cout<<"\nEquation 1 : ";
c1.display();

cout<<"\nEquation 2 : ";
c2.display();

cout<<"\nDivision : ";
c3=c1/c2;
c3.display();

break;

case 6:exit(0);
}
} while(1);
}

Comments

Popular posts from this blog

Selenium + Python + UnexpectedAlertPresentException: Dealing with annoying alerts

Handling  UnexpectedAlertPresentException   Alerts who hates them? I Do!  Who doesn't hate an annoying alert causing your tests / scraping job to fail? I must say they are pretty much on point on the Unexpected part!  Fortunately, there are easy ways to mitigate the issue. 1. Disable alerts completely: driver . execute_script( 'window.alert = function(){};' ); execute this script just before where you anticipate the alert and you're golden. 2. You want to see the alert text but not disturb the execution flow. driver . execute_script( 'window.alert = console.info;' ); Now the alerts have been redirected to the console and you don't have to worry about them. (Unless you have to - then you'd have to monitor the console) 3. You know exactly when it comes and want to accept the alert and move on. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from selenium import webdriver from selenium.webdriver.s...

4. Lex and Yacc Program to detect errors in a 'C' Language Program

Lex and Yacc Program to detect errors in a 'C' Language Program   Lex Code : %{ #include"y.tab.h" #include<stdio.h> int LineNo = 1 ; %} identifier [ a - zA - Z ][ _a - zA - Z0 - 9 ]* number [ 0 - 9 ]+|([ 0 - 9 ]*\.[ 0 - 9 ]+) %% main \(\) return MAIN ; if return IF ; else return ELSE ; while return WHILE ; int | char | flaot return TYPE ; { identifier } return VAR ; { number } return NUM ; \> | \< | \<= | \>= | == return RELOP ; [\ t ] ; [\ n ] LineNo ++; . return yytext [ 0 ]; %% Yacc Code : %{ #include<string.h> #include<stdio.h> extern int LineNo ; int errno = 0 ; %} % token NUM VAR RELOP % token MAIN IF ELSE WHILE TYPE % left '-' '+' % left '*' '/' %% PROGRAM : MAIN BLOCK ; BLOCK : '{' CODE '}' ; CODE : BLOCK | STATEMENT CODE | STATEMENT ; STATEMENT : DECST ';' | DECST { printf ( "\nLine number %d...

Python Program for Soundex Algorithm

This is a python implementation for Soundex Algorithm. This Program builds a JSON document as a dictionary and is kept on building at every execution. Its constantly appended and referenced while the program  is executed. Program: from re import sub def remove_symbols (input_string): #Convert the characters to lower case and then use #Regular expressions to remove non a-z chars return sub( '[^A-Z]+' , '' , input_string) def clean (input_string): #Convert the characters to lower case and then use #Regular expressions to remove non a-z chars return sub( '[^a-z]+' , '' , input_string . lower()) word = "Input" def soundex (word): #Step 1: Capitalize all letters in the word and drop all punctuation marks. word = remove_symbols(word . upper()) #Step 2: Retain the first letter of the word. first_letter = word[ 0 ] word = word[ 1 :] #Step 3 & 4: Change ( 'A...