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>
#include<cmath>
using namespace std;
int main(){
double S, epsilon;
cin>>S>>epsilon;
double x=S/2;
while(fabs(((S/x)-x)/2)>epsilon){
x=(x+S/x)/2;}
cout<<fixed;
cout.precision(5);
cout<<x;
}

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 func( double s,double eps)
{
double x1=0.001,x2=(x1+s/x1)/2;

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

return x1;
}

int main()
{
double s,eps;
cin>>s>>eps;

cout<<fixed;
cout.precision(5);
cout<<func(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>
using namespace std;
double sqrt(double S, double epsilon)
{
	double root=0.0000001;
	double old=S;
	while(abs(old-root)>epsilon)
	{
		old=root;
		root=((root+(S/root))/2);
	}
	return root;
}
int main()
{
	double S, epsilon;
	cin>>S>>epsilon;
	cout << fixed;
	cout.precision(5); 
	cout<<sqrt(S,epsilon);
	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: 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 x,double s){
	return (x+(s/x))/2;
}

double root(double s, double e){
	double x1 = s/2;
	double x2 = f(x1, s);
	while(abs(x2-x1) > e){
		x1 = x2;
		x2 = f(x2,s);
	}
	return x2; 
}

int main(){
	double s, e; cin >> s >> e;
	cout << fixed;
	cout.precision(5);
	cout << root(s, e);
	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: 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>
using namespace std;
float f(float &n,float &m)
{float o=(n+m/n)/2;
return o;
}
int main(){
float x1,x0,s,a,b;
cin>>s>>x0;
b=f(x0,s);
if(abs(b-x0)>0.0001){
{a=x0;
x1=f(x0,s);
b=x1;
x0=b;
}cout<<b;
}else if(b==x0) cout<<b;
}

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;
double f(double s){
double x=0.00001;
double temp;
double eps=0.001;
do{
temp = x;
x = (x+s/x)/2;
}while(abs(temp-x)>eps);
cout<<fixed;
cout.precision(5);
return x;
}
int main(){
double s;
cin>>s;
cout<<f(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: 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;
int main()
{ unsigned int S;
  double eps;double x1=1.0,x2,x3;
  cin>>S>>eps;
  x2=(x1+S/x1)/2;x3=(x2+S/x2)/2;
  while((x3-x2>eps)||(x3-x2<-eps))
  {x2=(x3+S/x3)/2;x3=(x2+S/x2)/2;}
  cout<<fixed;
  cout.precision(5);
  cout<<x3;
}

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;

int main()
{
	double S,eps;
	cin >> S >> eps;
	double x0=S/2,step=1;
	while(step>eps || step<-eps)
	{
		step=(x0+S/x0)/2-x0;
		x0+=step;
	}
	cout << fixed;
	cout.precision(5);
	cout << 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: 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 x, double s)
{
	double t = 0.5*(x + s/x);
	return t;
}
int main ()
{
	double x = 1.0,s,e;
	cin >> s >> e;
	double t = f(x,s);
	while(fabs(t-x) > e)
	{
		x = t;
		t = f(x,s);
	}

	cout << x;
}

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>
using namespace std;
double bsqrt(double S, double e, double x)
{
double a=(x+S/x)/2;
if((x-e)*(x-e)<=S && (x+e)*(x+e)>=S)return x;
else return bsqrt(S,e,a);
}
int main()
{
double S,e;
cin>>S>>e;
cout<<fixed;cout.precision(5);
cout<<bsqrt(S,e,1);
}

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>
#include <cmath>
using namespace std;

double funct(double x,double S)
{
double k= (x + S/x)/2.0;
return k;
}


int main()
{
double x;
cin>> x;

double new_root = x;double old =(x+1)/2.0;
while(fabs(new_root - old)>0.000001)
{
double d = funct(old,x);
old = new_root;
new_root= d;
}
cout<< fixed;
cout.precision(5);
cout << new_root;
}

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(double s,double eps)
{	double a=1,b=(1+s/1.0)/2.00;
	while(fabs(b-a)>eps)
{	a=b;
	b=(a+s/a)/2.00;
}
return a;
}
int main()
{
double s,eps;
cin>> s;
cin>>eps;
cout<<fixed;
cout.precision(5);
cout<<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>
using namespace std;
double sqrt(double a,double b){

int x0,xr,xl,xp;
cin>>x0;
xl=(x0+a/x0)/2;
if ((x0*x0)!=a){
while(xr-xl>b){

xr=(xl+a/xl)/2;
if (xr*xr==a){return xr;}
}
}
return xr;
}
int main(){
double S,epsilon;
cin>>S>>epsilon;
cout<<sqrt(S,epsilon);



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: 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;


float root(float s, float x0,double epsilon){
	if(s==1) return 1;

	float x1 = (x0 + s/x0)/2;
	if(fabs(x0-x1) < epsilon) return x1;
	else return root(s, x1, epsilon);


}

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

	double epsilon;
	cin>>epsilon;

	float x0 = s/2;

	cout<<fixed;
	cout.precision(5);
	cout<<root(s, x0, epsilon);

}

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 f(double S,double &x,double eps){
   double y;
   do{
       y=x;
       x=(x+S/x)/2;}
   while(abs(y-x)>eps);
   return x;}

int main(){
   double S,eps,x=5.000000;
   cin>>S>>eps;
  cout<<fixed;
  cout.precision(5);
   cout<<f(S,x,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: B