Problem: The Taylor series of a function f(x) about a is given by f(x) = f(a) + (x-a) f(1)(a) + [(x-a)2/2! ] f(2)(a) + [(x-a)3/3! ] f(3)(a) + ... + (x-a)n/n! f(n)(a) + ...Here n is the number of terms of the Taylor series expansion and f(n)(a)is the n-th derivative of the function f(x) evaluated at x = a. This formula (with only finitely many terms) is very accurate for x close to a.Write a C++ program that takes a, x, and n as inputs from the user and evaluates the Taylor expansion of f(x) = sin x about a up to n terms. The program should also compute the relative absolute error between the value of the Taylor expansion (let us call it ea) w.r.t. the true value which is sin(a). The formula for this is |ea - sin (a)| / |sin(a)|.The program should print the value of the Taylor expansion as well as the relative absolute error. 

Input Format - a - non zero real number, x,and an integer n
Output Format - 
Floating point numbers for the values of the Taylor expansion and the relative error
Please use before printing the approximated value and the error.
cout << fixed;      // uses fixed floating point representation
cout.precision(6);  // print six digits after the decimal point

Constraints
a not equal to zero
n is a positive integer
For higher accuracy, it is advisable for x to be close to a

Sample input and output a = pi/3 , x = pi/3 + 0.001, sin(x) is approximately 0.8

Input           1.047 1.048 100
Output            0.866426 0.000577

Note:Do not write any C++ statements for printing general messages. For example, the following should NOT be present in your program:cout << "Enter a number:",cout << "The computed answer is", etc.cout should be used to print only the computed final output. In addition, do not print unnecessary spaces unless specified in the questionPlease use cout << fixed; before printing the approximated value and the error.The solution file name should be an A_Q1.cpp

Student submission:
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	float a,x; int n;
	cin >> a >> x;
	cin >>  n;

	float d;
	d = x-a;

	float sum1=0 , sum2=0 , sum3=0 , sum4=0;
	float sum = 0;
	for (int i=0 ; i<=n ; i=i+1)
	{
		int r;
		r = i%4;

		float c,e,f;
		c= pow(d,i);
		e= sin(a);
		f = cos(a);
		int fact =1;
		if( i==0 || i==1)
		{
			fact = 1;
		}
		else
		{
			for (int j=0 ; j<= i-1 ; j=j+1)
			{
				fact = fact*(i-j);
			}
			
		}

		switch(r)
		{
			case 0:
				{
					sum1 = sum1 + float(c*e)/float(fact);
					break;
				}
			case 1:
				{
					sum2 = sum2 + float(c*f)/float(fact);
					break;
				}
			case 2:
                                { 
                                        sum3 = sum3 - float(c*e)/float(fact);
                                        break;
                                }
                        case 3:
                                { 
                                        sum4 = sum4 - float(c*f)/float(fact);
                                        break;
                                }

		}
	}
	
	sum = sum1 + sum2 + sum3 + sum4;
	float error;
        error =fabs ((sum - sin(a))/(sin(a))); 
	cout << fixed;
	cout.precision(6);
	cout << sum << " " << error ;

}

Grading criterion: Series sum calculated correctly
Rating A: Fully correct
Rating B: almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
Assigned grade: C