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
|
void Sineequations::getX()
{
double tempX;
int tempN;
char tempDegreeType, repeatCheck = 'Y';
while (repeatCheck == 'Y' || repeatCheck == 'y') {
cout << "Sup nigga, just wondering what the value of X might be.\nCould you give it to me?\n";
cin >> tempX;
cout << "\nOkay now would that numba be in Radians or Degrees?\nSay R for radians and D for degrees. I ain't good at listening to long words.\n";
cin >> tempDegreeType;
cout << "\nOkay so how many sumations ya want me ta do?\n";
cin >> tempN;
while (tempN < 1) {
cout << "\nPlease give a positive number for number of sumations.\n";
cin >> tempN;
}
sineMath(tempX, tempN, tempDegreeType);
cout << "\nWould you like to try another value for x? Y/N\n";
cin >> repeatCheck;
}
}
void Sineequations::sineMath(double x, int N, char degree)
{
const double PI = 3.14159;
double tempSum = 0, sum = 0, numerator;
int n = 0, factProduct = 1, factorial;
if (degree == 'D' || degree == 'd') {
x = (x*PI) / 180;
cout << "\nDegree converted to Radians = " << x << endl;
}
while (N >= 0) {
factorial = ((2 * n) + 1);
while (factorial > 0) {
factProduct = factorial*factProduct;
cout <<"F: "<< factorial <<" FP: "<< factProduct << endl;
factorial--;
}
numerator = ((pow(-1, n))*(pow(x, (2 * n + 1))));
cout << "N: " << N << ", n: " << n << ", factProduct: " << factProduct << " numerator: " << numerator << endl;
tempSum = (numerator / factProduct);
cout << "tempSum: " << tempSum << endl;
n++;
factProduct = 1;
sum += tempSum;
cout << "sum: " << sum << endl;
N--;
}
cout << "Here is the value of sine: " << sum << endl;
}
|