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(){
	int s;
	cin>>s;
	float y;
	cout<<fixed;
	cout.precision(5);
	float x;
	cin>>x;
	y = sqrt(s)-10*x;
	cout<< y;
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: D
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 absol(double x){
       if(x>0){return x;}
    return -x;
}

int main(){

   double xpre=3,xnow=4;
   float x,eps;
      cin>>x>>eps;
    while(absol(xnow-xpre)>eps){
       xpre=xnow;
      xnow=(xnow+(x/xnow))/2;
}
      cout<<fixed;
      cout.precision(5);
     cout<<xnow;
return 0;
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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+(double (s)/x))/2;
}
double sqroot(double s,double epsilon){
double x0=1,x1=0,x2=0;
x1=f(x0,s);
while (fabs(x2-x1)>epsilon){
x1=f(x0,s);
x2=f(x1,s);
x0=x2;
}
return x1;
}
int main(){
double s,epsilon;
cin>>s>>epsilon;

cout<<sqroot(s,epsilon);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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 getSqrt(double S, double eps)
{
	double x1 = 100;
	double x2 = 0;
	
	while (fabs(x1 - x2) >= eps)
	{
		x2 = (x1 + S / x1) / 2.0;
		x1 += x2;
		x2 = x1 - x2;
		x1 -= x2;
	}
	return x2;
}

int main()
{
	double S, eps;
	cin >> S;
	cin >> eps;
	
	cout << getSqrt(S, eps);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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 rec_sqrt(double S,double x0,double epsilon){
if(x0*x0==S)return x0;
double x1=(x0+S/x0)/2;
if(abs(x0-x1)<epsilon)return x1;
if(abs(x0-x1)>epsilon)return rec_sqrt(S,x1,epsilon);
}
int main(){
double S,x0,epsilon;
cin>>S>>epsilon;
x0=S/2;
cout<<fixed;
cout.precision(5);
cout<<rec_sqrt(S,x0,epsilon);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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 <simplecpp>

float f(float s) {
  float p,r,t,esp;
  p=s+1;
  r=s;
  esp=0.001;
  while ((p-r)>esp){
     t=(p+s/p)/2;
     p=r;
     r=t;
     }
 return r;}

main_program{
 float s;
 cin>>s; 
 cout<<fixed;
 cout.precision(5);
 cout<<f(s);
 }

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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 fun(float x0, int s, float eps){

	float x1 = (x0 + (s/x0))/2;
//	cout << x1;
	if (abs(x1 - x0) > eps){
		return fun(x1, s, eps);
	}
	return x1;
}


int main(){

	int n;
	float eps;
	cin >> n >> eps;
	cout << fun(2.0, n, eps);

	return 0;
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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 squareRoot(double S,double x)
{
	double eps=0.0000000001,x1,x2;

	x1=x;
	x2=(x+(S/x))*0.5;

	while(fabs(x2-x1)>eps)
	{
		x1=x2;
		x2=(x1+(S/x1))*0.5;
	}

	return x2;


}
int main()
{
	double S,r,g=2;
	cin>>S;
	r=squareRoot(S,g);
	cout<<fixed;
	cout.precision(5);
	cout<<r;

return 0;
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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;

void squareroot(double S,double eps){
double x1=1,x2=2;

while(x1-x2>=eps || x2-x1>=eps)
{x2=x1;
x1=(x1+S/x1)/2;}


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

cout<<x2;}

int main(){

double eps,S;
cin>>S>>eps;
squareroot(S,eps);
return 0;

}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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 mysqrt(double s, double eps){double xnow;
double xprev=2;double del=10;
while (del>eps){
xnow=(xprev+s/xprev)/2;
del=fabs(xnow-xprev);
xprev=xnow;
}
return xnow;
}
int main(){
double s,eps;
cin>>s>>eps;
cout<<fixed;
cout.precision(5);
cout<<mysqrt(s,eps);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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;
void root(float s,float e,float x0,float x1)
{
if(fabs(x0-x1)>=e)
{
	float x1=x0;
	x0=(x0+(s/x0))/2.0;
	root(s,e,x0,x1);
}
else
{
	cout.fixed;
	cout.precision(5);
	cout<<x0;
}
}
int main()
{
float s,e;
cin>>s>>e;
float x0 = 1.0,x1=0;
root(s,e,x0,x1);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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 x,double eps){
	double x0=x;
	double x1=(x0+x/x0);
	while(fabs(x0-x1)>eps){
		x0=x1;
	    x1=(x0+x/x0)/2;
	}
	return x1;
}
int main(){
	cout<<fixed;
	cout.precision(5);
	double x,t;
	cin>>x;
	t=f(x,0.01);
	cout<<t;
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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 S,double x0){
double x1=(x0+S/x0)*0.5;
double *p=&x0;
double *q=&x1;
while(x1>x0){
*p=x1;
*q=(x1+S/x1)*0.5;
if(*p>*q)break;
}

while(x0-x1>0.01){
*p=x1;
*q=(x1+S/x1)*0.5;

}return x1;
}
int main(){
double S,x0;
cin>>S>>x0;
if(x0<pow(S,0.5) x0=pow(S,0.5)+1;
cout<<fixed;
cout.precision(5);
cout<<f(S,x0);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
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 baby_sqrt(double x, double epsilon) {
	double xn_1, xn;
	xn = 10;
	xn_1 = (xn + x/xn)/2;
	double temp;
	while (fabs(xn_1-xn)>epsilon){
		 temp = xn_1;
		 xn_1 = (temp + x/temp)/2;
		 xn = temp;
	}
	return xn_1;

}

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

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: A