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 <iostream>
#include <cmath>
using namespace std;

int main() {
float a , x , n ,s ,m ,e;
const float pi = 3.14;
cin >> a >> x >> n;
s = sin(a);
m = sin(x) ;
e = (m - sin(a))/sin(a);
cout << fixed ;
cout.precision(6);
cout << m << " " << e;}

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: 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;
int main(){
double a,x,ea; int n;
cin>>a;
cin>>x;
cin>>n;
ea=0;
for(int i=0;i<=n;i++){
    if(i%4==0){
        int k=i;
        int l;
        for(int j=k-1;j>1;j--){
        if(k!=0){k*=j; l=k;}
        else if(k==0){l=1;}
        }
        ea+=(sin(a)*pow((x-a),i))/l	;
    }
    if(i%4==1){
        int k=i;
        for(int j=k-1;j>1;j--){
        k*=j;
        }
        ea+=(cos(a)*pow((x-a),i))/k;
        }
     if(i%4==2){
        int k=i;
        for(int j=k-1;j>1;j--){
        k*=j;
        }
        ea+=-1*(sin(a)*pow((x-a),i))/k;
    }
     if(i%4==3){
        int k=i;
        for(int j=k-1;j>1;j--){
        k*=j;
        }
        ea+=-1*(cos(a)*pow((x-a),i))/k;
        }


    }

double error=fabs(ea-sin(a))/fabs(sin(a));
cout<<fixed;
cout.precision(6);
cout<<ea;
cout<<" ";
cout<<fixed;
cout.precision(6);
cout<<error;
return 0;
}

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
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 fact (int x){
int i=1, j=1;
if ( x==0 || x==1 )
{
	return 1;
}
else{

for ( int it=0; it<x; it+=1 )
{
	i=j*i;
	j++;
}
return i;

}

}
int main(){
long double a, x, n, fx, L=1, i=2, j=1;
cin>>a>>x>>n;
cout<<fixed;
cout.precision(6);
fx= sin(a);

while(i<n+1)
{
	if (int(i)%2==1 && int(i)%3!=0)
	{
		long double k = sin(a), z;
		for(int it=0; it<i; it+=1 )
		{
			j=j*(x-a);
		}

		z= (j*k)/ fact(i);
		fx=fx+z;
		j==1;
	}

		if (int(i)%2==0 &&int(i)%4!=0)
	{
		long double k = cos(a), z;
		for(int it=0; it<i; it+=1 )
		{
			j=j*(x-a);
		}

		z= (j*k)/ fact(i);
		fx=fx+z;
		j=1;
	}

		if (int(i)%2==1 && int(i)%3==0)
	{
		long double k = -sin(a), z;
		for(int it=0; it<i; it+=1 )
		{
			j=j*(x-a);
		}

		z= (j*k)/ fact(i);
		fx=fx+z;
		j=1;

	}

		if (int(i)%2==0 && int(i)%4==0)
	{
		long double k = -cos(a), z;
		for(int it=0; it<i; it+=1 )
		{
			j=j*(x-a);
		}

		z= (j*k)/ fact(i);
		fx=fx+z;
		j=1;

	}
	i++;
}

L= fabs(fx-sin(a))/fabs(sin(a));
cout<<fx<<" "<<L;

}

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
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>

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: 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<simplecpp>
main_program{
	float a,x;
	int n;
	cin>>a>>x>>n;
	cout<<fixed;
	cout.precision(6);
	sin(x)=0.8;
	x=pi/3+0.001;
	a=pi/3;
	

}

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: 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;
int main(){
float x,a,t,e,p;
float S=0;
unsigned int f=1;
unsigned int n;
t=x-a;
cin>>a>>x>>n;
for(int i=0; i<n;i++){
p=pow(t,i);
if(i==0){
	f=1;
	S=S +( sin(a)/f);
	}
else if(i%4==1){
	f=f*i;
	S=S +( p*cos(a)/f) ;
	}
else if(i%4==2){
	f=f*i;
	S=S -( p*sin(a)/f);
	}
else if(i%4==3){
	f=f*i;
	S=S -( p*cos(a)/f);
	}
else if(i%4==0 && i!=0){
	f=f*i;
	S=S + (p*sin(a)/f);
	}

}
e=fabs((S-sin(a))/sin(a));
cout<<fixed;
cout.precision(6);
cout<<S<<e;
return 0;
}

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
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 fac=1,n;
int i,j,k;
int tprime=1;
float fdash=0.0,fx=0.0,actual,a,x;
float t=1.0;
float relerror;

int main(){
	cin >> a;
	cin >> x;
	
    cin >> n;
    relerror=abs(sin(a)-sin(x))/sin(a);

for(i=0;i<=n;i++)
{
	j=i;
	fac=1;
	for(k=1;k<=i;k++)
		{fac=fac*k;}
	while(j>3)
   {
	j=j-4;
   }
	if(j==0)
		fdash=sin(a);
	else if(j==1)
		fdash = cos(a);
	else if(j==2)
		fdash=-sin(a);
	else if(j==3)
		fdash=-cos(a);
	t=pow((x-a),i);
	fx=fx+(t*fdash)/fac;
}
cout.precision(6);
cout << fx;
if (tprime==1){
	cout.precision(4);
cout << relerror;
      }
}

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
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;
	double val=0;
	double fx;
	int fac=1;
	int a1=0,a2=0;
	for(int i=0;i<=n;i++){
	
	if(i%2==0){
	int m1;
	m1=pow(-1,a1);
	fx=m1*sin(x);
	a1++;
	}
	else{
	int m2;
	m2=pow(-1,a2);
	fx=m2*cos(x);
	a2++;
	}
	
	if(i==0){
	fac=1;
	}
	else{
	fac*=i;
	}
	val=val+(fx*(pow(x-a,i)))/fac;
	}
	double error;
	error=abs(val-sin(a))/abs(sin(a));
	cout<<fixed;
	cout.precision(6);
	cout<<val;
	cout<<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
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;
long double func;
const float pi=3.14;
int n;
cin>>n;
a=pi/3;
x=pi/3+0.001;
func=sin(a);
float y;
y=x-a;
float p,q,r,s;
p=sin(a);
q=cos(a);
r=-sin(a);
s=-cos(a);
int i=1;
while(i<=n){
	float tra;
	unsigned long long int f=1;
	float w;
	int j=1;
	while(j<=i){
		f*=j;
		j++;
	}
	w=pow(y,i);
	if(i%4==1){tra=(w*p)/f;}
	else if(i%4==2){tra=(w*q)/f;}
	else if(i%3==0){tra=(w*r)/f;}
	else {tra=(w*s)/f;}
	cout<<tra;
	func+=tra;
	i=i+1;
}
cout<<fixed;
cout.precision(6);
cout<<func;
float relerr;
relerr=abs((func-sin(a))/sin(a))*100;
cout<<relerr;

}

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