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{
double a,x,ea,sinx=0;
int n,i;
unsigned long long int f=1;
cin>>a>>x>>n;
n=n/10;
double b=x-a;
for(i=0;i<n;i++){
	for(int j=i;j>0;j--){if(i==0||i==1){f=1;}
		else{f*=j;}}
	if(i%4==0){
		sinx+=(pow(b,i)*sin(a))*pow(f,-1);}
	else if(i%4==1){
		sinx+=(pow(b,i)*cos(a))*pow(f,-1);}
	else if(i%4==2){
		sinx-=(pow(b,i)*sin(a))*pow(f,-1);}
	else if(i%4==3){
		sinx-=(pow(b,i)*cos(a))*pow(f,-1);}}
ea=fabs(sinx-sin(a))/fabs(sin(a));
cout<<fixed;
cout.precision(6);
cout<<sinx<<" "<<ea;
return 0;
}

Grading criterion: Nth derivative computed correctly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
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<iostream>
#include<cmath>

using namespace std;

int main()
{
 
long  double  a,x,sume=0,sumo=0;
 int n;

 
 cin>>a>>x>>n;

long  double  sum=0;
 n=20;

if(a!=0 &&n>0)
{

 if(n%2 == 0)
    {
	for(int i=1; i<=n/2 ; i++)
	  {
	   int facval=1;

 	  	 for(int k=1; k<=2*i ; k++)
			facval=facval*k;

	  long double j= pow(x-a,2*i);
	  sume=sume+ ( (pow(-1,i)*j) /facval );

	  }

	sume=(sume+1)*sin(a);

	for(int i=1; i<=n/2 ; i++)
	 {
	  int facval=1;

		for(int k=1; k<=2*i-1 ; k++)
			facval=facval*k;

	long double j=pow(x-a,2*i-1);

	sumo=sumo + ( ( pow(-1,i+1)*j )/facval ); 

	}

 sumo=sumo*cos(a);
 sum=sumo+sume;

 cout<<fixed;
 cout.precision(6);
 cout<<sum;

long double t=fabs(sum-sin(a))/fabs(sin(a));

cout<<" "<<t;

    } 

}

}

Grading criterion: Nth derivative computed correctly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
Assigned grade: C
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 fn){
long long int f=1;
for(int k=1; k<=fn; k++){
f=f*k;}
return f;}



double xan(int jn, double a, double x){
double xanv=1;
for(int j=1; j<=jn; j++){
	xanv=xanv*(x-a);}
return xanv;
}


double deriv(int di, double a){
if((di+3)%4==0){return cos(a);}
if(di%2==0 && di%4!=0){return -sin(a);}
if((di+1)%4==0){return -cos(a);}
if(di%4==0){return sin(a);}}



int main(){
double a,x,ans=sin(a);
long long int n;
cin>>a>>x>>n;
cout<<fixed;
cout.precision(6);
for(int i=1; i<=n; i++){
	ans=ans+(xan(i, a, x)/fact(i))*deriv(i, a);
}
cout<<ans<<" ";
cout<<abs(ans-sin(a))/abs(sin(a));
return 0;
}

Grading criterion: Nth derivative computed correctly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
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 factorial(int n){
if (n==0) return 1;
int prod=1;
for(int i=n;i>0;i=i-1) prod*=i;
return prod;}
main_program{
int n;
float a,x;
cin>>a>>x>>n;
float f=sin(a);
float f_;
for(int i=1;i<=n;i++){
if (i%4==1)f_=cos(a);
if (i%4==2) f_=-sin(a);
if (i%4==3) f_=-cos(a);
if (i%4==0) f_=sin(a);
f=f+(pow(x-a,i)/factorial(i))*f_;
}
cout<<fixed;
cout.precision(6);
float b=fabs((f-sin(a))/sin(a));
cout<<f<<b;
}

Grading criterion: Nth derivative computed correctly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
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<iostream>
#include<cmath>
using namespace std;

double f(double x){
	return sin(x);
}

double df(int n, double x){
	if(n%4==0){
		return sin(x);
	}
	else if(n%4==1){
		return cos(x);
	}
	else if(n%4==2){
		return -sin(x);
	}
	else{
		return -cos(x);
	}
}

int main(){
	int n;
	double a, x, s, re;
	cin>>a>>x>>n;
	s=f(a);
	for(int i=1; i<=n; i++){
		double coeff=1;
		for(int j=1; j<=i; j++){
			coeff=coeff*(x-a)/(j);
		}
		s=s+coeff*df(i, a);
	}
	cout<<fixed;
	cout.precision(6);
	re=fabs((s-f(a))/f(a));
	cout<<s<<" "<<re;
	return 0;
	
}

Grading criterion: Nth derivative computed correctly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
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<iostream>
#include<cmath>
using namespace std;
int main()
{
float n,x,a,b=0.0;
cin>>n;
int i=1;
int facval=1;
repeat(2*n) {
repeat((2*n)-1) {
facval=facval*i;
i=i+1;
}
a=((pow(-1,i+1)*(pow(x,(2*i)-1)))/facval;
b=b+a;
n=n+1;
}
cout<<b-sinx;
}

Grading criterion: Nth derivative computed correctly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
Assigned grade: D
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;

double f(double d, int n){ //generates the rational part of the nth term
double tn=1;
for(int i=0; i<n; i++){
tn=(tn*d)/(i+1);
}
if((n/2)!=((n/2)/2)*2) tn= (-1)*tn;
return tn;
}


int main(){

double x, a, t1, t2, ea, error;
int n;
cin>>x>>a>>n;
t1=t2=0;
double d= (x-a);

int i=0;
while(i<=(n/2)*2+4){    //computes the sin sequence
t1=t1+f(d, i);
i=i+2;
}

int j=n;
if(n-(n/2)*2==0) j=n-1;

int k=1;              //computes the cos sequence
while(k<=j+4){
t2=t2+f(d, k);
k=k+2;
}

ea=sin(a)*t1+cos(a)*t2;

error=abs((ea-sin(a))/sin(a)); //computes relative error

cout << fixed;      // uses fixed floating point representation
cout.precision(6);  // print six digits after the decimal point

cout<<ea<<" "<<error<<endl;

}

Grading criterion: (x^n)/n! term calculated correctly
Rating A: fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
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 <iostream>
#include <cmath>


using namespace std;

float fact(int u)
{

float fres = 1 ;
for( int j =1 ; j <= u ; j++)
{
fres *=j ;
}

return fres ;

}

float deri(float v, int b)
{

if(b%4 == 0)
{
return sin(v);
}

else if(b%4 == 1)
{
return cos(v);
}

else if(b%4 == 2 )
{
return -sin(v);
}

else if (b%4 == 3)
{
return -cos(v);
}


}

float power(float x , int y)
{
float prod = 1;

for(int i = 0 ; i < y; i++)
{
prod *= x ;

}

return prod;


}

int main()
{
float x , a , sum = 0, relerror;
int n ;
cin >> x >> a >> n ;



for(int i = 0 ; i < n ; i++)
{
 sum += float(deri(a, i))*float(pow(x-a, i))/fact(i);

}

relerror = abs(sin(a)-sum)/abs(sin(a));

cout << fixed ;
cout.precision(6);

cout << sum << " " << relerror  ;

return 0 ;


}

Grading criterion: (x^n)/n! term calculated correctly
Rating A: fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
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 <iostream>
using namespace std;
int main() {
int i,a,x,n;
cin >> a>>x>>n;
for(i=0;i<=n,i++;)
cout<<"sinx";}

Grading criterion: (x^n)/n! term calculated correctly
Rating A: fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
Assigned grade: D