Write a c program sin x x x33 x55 x77 x99 where x is in

Write a c++ program sin x = x - (x^3/3!) + (x^5/5!) - (x^7/7!) + (x^9/9!)... where x is in radian. Cos x = 1 - (x^2/2!) + (x^4/!) - (x^6/6!) + (x^8/8!)... where x is in radian. Write two function g(x) = and h(x) = cos(x) using the series above to obtain accuracy to 5 decimal places. Write a C++ program that use the functions above to calculate f(n) for n = theta to 6 where f(b) = 5g(n)* h(4000*PI*n + PI/3) = 5 sin(n)* cos(4000*PI*n + PI/3) Run Output Format Requirement n 5sin(n) cos(4000*PI*n + PI/3) f(n)

Solution

The C++ program code is shown below:

//Include libraries

#include <iostream>

#include <fstream>

#include <stdlib.h>

#include <cmath>

#include <iomanip>

using namespace std;

//Declare variables

int deg;

const double pi = 3.1415;

/*Function prototypes */

double fact (int f);

double power(double x, int y);

double sine(double x);

double cosine(double x);

//Define main

int main()

{

     //Declare variables

     char zzz;

     double x= 0.0;

     const double pi = 3.1415;

     double z = (4000*pi*x)+(pi/3);

     //Define conversion factor

     int deg=x*(180)/pi;

     //Display results

cout << endl << \" Degrees\" << \"    Sine\"<<\"            Cosine\"<<endl;

cout << endl << \"   \" << 0 << \"           \"<< sine(0)<<\"              \"<< cosine(0); //display sin and cos of 0

     //Loop until condition

     while (x < 0.7853)

     {

          //Increment x

          x = x + 0.0872664626;

          //Convert to degrees

          deg=x*(180/pi);

          //Display results

cout << endl << \"   \" << deg << \"      \"<< 5*sine(x)<<\"    \"<<cosine(x);

     }

     cout << endl;

     cout << \"Enter a character to end.\ \";

     cin >> zzz;

     //Pause console window

     system(\"pause\");

     //Return 0

     return 0;

}

//Define fact()

double fact(int x)

{

     //Declare variable

     double f=1.0;

     //Loop until value

     for (int i=1; i<=x; i++)

     {

          //Set f

          f=f*i;

     }

     //Return f

     return f;

}

//Define power()

double power (double x, int y)

{

     //Delare variable

     double p=1.0;

     //Loop until y

     for (int i=1; i<=y; i++)

     //Set p

     p=p*x;

     //Return p

     return p;

}

//Define sine()

double sine (double x)

{

     //Declare variables

     double sum_positive = 0.0;

     double sum_negative= 0.0;

     double output = 0.0;

     const double pi = 3.1415;

     //Loop until 1000

     for (int i=1; i<=1000; i+=4)

     {

          //Define formula

sum_positive = sum_positive + (power (x,i) / fact (i));

     }

     //Loop until 1000

     for (int i=3; i<=1000; i+=4)

     {

          //Define formula

sum_negative = sum_negative + (power (x,i) / fact (i));

     }

     //Set output

     output = (sum_positive - sum_negative);

     //Return output

     return output;

     //Retuen deg

     return deg=x*(180)/pi;

}

//Define cosine()

double cosine (double x)

{

     //Declare variables

     double sum_positive = 0.0;

     double sum_negative= 0.0;

     double output=0.0;

     const double pi = 3.1415;

     //Loop until 1000

     for (int i=4; i<=1000; i+=4)

     {

          //Define formula

sum_positive = sum_positive + (power (x,i) / fact (i));

     }

     //Loop until 1000

     for (int i=2; i<=1000; i+=4)

     {

          //Define formula

sum_negative = sum_negative + (power (x,i) / fact (i));

     }

     //Set output

     output = (1 - (sum_negative) + (sum_positive));

     //Return output

     return output;

     //Return deg

     return deg=x*(180)/pi;

}

Sample Output:

Degrees    Sine            Cosine

   0           0              1

   5      0.435779    0.996195

   10      0.868241    0.984808

   15      1.2941    0.965926

   20      1.7101    0.939693

   25      2.11309    0.906308

   30      2.5    0.866025

   35      2.86788    0.819152

   40      3.21394    0.766044

   45      3.53553    0.707107

Enter a character to end.

x

Press any key to continue

 Write a c++ program sin x = x - (x^3/3!) + (x^5/5!) - (x^7/7!) + (x^9/9!)... where x is in radian. Cos x = 1 - (x^2/2!) + (x^4/!) - (x^6/6!) + (x^8/8!)... wher
 Write a c++ program sin x = x - (x^3/3!) + (x^5/5!) - (x^7/7!) + (x^9/9!)... where x is in radian. Cos x = 1 - (x^2/2!) + (x^4/!) - (x^6/6!) + (x^8/8!)... wher
 Write a c++ program sin x = x - (x^3/3!) + (x^5/5!) - (x^7/7!) + (x^9/9!)... where x is in radian. Cos x = 1 - (x^2/2!) + (x^4/!) - (x^6/6!) + (x^8/8!)... wher
 Write a c++ program sin x = x - (x^3/3!) + (x^5/5!) - (x^7/7!) + (x^9/9!)... where x is in radian. Cos x = 1 - (x^2/2!) + (x^4/!) - (x^6/6!) + (x^8/8!)... wher
 Write a c++ program sin x = x - (x^3/3!) + (x^5/5!) - (x^7/7!) + (x^9/9!)... where x is in radian. Cos x = 1 - (x^2/2!) + (x^4/!) - (x^6/6!) + (x^8/8!)... wher

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site