CodeGraderBench/CodeGraderBench huggingface dataset:
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<simplecpp>
#include<cmath>
main_program{
	float a,x;
	int n;
	cin>>a;
	cin>>x;
	cin>>n;
	float ans=sin(a);
	int sg=1;
	for(int i=1;i<=n;i++)
	{
		float fn;
		if(i%2==0)
			fn=sin(a);
		else
			fn=cos(a);
		for(int k=2;k<=i;k=k+2)
			if(k==i)
			sg++;
		
		float p=pow((x-a),(i));
		int fac=1;
		for(int l=1;l<=i;l++)
			fac*=l;
		float tay;
		if(sg%2==0)
			 tay=-((fn*p)/fac);
		else 
			 tay=(fn*p)/fac;
			ans+=tay;
		
	}
	cout<<fixed;
	cout.precision(6);
					   cout<<ans<<" "<<abs(ans-(sin(a)))/abs(sin(a));
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: A
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 <simplecpp>
#include <cmath>
using namespace std;

#define n,0,1
int main()
{
double x0=0 y0=1,h=0,2,y1,y2,y3,y4,y5,yj
y1=3*x0+y0*y0;
y2=3+2*y0*y1;
y3=2*y1*y1+2*y0*y2;
y4=6*y1*y2+2*y0*y3;
y5=6*y1*y3+2*y0*y4;
y=y0+(y1*h)+(y2*pow(h,2)/2+(y3*pow(h,3)/6+(y4*pow(h,4)/24+(y5*pow(h,5)/32)
cout<<fixed;    //uses fixed floating point representation;
cout.precision(6);   //print six digit after the decimal point;
return(0);

}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: B
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()
{
int n, i; 
double a, x, power, factorial, sinx, cosa;
cin >> a >> x;
cin >> n;
while (n){
int i = 1;
factorial = i;
i = i + 1;
return factorial;
break;
}
while(n){
 power = (x-a);
power *= (x-a);
return power;
break;
}
for (int i = 0;i <= n;i++){
sinx =power/factorial*cosa;
}
cout << sinx ;
cout.precision(6);
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: B
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;
long long int fact(int z)
{unsigned long long int fac=1;
 for(int i=z;i>0;i--)
  {fac*=i; 
  } 
return fac;
}

int main()
{float a,x,f=0.0;
 int n;
 cin>>a>>x>>n;
  for(int i=0;i<=n;i++)
   {if(i<=30)
   {
    if(i%4==0)
     {  f+=(float)(pow(x-a,i)*sin(a)/fact(i));
     }
   else if(i%4==1)
     {  f+=(float)(pow(x-a,i)*cos(a)/fact(i));
     }
   else if(i%4==2)
     {  f-=(float)(pow(x-a,i)*sin(a)/fact(i));
     }
   else if(i%4==3)
     {  f-=(float)(pow(x-a,i)*cos(a)/fact(i));
     }
   cout<<f;
   }
  
  }
/*float re=abs((f-sin(a))/sin(a));
cout<<fixed;
cout.precision(6);
cout<<f<<" "<<re;*/
return 0;
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: B
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 <math.h>
using namespace std;
int main()
{float a,x,s,y,c;
 int n;
 cin>>a>>x>>n;
 s=sin(a);
 float e=s;
 for(i=0;i<n;i++)
 if (i++%4==0) c=sin(a);
 else if (i++%4==1) c=cos(a);
 else if (i++%4==2) c=-sin(a);
else if (i++%4==3) c=-cos(a);
 e=e+((pow((x-a),i++))/facval(i++)*c;
 y=(abs(e-s))/s;
cout <<e<<" "<<y;}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: A
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<simplecpp>
main_program
{
double a,x,val=0.0,fac=1.0,p,err;
int n,i,j;
cin>>a>>x>>n;
val=val+ sin(a);
for (i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{fac=fac*j;}
if( (i-1)%3==0)
p=(pow ((x-a),i)*cos (a))/fac;
if( (i-2)%3==0)
p=-(pow ((x-a),i)*sin (a))/fac;
if( i%3==0)
p=-(pow ((x-a),i)*cos (a))/fac;
val=val+p;
}
cout<<fixed;
cout.precision(6);
err=(val-sin (a))/sin(a);
cout<< val <<" "<<err;
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: A
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<simplecpp>
int fact(int f)
{
	int k;
	int j=1;
	for(k=1;k<=f;k++)
	{
		j=j*k;
	}
	return(j);
}

int main()
{
	double a,x,s,multi,taylor,error;
	int n,fact1,i;
	cin >> a >> x >> n;
	s= x - a;
	taylor=sin(a);
	i=1;	
	while (i<=n)
	{
		multi=pow(s,i);
		fact1= fact(i);
		if ( i%4==0)
		{
			taylor=taylor+ ( (multi)/(fact1) )* sin(a);
		}
		else if ( i%4==1)
		{
			taylor=taylor+  ((multi)/(fact1))* cos(a);
		}
		else if ( i%4==2)
		{
			taylor=taylor -  ((multi)/(fact1))*sin(a);
		}
		else if ( i%4==3)
		{
			taylor=taylor -  ((multi)/(fact1))*cos(a);
		}
		i++;
	}
	error= (taylor - sin(a))/(sin(a));
	cout << fixed;
	cout.precision(6);
	cout << taylor << " ";
	cout << fixed;
	cout.precision(6);
	cout << error;

}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: B
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<math.h>
using namespace std;
long double j(int i){
long double b=1;
while(i>1){
b=1/(b*i--);
}
return b;
}
int main(){
int n;
float x,a;
 long double fx=0;
cin>>a>>x>>n;

for(int i=0;i<=n;i++){
switch (i%4){

case 0:fx+=pow(x-a,i)*sin(x)*j(i);break;
case 1:fx+=pow(x-a,i)*cos(x)*j(i);break;
case 2:fx+=pow(x-a,i)*(-sin(x))*j(i);break;
case 3:fx+=pow(x-a,i)*(-cos(x))*j(i);break;

}

}
cout<<fixed;
cout.precision(6);
cout<<fx<<" "<<fabs(sin(x)-fx);
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: B
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,f0,f1,f2,f3,b=1.0,ea,err; int n;
cin>>a>>x>>n;
f0=sin(a);
f1=cos(a);
f2=-sin(a);
f3=-cos(a);
ea=f0;
for (int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{b=(b*(x-a))/j;}
if (i%4==1)
ea=ea+b*f1;
else if(i%4==2)
ea=ea+b*f2;
else if(i%4==3)
ea=ea+b*f3;
else ea=ea+b*f0;
b=1.0;
}
cout<<fixed;
cout.precision(6);
err=(ea-f0)/f0;
cout<<ea<<" ";
if (err>=0)
cout<<err;
else cout<<((-1.0)*err);
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: A