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 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: Series sum 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>
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: Series sum 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;
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: Series sum calculated 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<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: Series sum 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<cmath>
#include<stdlib.h>
using namespace std;
 int f(int y){
int i=1;
if(y==1 || y==0) return 1;
while(y>0){
i=i*y;
y=y-1;}
return i;}

int main()
{
double a,x,p,q,r,s,t,v1=0,v2=0,v3=0,v4=0,error;
double n,u=0,v=1,w=2,z=3;
cin>>a>>x>>n;
p=sin(a);
q=cos(a);
r=-sin(a);
s=-cos(a);
while(u<=n)
{v1=v1+(pow(x-a,u)/f(u))*p;
u=u+4;}
while(v<=n)
{v2=v2+(pow(x-a,v)/f(v))*q;
v=v+4;}
while(w<=n)
{v3=v3+(pow(x-a,w)/f(w))*r;
w=w+4;}
while(z<=n)
{v4=v4+(pow(x-a,z)/f(z))*s;
z=z+4;}
t=v1+v2+v3+v4;
error= abs(t-p)/abs(p);
cout<<fixed;
cout.precision(6);
cout<<t;
cout<<error;
}

Grading criterion: Series sum calculated 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<simplecpp>
main_program { 
int n,x ;
float a;
cin>>a>>x>>n ;
	x=a
repeat (n){ 
f(x );} 
	i=1
	i++
	cout<<'|ea-sin(a) ;|'/'|sin(a) ;|' ;
	cout << fixed;      // uses fixed floating point representation


cout.precision(6);  // print six digits after the decimal point 
	cout<< 0.866426 0.000577
}

Grading criterion: Series sum 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<cmath>
using namespace std;
int main()
{
double a, x, y;
int n, i=1, factorial=1;
cin>>a>>x>>n;
y=x-a;
n/=10;
double taylor_sum=0, taylor_error, nth_different;
while(i<=n)
{
factorial*=i;
switch(i%4)
{
case 1: nth_different=cos(a); break;
case 2: nth_different=-sin(a); break;
case 3: nth_different=-cos(a); break;
case 0: nth_different=sin(a); break;
}
taylor_sum += ((y*nth_different)/factorial);
i++; y*=y;
}
taylor_error = abs(taylor_sum/sin(a));
taylor_sum+=sin(a);
cout<<fixed; cout.precision(6);
cout<<taylor_sum<<" "<<taylor_error<<endl;
}

Grading criterion: Series sum 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<simplecpp>
main_program
{
double a,x,p,m;
int n,i,f=1,j;
cin>>a>>x;
cin>>n;
double e,t=1;
e=sin(a);
t=x-a;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
f*=j;
t*=t;
}
m=(t/f);
if(i%4==0)
{e+=m*sin(a);}
else if(i%4==1)
{e+=m*cos(a);}
else if(i%4==2)
{e-=m*sin(a);}
else if(i%4==3)
{e-=m*cos(a);}
}
p=fabs(e-sin(a))/fabs(sin(a));
cout<<fixed;
cout.precision(6);
cout<<e<<" ";
cout<<p;
}

Grading criterion: Series sum 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<simplecpp>

int main(){
    float a,x,n,sum=0;
    int i=0,k=1,fac=1;
    float sp=0,cp=0;
    cin>>a>>x>>n;
    while(i>n) {
             if((i+3)%2!=0){  
             sum=sum+( (pow((x-a),i)*sin(x)/fac *pow(-1,sp) ))  ;
             i++; fac=fac*k;
             k++; sp++;
                                                  }

             else {
             sum=sum+( (pow((x-a),i)*cos(x)/fac *pow(-1,cp) ))  ; 
             i++; fac=fac*k;
             k++; cp++;
         }



      }   cout<<fixed;cout.precision(6);
          cout<<sum;
         
          cout<<fixed;cout.precision(6);
         cout<<fabs((sum-sin(a))/sin(a))  ;  
             
    }

Grading criterion: Series sum 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