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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
//date: 02/08/2014
//Project #3
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;
void sum();
void difference();
void multiplication();
void division();
float real1, real2, imaginary1, imaginary2,sumz, differencez, multiplicationz, divisionz;
char sign1, sign2, complex1, complex2;
int main()
{
cout << "Please enter two complex numbers using the format x+jy or x-jy." << endl;
float real1, imaginary1;
char sign1, complex1;
//Asks the user to input the first complex number
cout << "Enter the first complex number. (in x +- j y format, seperate each with a space.)" << endl;
cin >> real1 >> sign1 >> complex1 >> imaginary1;
if (sign1 == '-')
imaginary1 = (-1)*imaginary1;
cout << real1 << sign1 << complex1 << imaginary1 << endl;
float real2, imaginary2;
char sign2, complex2;
//Asks the user to input the first complex number
cout << "Enter the second complex number. (in x +- j y format, seperate each with a space.)" << endl;
cin >> real2 >> sign2 >> complex2 >> imaginary2;
if (sign2 == '-')
imaginary2 = (-1)*imaginary2;
cout << real2 << sign2 << complex2 << imaginary2 << endl;
// Finds the magnitude of the first complex number
float zmag1;
zmag1 = (sqrt(real1*real1 + imaginary1*imaginary1));
abs(zmag1);
cout << "The magnitude of the first real number is " << abs(zmag1) << endl;
// Finds the magnitude of the second complex number
float zmag2;
zmag2 = (sqrt(real2*real2 + imaginary2*imaginary2));
abs(zmag2);
cout << "The magnitude of the second real number is " << abs(zmag2) << endl;
double pi;
pi = atan(1) * 4;
// Finds the argument of the first complex number
if (real1 > 0 && imaginary1 > 0) {
cout << "The argument of The first imaginary number is " << atan(imaginary1 / real1) << endl;
}
else if (real1 > 0 && imaginary1 < 0) {
cout << "The argument of The first imaginary number is " << atan(imaginary1 / real1) << endl;
}
else if (real1 < 0 && imaginary1 > 0) {
cout << "The argument of The first imaginary number is " << pi + atan(imaginary1 / real1) << endl;
}
else if (real1 < 0 && imaginary1 < 0){
cout << "The argument of The first imaginary number is " << -pi + atan(imaginary1 / real1) << endl;
}
// FInds the argument of the second complex number
if (real2 > 0 && imaginary2 > 0) {
cout << "The argument of The second imaginary number is " << atan(imaginary2 / real2) << endl;
}
else if (real2 > 0 && imaginary2 < 0) {
cout << "The argument of The second imaginary number is " << atan(imaginary2 / real2) << endl;
}
else if (real2 < 0 && imaginary2 > 0) {
cout << "The argument of The second imaginary number is " << pi + atan(imaginary2 / real2) << endl;
}
else if (real2 < 0 && imaginary2 < 0){
cout << "The argument of The second imaginary number is " << -pi + atan(imaginary2 / real2) << endl;
}
sum();
difference();
multiplication();
division();
}
void sum() {
sumz = (real1 + real2) + complex1*(imaginary1 + imaginary2);
cout << sumz;
}
void difference() {
differencez = (real1 - real2) + complex1*(imaginary1 - imaginary2);
cout << differencez;
}
void multiplication() {
multiplicationz = (real1 * real2-imaginary1*imaginary2) + complex1*(real1*imaginary2 +real2 * imaginary1);
cout << multiplicationz;
}
void division() {
divisionz = ((real1 * real2 + imaginary1*imaginary2) + complex1*(real2*imaginary1 - real2 * imaginary2))/(real2*real2+imaginary2*imaginary2);
cout << divisionz;
}
|