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;
	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: 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<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: 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;
int n;
cin>>a>>x;
cin>>n;
double y;
y=x-a;
double p,q,r,s;
p= sin(a);
q= cos(a);
r= -sin(a);
s= -cos(a);
double sumval=p;
for(int i=1;i<=n;i++){
float product=1;
for(int j=1;j<=i;j++){
product=product*j;
}
double pro=1;
for(int k=1;k<=i;k++){
pro*=y;
}
if(i%4==1){
sumval=sumval+(pro*q)/(product);}
else if(i%4==2){
sumval=sumval+(pro*r)/(product);}
else if(i%4==3){
sumval=sumval+(pro*s)/(product);}
else if(i%4==0){double d=(pro*p)/(product);
sumval+=d;}
}
cout<<fixed;
cout.precision(6);
cout<<sumval<<" ";
double t;
t = (fabs(sumval-p))/(fabs(p));
cout<<fixed;
cout.precision(6);
cout<<t;
}

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,k,l;
int n,i,f;
cin>>a>>k;
cin>>n;
double e,t=1;
e=sin(a);
for(i=1; i<=n; i++;)
{
t=pow((k-a),i);
for(j=1 j<=i; j++)
{
f*=j;
}
if(i%4==0)
{e+=(t/f)*sin(a);}
else if(i%4==1)
{e+=(t/f)*cos(a);}
else if(i%4==2)
{e-=(t/f)*sin(a);}
else if(i%4==3)
{e-=(t/f)*cos(a);}
}
l=fabs(e-sin(a))/fabs(sin(a));
cout<<fixed;
cout.precision(6);
cout<<e<<" ";
cout<<l;
}

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{
unsigned int a;
int x;

cin >> a;
cin >> x;

int y = 1 - x + pow (x,3)/ 3 ;! - pow(x,5)/5;! + ;

int i  (y - sin (a) ) ;/ (sin (a));
cout << y ;
cout << i ;
cout << fixed ;
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>
using namespace std;
#include <math.h>
int main()
{
float a,x,error,g,b,c,f;
int n,h,i=1,d;
cin>>a>>x>>n;
b= sin(a);
c= cos(a);
f=sin(a);
for(d=1;d<=n;d++)
{
for(h=1;h<=d;h++)
{
i=i*h;
}
if(d%2==0)
{
g=pow((x-a),d)*b;
f=f+g/i;
}
else
{
g=pow((x-a),d)*c;
f=f+g/i;
}
}
error=abs((f - sin (a)) /(sin(a)));
cout << fixed;
cout.precision(6);
cout<<f;
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: 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<math.h>
using namespace std;

int main()
{
	long double a;
	long double x;
	long int n;
	cin>>a>>x>>n;

	long double T=0;
	long double T1=0;
	long double T2=0;

	double r1=1;
	for(int i=2;i<=n;i+2)
	{
		r1=(r1*(x-a)*(x-a)*(-1))/((i)*(i-1));

		T1=T1+r1;

	}
	T1=T1*(sin(a));

	double r2=(x-a);
	for(int i=3;i<=n;i+2)
	{
		r2=(r2*(x-a)*(x-a)*(-1))/((i)*(i-1));

		T2=T2+r2;

	}
	T2=T2*(cos(a));

	T=T1+T2;

	long double error;

	error=abs((T-sin(a))/(sin(a)));

	cout<<T<<" ";
	cout<<fixed;
	cout.precision(6);
	cout<<error;

	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: 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 x; 
 cin >> x;
 double a; 
 cin>>a;
 cout << fixed;      // uses fixed floating point representation
cout.precision(6);  // print six digits after the decimal point
 double s=0, t=x; 
 int n; cin>>n;
 int k=1;
for(; k<=n; k++)
{
 s = s + t;
 t = - t * x * x/(2*k)/(2*k+1);

}
 double z=(abs(exp(a)- sin (a))/ abs(sin(a)));
 
 cout << s << abs(t) << abs(a) ;
 
 cout <<endl<<sin(x)<< endl<< 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: 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,f,k,sum=0,m=(x-a),l=m;
int n,prod,y=0,z=0;
cin>>a>>x>>n;
while(y<=n){
while(z<y){
m=l*m;
z++;}
if (y == 0) prod=1;
for (int i = y; i > 0; i=i-1){
        prod *= i;}
if(y%4==0){f=sin(a);}
if(y%4==1){f=cos(a);}
if(y%4==2){f=sin(a)*(-1);}
if(y%4==3){f=cos(a)*(-1);}
k=f*m/prod;
sum=sum+k;
y++;}
int err=abs((sum-sin(a))/sin(a));
cout<<fixed;
cout.precision(6);
cout<<sum<<" "<<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: B