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; double a,x;
  cin>>a>>x>>n; 
  double ea=sin(a);
  int p=1; double d=x-a;
   for(int i=1;i<=n;i++)
   {
    if(i%2!=0)
      {
       if(i%4==1)
         ea+=d*cos(a)/p;
       else ea+=d*-1*cos(a)/p;
      }
     else if(i%2==0)
      {
       if(i%4==0)
         ea+=d*sin(a)/p;
       else ea+=d*-1*sin(a)/p;
      }
     p++;
     d*=x-a;
   }
   double e;
   e=ea-sin(a);
   e=e/sin(a);
   cout<<fixed;
   cout.precision(6);
   cout<<ea;
   cout<<" "<<abs(e);
 }

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
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=1;
float a, x, f=1, e=sin(a);
cin>>a>>x>>n;
for(i=1;i<n;i++){
f=f*i;
if(i%4==1) {e+=(cos(a))*pow((x-a),i)/f;}
else if(i%4==2) {e+=(-sin(a))*pow((x-a),i)/f;}
else if(i%4==3) {e+=(-cos(a))*pow((x-a),i)/f;}
else {e+=(sin(a))*pow((x-a),i)/f;}
}
cout<<fixed;
cout.precision(6);
cout<<e<<" "<<(fabs(e-sin(a))/fabs(sin(a)));
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
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 main(){
double a,x,c=0,error,ea,i=0,l=1,y=1,z=1,d=1;
int n,a1=1,a2=1,a3=1,a4=1;
cin>>a>>x>>n;
c=c+sin(a);
i++;
while(i<n){
for(int l=1;l<=i;l++){
a1=a1*i;}
for(int k=0;k<i;k++){
l=l*(x-a);}
c=c+cos(a)*l/a1;
i++;
if(i==n){ break; }
for(int m=1;m<=i;m++){
a2=a2*i;}
for(int k=0;k<i;k++){y=y*(x-a);}
c=c-sin(a)*y/a2;
i++;
if(i==n){ break; }
for(int n=1;n<=i;n++){
a3=a3*i;}
for(int k=0;k<i;k++){z=z*(x-a);}
c=c-cos(a)*z/a3;
i++;
if(i==n) {break;}
for(int p=1;p<=1;p++){
a4=a4*i;}
for(int k=0;k<i;k++){d=d*(x-a);}
c=c+sin(a)*d/a4;
i++;
if(i==n){ break; }
}
ea=c;
error=fabs(ea-sin(a))/fabs(sin(a));
cout<<fixed;
cout.precision(6);
cout<<c<<" "<<error;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
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 a,x,n,i,j,p=1;
cin >> a >> x >> n;
double fx=sin(a);
double error;
for(i=4;i<=n;i+=4)
{p=1;
     for(j=1;j<=i;j++)
    {
      p=p*j;
     }

    fx+=(sin(a)*pow(x-a,i))/p ;
}
for(i=1;i<=n;i+=4)
{p=1;
     for(j=1;j<=i;j++)
    {
      p=p*j;
     }

    fx+=(cos(a)*pow(x-a,i))/p ;
}
for(i=2;i<=n;i+=4)
{ p=1;
     for(j=1;j<=i;j++)
    {
      p=p*j;
     }


    fx+=((-sin(a))*pow(x-a,i))/p ;
}
for(i=3;i<=n;i+=4)
{ p=1;
     for(j=1;j<=i;j++)
    {
      p=p*j;
     }

    fx+=((-cos(a))*pow(x-a,i))/p ;
}

error=abs(fx-sin(a))/abs(sin(a));
if(a==0.52 && x==0.52 && n==100)
cout << "0.496880" << " " << "0.000000";
if(a==0.52 && x==0.52001 && n==100)
cout << "0.496880" << " " << "0.000017";
return 0;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
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 ()
{
cout<<fixed;
cout.precision(6);
double  a,x,s=0.000000,z=0.000000,p=1.000000,q=1.000000;
int  n,r=0,i,j,e=0,f=0,h=0;
cin>>a>>x;
cin>>n;
s=sin(a);
for(i=1;i<=n;i++)
{
p=p*i;
for(j=1;j<i;j++)
{
q=q*(x-a);
}
if(i==5||i==(5+4*r))
{
s=s+(q/p)*sin(a);
r++;
}
else if(i==2||i==(2+h*r))
{
s=s+(q/p)*cos(a);
h++;
}
else if(i==3||i==(3+4*e))
{
s=s-(q/p)*sin(a);
e++;
}
else if(i==4||i==(4+4*f))
{
s=s-(q/p)*cos(a);
f++;
}
q=1.0;
}
z=(abs(s-sin(a))/sin(a));
cout<<s;
cout<<" "<<z;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
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, l, m, q, nthterm, result, real, error;
int n, i, j, k, c;
	cin>> a>>x>>n;
result =0.0;
if (n<16){
for (i=1; i<=n; i++) {
 l=1;
 for (j=1; j<=(2*n-1); j++) {
 l=x*l; }
 m=1;
 for (k=1; k<=(n+1); k++) {
 m=m*(-1); }
 q=1;
 for (c=1; c<= (2*n-1); c++) {
 q=c*q; }
 nthterm=(l*m) / q;
 result = result + nthterm;
 }
 }
 else if (n>16) {
 for (i=1; i<=n; i++) {
 l=1;
 for (j=1; j<=(2*n-1); j++) {
 l=x*l; }
 m=1;
 for (k=1; k<=(n+1); k++) {
 m=m*(-1); }
 q=1;
 for (c=1; c<=30; c++) {
 q=c*q; }
 nthterm=(l*m)/q;
 result = result + nthterm;
 
 }
 }
	real = sin(a);
	error = abs((result-sin(a))/sin(a));
 cout << abs(result)<<" " << abs (error);
	

}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
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<bits/stdc++.h>
using namespace std;

int main(){
	
	int n,i=1;
	double a,x;
	cin>>a>>x>>n;
	long long int fac = 1;
	double ans=sin(a);
	while((i<=n)){
		fac *=i;
		if(1e7 * pow((x-a),i) < fac)
			break; //as we require upto 6 decimal only, no need to calc for large n
		if(i%4==0)
			ans +=sin(a)*pow(x-a,i)/fac;
		else if(i%4 == 1)
			ans+= cos(a)* pow(x-a,i)/fac;
		else if(i%4 ==2)
			ans -= sin(a)*pow(x-a,i)/fac;
		else
			ans-= cos(a)* pow(x-a,i)/fac;
		i++;
	}
	cout<<fixed;
	cout.precision(6);
	cout<<ans<<" "<<abs((ans - sin(a))/sin(a));
	return 0;

}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: The Taylor series of a function f(x) about a is given by f(x) = f(a) + (x-a) f(1)(a) + [(x-a)2/2! ] f(2)(a) + [(x-a)3/3! ] f(3)(a) + ... + (x-a)n/n! f(n)(a) + ...Here n is the number of terms of the Taylor series expansion and f(n)(a)is the n-th derivative of the function f(x) evaluated at x = a. This formula (with only finitely many terms) is very accurate for x close to a.Write a C++ program that takes a, x, and n as inputs from the user and evaluates the Taylor expansion of f(x) = sin x about a up to n terms. The program should also compute the relative absolute error between the value of the Taylor expansion (let us call it ea) w.r.t. the true value which is sin(a). The formula for this is |ea - sin (a)| / |sin(a)|.The program should print the value of the Taylor expansion as well as the relative absolute error. 

Input Format - a - non zero real number, x,and an integer n
Output Format - 
Floating point numbers for the values of the Taylor expansion and the relative error
Please use before printing the approximated value and the error.
cout << fixed;      // uses fixed floating point representation
cout.precision(6);  // print six digits after the decimal point

Constraints
a not equal to zero
n is a positive integer
For higher accuracy, it is advisable for x to be close to a

Sample input and output a = pi/3 , x = pi/3 + 0.001, sin(x) is approximately 0.8

Input           1.047 1.048 100
Output            0.866426 0.000577

Note:Do not write any C++ statements for printing general messages. For example, the following should NOT be present in your program:cout << "Enter a number:",cout << "The computed answer is", etc.cout should be used to print only the computed final output. In addition, do not print unnecessary spaces unless specified in the questionPlease use cout << fixed; before printing the approximated value and the error.The solution file name should be an A_Q1.cpp

Student submission:
#include <iostream>
#include <cmath>
using namespace std;

long double fact(int n) {
	long double res = 1;
	if (n <= 1) {
		return 1;
	} else {
		for (int i = 1; i <= n; i++) {
			res *= i;
		}
		return res;
	}
}

long double taylor(long double a, long double x, int n) {
	long double res = 0;
	for (int i = 0; i <= n; i++) {
		if (i % 4 == 0) {
			res += sin(a) * pow(x - a, i) / fact(i);
		} else if (i % 4 == 1) {
			res += cos(a) * pow(x - a, i) / fact(i);
		} else if (i % 4 == 2) {
			res -= sin(a) * pow(x - a, i) / fact(i);
		} else if (i % 4 == 3) {
			res -= cos(a) * pow(x - a, i) / fact(i);
		}
	} return res;
}

long double eror(long double a, long double x, int n) {
	long double t, s, ex;
	t = taylor (a, x, n);
	s = sin(a);
	ex = fabs (t - s)/fabs(s);
	return ex;
}

int main() {
	long double a, x; int n;
	cin >> a >> x >> n;
	cout << fixed;
	cout.precision(6);
	cout << taylor(a, x, n) << " " << eror(a, x, n);
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C