United Cse
Saturday, 29 November 2014
GCC Compiler
Sunday, 16 November 2014
Complex Arithmetic
/* Complex Numbers
* **Addition
******* *Turbo C++ **16/11/2014 ****Hemanth
{
cout<<"Give REAL part of Complex Number\n"<<endl;
cin>>x;
cout<<"Give IMAGINARY part of Complex Number\n"<<endl;
cin>>y;
void Complex::addition(Complex &a,Complex &b)
{
x=(a.x+b.x);
{
x=(a.x-b.x);
y=(a.y-b.y);
}
void Complex::multiplication(Complex &a,Complex &b)
{
x=(a.x*b.x)-(a.y*b.y);
y=(a.x*b.y)+(a.y*b.y);
{
b.y=(-1*b.y) //Taking Conjugate of num2 and performing multiplication
Complex numerator(2);
numerator.multiplication(a,b);
x=numerator.x/((b.x*b.x)+(b.y*b.y));
y=numerator.y/((b.x*b.x)+(b.y*b.y));
}
void Complex::display(Complex &result)
{
cout<<result.x;
if(result.y<0)
cout<<"-i"<<-1*result.y;
else
cout<<"+i"<<result.y;
}
int main()
{
clrscr();
int option;
Complex result(1);
cout<<"\t\tArithmetic Operations On Complex Numbers\n\n";
cout<<"Enter 1st Complex Number\n"<<endl;
Complex num1;
cout<<"Enter 2nd Complex Number\n"<<endl;
Complex num2;
do{
clrscr();
cout<<"\t\tNUM1: ";
num1.display(num1);
cout<<"\t\tNUM2: ";
num2.display(num2);
cout<<"\n\n\t1.Addition\n\n\t2.Subtraction\n\n\t3.Multiplication\n\n";
cout<<"\t4.Division\n\n\t5.Exit\n\nEnter Your Choice:";
cin>>option;
switch(option)
{
case 1:
result.addition(num1,num2);
cout<<"\nAddition is ";
result.display(result);
break;
case 2:
result.subtraction(num1,num2);
cout<<"\nSubtraction is ";
result.display(result);
break;
case 3:
result.multiplication(num1,num2);
cout<<"\nMultiplication is ";
result.display(result);
break;
case 4:
result.division(num1,num2);
cout<<"\nDivision is ";
result.display(result);
break;
}
getch();
} while(option!=5);
return 0;
}
* **Addition
* **Subtraction
* **Multiplication
* **Division******* *Turbo C++ **16/11/2014 ****Hemanth
*/
#include<iostream.h>
#include<conio.h>
class Complex{
float x,y;
void addition(Complex &,Complex &);
void subtraction(Complex &,Complex &);
void multiplication(Complex &,Complex &);
void division(Complex ,Complex);
void display(Complex &);
Complex(int a)
{
//No Default Values
}
Complex()
{
//OverLoading Constructor To Take Values from Usercout<<"Give REAL part of Complex Number\n"<<endl;
cin>>x;
cout<<"Give IMAGINARY part of Complex Number\n"<<endl;
cin>>y;
}
};void Complex::addition(Complex &a,Complex &b)
{
x=(a.x+b.x);
y=(a.y+b.y);
}
void Complex::subtraction(Complex &a,Complex &b){
x=(a.x-b.x);
y=(a.y-b.y);
}
void Complex::multiplication(Complex &a,Complex &b)
{
x=(a.x*b.x)-(a.y*b.y);
y=(a.x*b.y)+(a.y*b.y);
}
void Complex::division(Complex a,Complex b){
b.y=(-1*b.y) //Taking Conjugate of num2 and performing multiplication
Complex numerator(2);
numerator.multiplication(a,b);
x=numerator.x/((b.x*b.x)+(b.y*b.y));
y=numerator.y/((b.x*b.x)+(b.y*b.y));
}
void Complex::display(Complex &result)
{
cout<<result.x;
if(result.y<0)
cout<<"-i"<<-1*result.y;
else
cout<<"+i"<<result.y;
}
int main()
{
clrscr();
int option;
Complex result(1);
cout<<"\t\tArithmetic Operations On Complex Numbers\n\n";
cout<<"Enter 1st Complex Number\n"<<endl;
Complex num1;
cout<<"Enter 2nd Complex Number\n"<<endl;
Complex num2;
do{
clrscr();
cout<<"\t\tNUM1: ";
num1.display(num1);
cout<<"\t\tNUM2: ";
num2.display(num2);
cout<<"\n\n\t1.Addition\n\n\t2.Subtraction\n\n\t3.Multiplication\n\n";
cout<<"\t4.Division\n\n\t5.Exit\n\nEnter Your Choice:";
cin>>option;
switch(option)
{
case 1:
result.addition(num1,num2);
cout<<"\nAddition is ";
result.display(result);
break;
case 2:
result.subtraction(num1,num2);
cout<<"\nSubtraction is ";
result.display(result);
break;
case 3:
result.multiplication(num1,num2);
cout<<"\nMultiplication is ";
result.display(result);
break;
case 4:
result.division(num1,num2);
cout<<"\nDivision is ";
result.display(result);
break;
}
getch();
} while(option!=5);
return 0;
}
Saturday, 15 November 2014
Guess Game with C++
// Having Problems Executing Program....Comment below
/* A simple GUESS GAME
* Compiled Using Turbo C++
* 14/11/2014 ***Hemanth
*/
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int guess,Random,i;
clrscr();
randomize();
Random=random(101);
cout<<"\t\tGUESS GAME\n\t\tguess a number between 0 and 100\n"<<endl;
for(i=1;i<=5;i++)
{
cout<<"\nEnter your guess"<<endl;
cin>>guess;
if(guess==Random)
{
cout<<"YOU WON!"<<endl;
getch();
exit(0);
}
if(guess>Random)
cout<<"\nSorry,Wrong Guess! Number is less than "<<guess;
if(guess<Random)
cout<<"\nSorry,Wrong Guess! Number is greater than "<<guess;
cout<<"\tChances Left:"<<5-i<<endl;
}
cout<<"\nYour 5 chances are completed.YOU LOST!"<<endl;
cout<<"\ncorrect GUESS is "<<Random;
getch();
return 0;
}
/* A simple GUESS GAME
* Compiled Using Turbo C++
* 14/11/2014 ***Hemanth
*/
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int guess,Random,i;
clrscr();
randomize();
Random=random(101);
cout<<"\t\tGUESS GAME\n\t\tguess a number between 0 and 100\n"<<endl;
for(i=1;i<=5;i++)
{
cout<<"\nEnter your guess"<<endl;
cin>>guess;
if(guess==Random)
{
cout<<"YOU WON!"<<endl;
getch();
exit(0);
}
if(guess>Random)
cout<<"\nSorry,Wrong Guess! Number is less than "<<guess;
if(guess<Random)
cout<<"\nSorry,Wrong Guess! Number is greater than "<<guess;
cout<<"\tChances Left:"<<5-i<<endl;
}
cout<<"\nYour 5 chances are completed.YOU LOST!"<<endl;
cout<<"\ncorrect GUESS is "<<Random;
getch();
return 0;
}
Subscribe to:
Posts (Atom)