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, 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: 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: 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: 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 <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: 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{
float a,x,n;cin>>a>>x>>n;
float k=x-a;
double f=0,ti;
for(int i=1;i<=n;i++){
double l1,l2,l3;
l1=l2=l3=1;
for(int j=1;j<=i-1;j++)
{
l3=l3*k;l2=l2*j;
}
if(i%2==0){
for(int j=1;j<=(i+2)/2;j++){
l1=l1*(-1);
}
ti=cos(a);
}
if(i%2==1){
for(int j=1;j<=(i+3)/2;j++){
l1=l1*(-1);
}
ti=sin(a);
}
ti=ti*(l1*l3)/l2;
f=f+ti;
}
cout<<fixed;
cout.precision(6);
cout<<f<<" ";
cout<<fabs((f-sin(a))/sin(a))<<endl;
}

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

using namespace std;

int fac(int n){

if(n==1){return 1;}

else{

int i=n-1;

while(i>0){

n=n*i;

i--;

}

return n;

}

}


int main(){

double a,x;int n;

cin >> a >> x >> n;


double len = x-a;

double y =sin(a);

double z;

for(int i=1;i<n+1;i++){

if(i%4==1){z=cos(a);}

else if(i%4==2){z=-sin(a);}

else if(i%4==3){z=-cos(a);}

else{z=sin(a);}

y = y+(((pow(len,i))/fac(i))*z);

}

double err = fabs(y - sin (a))/fabs(sin(a));

cout << fixed;

cout.precision(6);

cout << y << " " << 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: 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>
int f (long long int k){
		if(k==0) return 1;
		long long int c=1;
		for(int i=k;i>0;i=i-1){
					c=c*i;}
		return c;
		}
using namespace std;
int main(){
long double a,x;
long long int n;
cin>>a>>x>>n;
long double sx=0.0;
long double m=(x-a);
for(long long int i=0;i<=n;i++){
	if(i%4==0){sx=sx+(long double)(pow(m,i))*(sin(a))/f(i);}
	if(i%4==1){sx=sx+(long double)(pow(m,i))*(cos(a))/f(i);}
	if(i%4==2){sx=sx-(long double)(pow(m,i))*(sin(a))/f(i);}
	if(i%4==3){sx=sx-(long double)(pow(m,i))*(cos(a))/f(i);}
	}
long double e=fabs((long double)(sx-sin(a))/sin(a));
cout<<fixed;
cout.precision(6);
cout<<sx<<" "<<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;
double factdiv(double term, int  n)
{
 for(int i =n;i>0;i--)
	term =term/i;
return term;
}
int main()
{ double x,a;
  int n;
 cin>>x>>a>>n;
double fx=sin(a);
double tp=0;
for(int i=0;i<=n;i++)
	{double term;
	switch(i%4)
	{
	case 0:term=sin(a);
		break;
	case 1:term=cos(a);
		break;
	case 2:term=-sin(a);
		break;
	case 3:term=-cos(a);
		break;
	}
	double add=(term)*pow(x-a,i);
	add=factdiv(add,i);//cant use factorial directly since even long long int cannot store 100!
	tp=tp+add;

	}
double err = abs((double)(tp-fx)/(double)fx);
cout<<fixed;
cout.precision(6);
cout<<tp<<" "<<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: 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>
double f (int n, double a){
	if (n % 2 == 0) return sin(a);
	else return cos(a);

}
long double facval (int fac) 
	{long double
		 n = 1;
	if (fac == 0) return 1;
	else {                           
    for (int i = fac; i > 0; i--)
		n = n * i;
	return n;}
}

int g(int n){
	if (n % 4 == 0 || n % 4 == 1)
		return 1;
	else return -1;
}
main_program{
	double a, x;
	int n;
	cin >> a >> x >> n;
	double taylor = 0;
	for (int i = 0; i <= n; i++){
		taylor = taylor +(pow(x - a,i) * f(i,a) / facval(i) ) * g(i);
	}
	cout << fixed;     
	cout.precision(6);
	cout << taylor << " " << (taylor - 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