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

j=j+1;

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


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

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

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

Grading criterion: 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 fact(int q){
int fac=1;
for(int s=1;s<=q;s++){
fac=fac*s;
}
return fac;
}

int main(){ 
float a,x; int n;
cin>>a>>x>>n;
float sum=0.0; float f;
for(int i=0;i<=n;i++){
if(i%4==0){f=sin(a);}
else if(i%4==1){f=cos(a);}
else if(i%4==2){f=-sin(a);}
else if(i%4==3){f=-cos(a);}

sum=sum+pow(x-a,i)/fact(i)*f;
}
cout<<sum;
}

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 <simplecpp>
main_program{
	float a,x,df,f,error,j;
	unsigned int n,i;
	long double fact;
	cin>>a>>x>>n;
	i=0;
	f=0;
	fact=1;
	while (i<=n){
	if (i%4==0) df=sin(a);
	else if (i%4==1) df=cos(a);
	else if (i%4==2) df=sin(a)*(-1);
	else df=cos(a)*(-1);
	j=i;
	while (j>0){
	fact*=1/j;
	j-=1;
	}
	f+=(pow((x-a),i))*df*fact;
	i+=1;
	fact=1;
	}
	error=(abs(sin(a)-f))/sin(a);
	cout<<fixed;
	cout.precision(6);
	cout<<f<<" "<<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<simplecpp>
main_program{
	float a;
	cin >> a;
	float x;
	cin >> x;
	int n;
	cin >> n;
	float arr[(n+1)];
	float sum = sin(a);
	for(int i=1; i<=n; i=i+4)
	{
		arr[i] = cos(a);
	}
	
	for(int i=0; i<=n; i=i+4)
	{
		arr[i] = sin(a);
	}
	
	for(int i=2; i<=n; i=i+4)
	{
		arr[i] = -1*sin(a);
	}
	
	for(int i=3; i<=n; i=i+4)
	{
		arr[i] = -1*cos(a);
	}
	int fac[(n+1)];
	int j = 1;
	int k = 1;
	for(int i=1; i<=n; i++)
	{
		j = j*k;
		fac[i] = j;
		k++;

	}
	
	for(int i=1; i<=n; i++)
	{
		sum = sum + (pow((x-a),i)*arr[i])/fac[i];
	}
	
	float errval;
	
	if(sin(a)>0)
	{
		errval = (sum - sin(a))/sin(a);
		
	}
	else
	{
		errval = (sin(a)-sum)/sin(a);
	}
	
	cout << fixed;
	cout.precision(6);
	cout << sum << " " << errval;
	
	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 <iostrem>;
usingname space std;
intmain(){

	let a=pi/3 ;
	 let x = pi/3 + 0.001;
	
	
	
	
	
	cout << fixed;      // uses fixed floating point representation
cout.precision(6);  // print six digits after the decimal point

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