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<math.h>
using namespace std;
int main(){
float a,x;
int n;
cin>>a>>x>>n;
cout<<fixed;
cout.precision(6);
float f,w;
f=0,w=0;
float t;
for (int i=1; i<n; i++) {if (i%4==0) {t=sin(a);} if (i%4==1) {t=cos(a);} if (i%4==2) {t=-sin(a);} if (i%4==3) {t=-cos(a);}
float r;
r=(x-a);
for (int k=1; k<i; k++) {r=r*(x-a);}
w=w+r*t;}
f=w+sin(a);
float e=abs((f-sin(a))/(sin(a)));
cout<<f<<" "<<e;
}

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: 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 fac (int x){int fac=1;
                while(x>1){fac=fac*x;
                           x=x-1;}
                return fac; } 
int main(){
cout<<fixed;
cout.precision(6);
float a,x;
int n;
float taylor=sin(a);
int p=0,q,r,Q,R;
q=p+1;r=p+2;
int m,fac=1;
Q=fac(q);
R=fac(r);
while(p<n){taylor=taylor+pow(-1,q-1)*cos(a)*(float(pow((x-a),q))/Q)+
                         pow(-1,r-1)*sin(a)*(float(pow((x-a),r))/R);}
                                            
cout<<taylor;
}

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: 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()
{
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: (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 <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: (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
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: (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: 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 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: (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 <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: (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<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: (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<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: (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