CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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



void sqrt(double s,double eps){
	cout<<fixed;
	cout.precision(5);

	double x1=s-1,x2=s;

	while(abs(x2-x1)>eps){
		x2=(x1+s/x1)/2;
		double temp=x1;
		x1=x2;
		x2=temp;
		
		

	}
	cout<<x1;
}

int main(){

double s,eps;
cin>>s>>eps;
sqrt(s,eps);

}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok variable names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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

float square_root(int S, float eps, float x)
{

	float x1=(x + (S/x))/2;
	if((fabs(x1-x))>eps) return square_root(S,eps,x1);
	else return x1;

}

int main()
{
	int S;
	float eps;
	float x0=10.0; //a random positive number guess
	cin >> S >> eps;
	if((S>0) && (eps<=0.01))
	{
		cout << fixed;
		cout.precision(5);
		cout << square_root(S,eps,x0);
	}
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok variable names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
using namespace std;
float rec_sqrt(float x,int n)
{
		if (n == 1) return 1;

		if (n == 0) return x;
		float temp = rec_sqrt(x,n);
		if ((n+1) == 0) return temp*temp;
		else return temp*temp*n;
		}
		int main()
		{
		float x,S; int n;
		cout<<"enter x and n:"; cin>>x>>n;
		S=rec_sqrt(x,n);
		cout<<"S= " <<S;
		}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok variable names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include <iostream>

using namespace std ;
const double E = 0.01 ;
void sqrt(int s, int n, int x0);
	 while (((n+1)-n) <= E); {
		 {
		 n=((x0 + s) / x0) / 2 ;
		 n = n + 1;
		 precision(5)
     return;
			 }
	 }
int main() {
	
	 cin >> s >> x0 ;
	 sqrt(s, x0) ;
	 cout >> n ;
	 return 0 ;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok variable names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
using namespace std;
float f(int S,float epsilon){
int n=100;
float p;
float A[n+2];
A[0]=1;
for (int i=1;i<n+2;i++){
cout << fixed; 
cout.precision(5);
float t=(float)S/(float)A[i-1];
cout << fixed; 
cout.precision(5);
float u=(float)A[i-1]+(float)t;
cout << fixed; 
cout.precision(5);
A[i]=(float)u/(float)2;
if ((A[i-1]-A[i])<=epsilon && (A[i-1]-A[i])>=-epsilon) {p=A[i-1];break;}
}
cout << fixed; 
cout.precision(5);
return p;
}
int main(){
int S;float epsilon;
cin>>S>>epsilon;
float o=f(S,epsilon);
cout << fixed;
cout.precision(5); 
cout<<o;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok variable names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<simplecpp>
double sqt(double a,double epsilon);

main_program{
	double s;
	double eps,c;
	cin>>s>>eps;
	c=sqt(s,eps);	
	cout<<fixed;
	cout.precision(5);
	cout<<c;
	
}

double sqt(double a,double epsilon)
{
	double x[1000];
	int i;
	x[0]=100;
	for(i=1;i<1000;i++)
	{
	x[i]=(x[i-1]+ (a/x[i-1]))/2;
	if(fabs(x[i]-x[i-1])<epsilon)
	break;
	}
	return x[i];
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok variable names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
#include<cmath>
using namespace std;
double root(double s,double eps){
double x0=1,x1=s;
while(true){
x1=(x0+s/x0)/2;
if(fabs(x0-x1)<=eps) {break;}
x0=x1;
}
return x1;}
int main(){
double s,eps;
cin>>s>>eps;
double k;
k=root(s,eps);
cout<<fixed;
cout.precision(5);
cout<<k;}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok variable names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
#include<cmath>
using namespace std;
double sqrt(int s,double e){
	double x0=1;
	double x1=x0+4;
	while(fabs(x1-x0)>=e){
		x0 = x1;
		x1= (x0+ s/x0)/2;
		 }
return x1;}





int main(){
int s;
cin>>s;

double  epsilon;
cin>>epsilon;
double p;
p= sqrt(s,epsilon);
cout<<fixed;
cout.precision(5); 
cout<<p;

}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok variable names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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

double fun(int s,double eps){
double x,nx;
cin>>x;
//cout<<x<<endl;
int temp;
nx=(x+(s/x))/2;
while(fabs(nx-x)>eps){

nx=(x+(s/x))/2;
temp=x;
x=nx;
}
return x;
}

int main(){
int n;
cin>>n;
double eps;
cin>>eps;
double root=fun(n,eps);

cout<<fixed;
cout.precision(5);
cout<<root;

return 0;}

Grading criterion: Use of function beyond what was instructed or any other nice quality.
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<simplecpp>
main_program{
long double s,pre,e,ans,a;
cin>>s>>e;
pre=1;
do
{
ans=(pre+s/pre)/2;
if(pre-ans>0) a=pre-ans;
else if (ans-pre>0) a=ans-pre;
else if (ans==pre) a=0;
if (a>e) pre=ans;
} while (a>e);
cout<<fixed;
cout.precision(5);
cout<<pre;
}

Grading criterion: Use of function beyond what was instructed or any other nice quality.
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include <iostream>
#include <cmath>
using namespace std;
long double sq(int s)
{
long double x=2;
long double x1=0;
while(fabs(x1-x)>0.001)
{
x1=x;
x=(x+s/x)/2;

}
 cout << fixed;
cout.precision(5);
return x1;
}
int main()
{
int s;
cin>>s;
cout<<sq(s);
}

Grading criterion: Use of function beyond what was instructed or any other nice quality.
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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

using namespace std;

double f(double g, double n){
	return (g+(n/g))*(0.5);}


double square_root(double g,double n,double epsilon){
	double x1 =g;
	double x2 =f(g,n);
	while(fabs(x2-x1)>epsilon){
		x1=x2;
		x2=f(x1,n);}
	return x1;}

int main(){
	double n,epsilon;
	cin>> n>>epsilon;
	cout<<fixed;
	cout.precision(5);
	cout<<square_root(10,n,epsilon);
	}

Grading criterion: Use of function beyond what was instructed or any other nice quality.
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
#include<cmath>
using namespace std;
double f(double S, double eps)
{
  double x=4;
  while(fabs((((S/x)+x)/2)-x)>eps)
  {
    x = (x+(S/x))/2;
  }
  return x;
}

int main()
{
double S, eps;
cin >> S >> eps;
cout << fixed;
cout.precision(5);
cout << f(S, eps);
return 0;
}

Grading criterion: Use of function beyond what was instructed or any other nice quality.
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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

double rt(double S,double epsilon)
{
	
	double x=S;
	while ((fabs(x-(x+(S/x))/2))>epsilon)
	{
		x=((x+(S/x))/2);
	}
	return x;

}

int main()
{
	double S,epsilon;
	cin>>S>>epsilon;
	cout<<fixed;
	cout.precision(5);
	cout<<rt(S,epsilon);
}

Grading criterion: Use of function beyond what was instructed or any other nice quality.
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: A