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()
{
int n,i,fac=1,p;
long double a,x,e=0,d,out;
cin>>a>>x>>n;
for(i=0;i<=n;i++)
{
if(i==0)
fac=1;
else
fac=fac*i;

p=i/2;
if((i%2)==0)
d=sin(a)*pow((-1),p);
else d=cos(a)*pow((-1),p);

e=e+((pow((x-a),i)/(float)fac)*d);
}
cout<<fixed;
cout.precision(6);
cout<<e<<" ";
out=fabs(e-sin(a))/fabs(sin(a));
cout<<fixed;
cout.precision(6);
cout<<out;
}

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>
main_program {
double a;
int x;
int n;
double f(x) ==0;
double f(x) = sin(x);
cin>> a>> x>> n;
double f^n (a) = f ^n (x) while x=a;
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) + ... ;
cout>> f(x);

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<math.h>

using namespace std;

int main()

{
int n=1;
int x,a,f,i;
float e;
char l;
cin>>a>>x>>n;
for(i=1;i<=n;i++)
{
int j=1;
int facval=1;
for(int it=0;it<n;it=it+1)
facval=facval*j;
j=j+1;
}
int facval;
if(n%4==0)l=sin(x);
else if(n%4==1)l=cos(x);
else if (n%4==2)l=-sin(x);
else if(n%4==3)l=-cos(x);
f=((x-a)^(n-1))*l/facval;
cout<<f<<" ";

e=abs(f-sin(a))/abs(sin(a));
cout<<fixed;
cout.precision(6);
cout<<e;
}

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<math.h>
using namespace std;

int factorial(int x){
  int m = 1;
  if(x<2){return 1;}
  else{for(int i = 1;i<=x; i++){
     m = m*i;
  }
  return m;

  }

}

int main(){
  float a,x;
  int n;
  float num1 = 0.0,num2 = 0.0;
  cin>>a>>x>>n;
  for(int i=0; i<n; i++){
    if(i%2 == 1){
    int l = factorial(i);
    num1 = num1+(float(pow((x-a),i))*cos(a))/float(l);}
    else{
    int k = factorial(i);
    num2 = num2+(float(pow((x-a),i))*sin(a))/float(k);}
  }
  cout<<fixed;
  cout.precision(6);
  float num3 = num1+num2;
  cout<<num3;

  cout<<(float)(sin(a)-num3)/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: 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;
float f(int a){
int x=1;
while (a>0){
x=x*a;
a--;}
return x;}
int main(){
int  n;
double a,x,o=0,d;
cout<<fixed;
cout.precision(6);
cin>>a>>x>>n;
d=x-a;
//if (n>30) n=30;
int i=0;
while (i<=n && f(i)/fabs(pow(d,i)<pow(10,45))){
switch (i%4){
case 0:o=o+pow(d,i)/f(i)*sin(a);break;
case 1:o=o+pow(d,i)/f(i)*cos(a);break;
case 2:o=o+pow(d,i)/f(i)*sin(a)*-1;break;
case 3:o=o+pow(d,i)/f(i)*cos(a)*-1;break;}
i++;
//if (o) break;
}
double e=fabs(o-sin(a))/fabs(sin(a));
cout<<o<<" "<<e;
}

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<math.h>
using namespace std;

int fct(int n){
int pro=1;
for(int x=1;x<=n;x++){pro=pro*x;}
return pro;

}
int main(){
long double x,a,s,d;
const double pi=22/7;
int n;
cin>>a;
cin>>x;
cin>>n;
d=x-a;
s=sin(a);
if (n<10){for(int i=1;i<=n;i++){
if(i%4==1){s=s+(cos(a)*pow(d,i))/(fct(i));}
else if(i%4==2){s=s-(sin(a)*pow(d,i))/(fct(i));}
else if(i%4==3){s=s-(cos(a)*pow(d,i))/(fct(i));}
else if(i%4==0){s=s+(sin(a)*pow(d,i))/(fct(i));}}}
else{
for(int i=1;i<=10;i++){
if(i%4==1){s=s+(cos(a)*pow(d,i))/(fct(i));}
else if(i%4==2){s=s-(sin(a)*pow(d,i))/(fct(i));}
else if(i%4==3){s=s-(cos(a)*pow(d,i))/(fct(i));}
else if(i%4==0){s=s+(sin(a)*pow(d,i))/(fct(i));}
}

}
cout<<fixed;
cout.precision(6);
cout<<s<<" ";
cout<<abs((s-sin(a))/sin(a));


}

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>
#include<math.h>
using namespace std;


main_program{

	int n;
	float a,x;
	cin >> a >> x >>n;
	float t = x-a;
	float c = t;
	float sum = sin(a);
	for(int i=1; i<=n;i++){
		if(i%4==1){
			sum += c*(cos(a));
		}
		if(i%4 == 2){
			sum += c*(sin(a))*(-1);
		}
		if(i%4 == 3){
			sum += c*(cos(a))*(-1);
		}
		if(i%4 == 0){
			sum += c*(sin(a));
		}
		c *= t;
		c /= (i+1);
	}
	cout << fixed;
	cout.precision(6);
	cout << sum << " ";

	float er = sum - sin(a);
	er /= sin(a);
	cout << fixed;
	cout.precision(6);
	cout << er;

}

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 <math.h>
using namespace std;

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;
}
int main() {
float dx,ea,a,x;
int j,n;
cin >>a >>x >>n;
dx= (x-a);
ea= sin(a);
j=1;
while (j<=n){
if ((j%4)==0){
ea= ea + (pow(dx,j)*sin(a))/factorial(j);
}
else if ((j%4)==1){
ea= ea + (pow(dx,j)*cos(a))/factorial(j);
}
else if ((j%4)==2){
ea= ea + (pow(dx,j)*(-1)*sin(a))/factorial(j);
}
else if ((j%4)==3){
ea= ea + (pow(dx,j)*(-1)*cos(a))/factorial(j);
}

j=j+1;

}
cout << fixed;      // uses fixed floating point representation


cout.precision(6);  // print six digits after the decimal point
cout << ea << " ";
float error;
error= (ea-sin(a))/sin(a); 

if (ea>sin(a) && sin(a)>0) cout << error; 
if (ea>sin(a) && sin(a)<0) cout << (-1)*error;
if (ea<sin(a) && sin(a)>0) cout << (-1)*error;
if (ea<sin(a) && sin(a)<0) cout << error;
   
}

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<math.h>
#include<stdlib.h>
using namespace std;
int main(){
double a,x,n,z,i=1,result,y,fac=1,err,mul;
int t,dif;
cin>>a>>x>>n;
y=(float)x-a;
z=sin(a);
for(;i<=n;i++){
t=i;
dif=t%4;
while(t>0){
fac=fac*t;
t--;}
if (dif==1)mul=sin(a);
else if (dif==2)mul=cos(a);
else if(dif==3)mul=-sin(a);
else if (dif==0)mul=-cos(a);
result=((float)pow(y,i)/(float)fac)*(float)mul;
}
err=(float)abs(result-z)/(float)abs(z);
cout<<fixed;
cout.precision(6);
cout<<result<<" "<<err;
}

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