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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
#include <iostream> // saves basic input output functions
using namespace std;
int main()
{
char option;
char optionSim;
int sim1, sim2, simSum;
char optionCom;
int comReal1, comImag1, comReal2, comImag2, comSumR, comSumI;
int imag;
int pythag, polarR, polarI, polarA;
do //do while loop, shows menu until user exits
{
// shows Options for the menu
cout << "\n Main Menu" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "1) Simple Number Calculator " << endl;
cout << "2) Complex Number Calculator " << endl;
cout << "3) Calculate Capacitance " << endl;
cout << "4) Calculate Reactance " << endl << endl;
cout << "Q) Quit Program " << endl;
//user input's a number
cout << "Please select an option : ";
cin >> option; // taking option value as input and saving in variable "option"
option = toupper(option); // check for upper case 'Q'
if (option == '1') // Simple Calc
{
cout << "\n Simple Calculator" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "Do you want to do... " << endl;
cout << "1) Addition " << endl;
cout << "2) Subtraction " << endl;
cout << "3) Multiplication " << endl;
cout << "4) Division " << endl;
cout << "5) Go back to main " << endl << endl;
cout << "Please select an option : " << endl;
cin >> optionSim;
if (optionSim == '1')
{
cout << "Please input your numbers: " << endl << endl;
cin >> sim1;
cin >> sim2;
simSum = sim1 + sim2;
cout << "The sum of those numbers are " << simSum << endl << endl;
}
else if (optionSim == '2')
{
cout << "Please input your numbers: " << endl << endl;
cin >> sim1;
cin >> sim2;
simSum = sim1 - sim2;
cout << "The sum of those numbers are " << simSum << endl << endl;
}
else if (optionSim == '3')
{
cout << "Please input your numbers: " << endl << endl;
cin >> sim1;
cin >> sim2;
simSum = sim1 * sim2;
cout << "The sum of those numbers are " << simSum << endl << endl;
}
else if (optionSim == '4')
{
cout << "Please input your numbers: " << endl << endl;
cin >> sim1;
cin >> sim2;
simSum = sim1 / sim2;
cout << "The sum of those numbers are " << simSum << endl << endl;
}
else if (optionSim == '5')
{
cout << "go back " << endl;
}
}
else if (option == '2') // Complex Calc
{
cout << "\n Complex Calculator" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout << "Do you want to do... " << endl;
cout << "1) Addition " << endl;
cout << "2) Subtraction " << endl;
cout << "3) Multiplication " << endl;
cout << "4) Division " << endl;
cout << "5) Go back to main " << endl << endl;
cout << "Please select an option : " << endl;
cin >> optionCom;
if (optionCom == '1') //addition
{
cout << "Given your question in the form '(a +- bi) + (c +- di) the answer will be given in rectangular form" << endl;
cout << "What is the real part of the first number" << endl;
cin >> comReal1;
cout << "What is the imaginary multiplier of the first number" << endl;
cin >> comImag1;
cout << "What is the real part of the second number" << endl;
cin >> comReal2;
cout << "What is the imaginary multiplier of the second number" << endl;
cin >> comImag2;
comSumR = comReal1 + comReal2; //add the real variable, then add the imaginary, put into line below
comSumI = comImag1 + comImag2;
cout <<"Your answer is "<<comSumR<<" + "<<comSumI<<"i" << endl;
}
else if (optionCom == '2')
{
cout << "Given your question in the form '(a +- bi) - (c +- di) the answer will be given in rectangular form" << endl;
cout << "What is the real part of the first number" << endl;
cin >> comReal1;
cout << "What is the imaginary multiplier of the first number" << endl;
cin >> comImag1;
cout << "What is the real part of the second number" << endl;
cin >> comReal2;
cout << "What is the imaginary multiplier of the second number" << endl;
cin >> comImag2;
comSumR = comReal1 - comReal2; //add the real variable, then add the imaginary, put into line below
comSumI = comImag1 - comImag2;
cout <<"Your answer is "<<comSumR<<" + "<<comSumI<<"i" << endl;
}
else if (optionCom == '3')
{
cout << "Given your question in the form '(a +- bi) - (c +- di) the answer will be given in polar form" << endl;
cout << "What is the real part of the first number" << endl;
cin >> comReal1;
cout << "What is the imaginary multiplier of the first number" << endl;
cin >> comImag1;
cout << "What is the real part of the second number" << endl;
cin >> comReal2;
cout << "What is the imaginary multiplier of the second number" << endl;
cin >> comImag2;
comSumR = (comReal1 * comReal2);
comSumI = (comImag1 * comImag2) + (comReal1 * comImag1) + (comReal1 * comImag2);
double sqrt, atan, cos, sin; // <----- This is the part I'm struggling to get
pythag = sqrt((comSumR*comSumR)+(comSumI*comSumI));
polarA = atan (comSumI / comSumR);
polarR = (pythag)*cos(polarA);
polarI = (pythag)*sin(polarA);
cout << "Your answer is "<<polarR<<" + "<<polarI<<"i "<< endl;
}
else if (optionCom == '4')
{
}
else if (optionSim == '5')
{
cout << "go back " << endl;
}
else
{
cout << "That is not an option." << endl;
}
}
else if (option == '3') // Capacitance
{
cout << "Do some Capacitance calcs here." << endl << endl;
}
else if (option == '4') // Reactance
{
cout << "Do a little Reactance calc here." << endl << endl;
}
else if (option == 'Q') // Exit
{
cout << "Terminating Program" << endl << endl << endl;
}
else
{
//Displaying error message
cout << "That is not an option." << endl << endl;
}
} while (option != 'Q'); //condition of do-while loop
cout << "Program is finished!!" << endl << endl << endl;
return 0;
}
|