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<bits/stdc++.h>
#include<cmath>
using namespace std;

double fact(int n) {
   double fact = 1;
    for(; n >= 1 ; n--) {
        fact = n * fact;
    }
    return fact;
}

double powerOfX(double x, double n)
{
    double output = 1;
    while(n > 0) {
         output *= x;
         n--;
    }
    return output;
}

int main(){
    float a, x;
    int n;
    cin >> a >> x >> n;
    double res;
    for(int i = 0; i < n; i++) {
        double term1 = pow(-1, i);
        double term2 = powerOfX(x, 2*i + 1);
        double term3 = fact(2*i + 1);
        res += (term1 * term2) / term3;
    }

    double error = abs(res - sin(a)) / abs(sin(a));

    cout << fixed;
    cout.precision(6);
    cout << res << " " << error;

    return 0;
}

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

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

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

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

Input           1.047 1.048 100
Output            0.866426 0.000577

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

Student submission:
#include<simplecpp>
#include<cmath>

main_program{
double a,x,c,d,e,f,g,h,i,j,k;
int n,y,r,m,o,l;

cin >>a>>x>>n;
m=0;
o=1;
h=1;
d=sin(a);
e=cos(a);
f=-sin(a);
g=-cos(a);
c=x-a;
j=0;

for(y=1;y<=n;y++)
{
r=y%4;

repeat(y-1)
{
h=h*c;
}

if(r==1)i=d;
else if(r==2)i=e;
else if(r==3)i=f;
else if(r==0)i=g;

j=j+(h*i);

}

k=(j-d)/d;
l=m-o;
if(k<0)k=k*l;

cout <<fixed;
cout.precision(6);
cout <<j<<" "<<k;
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
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>
using namespace std;

int main(){
double a,x;
int n;
cin>>a>>x>>n;
double sin=0;
double t=x;
for(int i=1;i<=2*n;i+=2){
sin=sin+t;
t*=(((-1*x)*x)/((i+1)*(i+2)));
}
/*cout<<fixed;
cout.precision(6);
cout<<sin;*/
double sin2=0;
double t2=a;
for(int i=1;i<=2*1000000;i+=2){
sin2=sin2+t2;
t2*=(((-1*a)*a)/((i+1)*(i+2)));
}
double e=abs(sin2-sin);
double re=e/sin2;
cout<<fixed;
cout.precision(6);
cout<<sin<<" "<<re;
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
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<iostream>
#include<cmath>
using namespace std;

int fac(int n){
	if(n==0 || n==1) return 1;
	double pro=1;
	while(n>=2) {pro*=n;n--;}
	return pro;
}

int main(){
	double ea=0,a,x;
	int n;
	cin>>a>>x>>n;
	for(int i=0;i<n;i++){
		if(i%4==0) ea+= pow(x-a,i)*sin(a)/fac(i);
		else if (i%4==1) ea+= pow(x-a,i)*cos(a)/fac(i);
		else if(i%4==2) ea+= pow(x-a,i)*(-sin(a))/fac(i);
		else if(i%4==3) ea+= pow(x-a,i)*(-cos(a))/fac(i);
	}
	double err= fabs(ea-sin(a))/fabs(sin(a));
	cout<<fixed;
	cout.precision(6);
	cout<<ea<<" "<<err;
}

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

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

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

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

Input           1.047 1.048 100
Output            0.866426 0.000577

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

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

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
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 x){int fac=1;
                while(x>1){fac=fac*x;
                           x=x-1;}
                return fac; } 
int main(){
cout<<fixed;
cout.precision(6);
float a,x;
int n;
float taylor=sin(a);
int p=0,q,r,Q,R;
q=p+1;r=p+2;
int m,fac=1;
Q=fac(q);
R=fac(r);
while(p<n){taylor=taylor+pow(-1,q-1)*cos(a)*(float(pow((x-a),q))/Q)+
                         pow(-1,r-1)*sin(a)*(float(pow((x-a),r))/R);}
                                            
cout<<taylor;
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
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<iostream>
#include<cmath> 
using namespace std;
int main()
{
int n,i,fac=1,p;
long double a,x,e=0,d,out;
cin>>a>>x>>n;
for(i=0;i<=n;i++)
{
if(i==0)
fac=1;
else
fac=fac*i;

p=i/2;
if((i%2)==0)
d=sin(a)*pow((-1),p);
else d=cos(a)*pow((-1),p);

e=e+((pow((x-a),i)/(float)fac)*d);
}
cout<<fixed;
cout.precision(6);
cout<<e<<" ";
out=fabs(e-sin(a))/fabs(sin(a));
cout<<fixed;
cout.precision(6);
cout<<out;
}

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

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

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

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

Input           1.047 1.048 100
Output            0.866426 0.000577

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

Student submission:
#include <simplecpp>
main_program {
double a;
int x;
int n;
double f(x) ==0;
double f(x) = sin(x);
cin>> a>> x>> n;
double f^n (a) = f ^n (x) while x=a;
f(x) = f(a) + (x-a) f^1 (a) + [(x-a)2/2! ] f^2 (a) + [(x-a)3/3! ] f^3 (a) + ... + (x-a)n/n! f^n (a) + ... ;
cout>> f(x);

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
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<iostream>
#include<math.h>

using namespace std;

int main()

{
int n=1;
int x,a,f,i;
float e;
char l;
cin>>a>>x>>n;
for(i=1;i<=n;i++)
{
int j=1;
int facval=1;
for(int it=0;it<n;it=it+1)
facval=facval*j;
j=j+1;
}
int facval;
if(n%4==0)l=sin(x);
else if(n%4==1)l=cos(x);
else if (n%4==2)l=-sin(x);
else if(n%4==3)l=-cos(x);
f=((x-a)^(n-1))*l/facval;
cout<<f<<" ";

e=abs(f-sin(a))/abs(sin(a));
cout<<fixed;
cout.precision(6);
cout<<e;
}

Grading criterion: Is relative absolute error calculated ?
Rating A: If correctly calculated
Rating B: If wrong
Rating C: 0
Rating D: 0
Assigned grade: A