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<stdlib.h>
using namespace std;
double square_root(double S,double epsilon){
     double x0=10;
	double x1=(x0+S/x0)/2;
     do{
		 double temp=x0;
		 x0=x1;
		 x1=(x0+S/x0)/2;
	 } while(abs(x1-x0)>epsilon);
     return x0;
}
int main(){ 
    double S,epsilon;
    cin >> S >> epsilon;
	cout<<fixed;
	cout.precision(5);
    cout << square_root(S,epsilon);
    return 0;
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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 fabs(double x)
{
if(x>=0) {return x;}
else {return -x;}
}
double root(double S, double epsilon)
{
double x=1;
while(fabs(x-(x+S/x)/2)>epsilon)
{x=(x+S/x)/2;}
return x;
}
int main()
{
double S,epsilon;
cin>>S>>epsilon;
double y=root(S,epsilon);
cout<<fixed;
cout.precision(5);
cout<<y;
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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 squareroot(double x, double epsilon)
{
double x0=x;
double x1=(x0+x/x0)/2;
while (fabs(x0-x1)>epsilon)
{
x0=x1;
x1=(x0+x/x0)/2;
}
return x1;
}
int main ()
{
double S, epsilon;
cin >> S >> epsilon;
cout << fixed;
cout.precision(5);
cout << squareroot(S, epsilon);
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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;
long double squareroot(long double S,long double eps,long double x){
	long double y=(x+S/x)/2;
	while(fabs(y-x)>eps){
		x=y;
		y=(x+S/x)/2;
		
		}
	return y;
	}
int main(){
long double S;cin>>S;
long double eps;cin>>eps;

cout<<squareroot(S,eps,S);
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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 mysqrt(double S, double eps)
{
	double x = 1.0;
	double temp = (x + S/x)/2.0;
	while(fabs(temp - x) >= eps)
	{
		x = temp;
		temp = (x + S/x)/2.0;
	}
	return x;
}

int main(){
	double S,eps;
	cin>> S >> eps;
	double ans = mysqrt(S,eps);
	cout<< fixed; cout.precision(5);
	cout<< ans;
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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 x, double eps){
double x0=5;
double a,b;
a = x0;
b = (a + (x/a))/2;
while (abs(a -b) >= eps) {
a = b;
b = (a + (x/a))/2;
}
return b;
}
int main(){
double S,eps;
cin >> S >> eps;
cout << fixed;
cout.precision(5);
cout << sqrt(S,eps);
return 0;
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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 f(double x, double s){
return (x+(s/x))/2;
}
double squaroot(double x, double s, double eps){
double x1=f(x,s);
while (1){
x=x1;
x1=f(x1,s);
if (x1>x && x1-x<eps) break;
if (x>=x1 && x-x1<eps) break;
}
return x1;
}
int main(){
double s;
cin>>s;
double eps=0.0001;
double x=s/2;
cout<<squaroot(x,s,eps);
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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 bsqrt(int s, double eps){

double a,b;
a=1;
b=(a+(s/a))/2;
double temp;
while (fabs(a-b)>eps){
temp=b;
b=(b+(s/b))/2;
a=temp;
}

return a;
}

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

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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 (int n, double s)
{
 double x0 = 1;
 if (n == 1) return (x0 + s/x0)/2;
 else
 {
  double k = (f (n-1, s) + s/(f (n-1, s)))/2;
  return k;
 }
}
double g (double s)
{
 int n;
 for (n = 1; n>0; n++)
 {
  while (fabs(f(n+1, s) - f(n, s)) < 0.00001) return f(n+1, s);
 }
}
int main()
{
 double s;
 cin>>s;
 cout<<fixed;
 cout.precision(5);
 cout<<g(s);
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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(int n,int k) {
if(n==1) return 2.00;
else {
float f=(rec(n-1,k)+(k/rec(n-1,k)))/2;
return f;
}}
int main () {
int k;
float e;
cin>>k>>e;
for(int i=1;i>0;i++){
if((rec(i+1,k)-rec(i,k))<e){
cout<<rec(i+1,k) ;break;}
 continue;
}
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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 root1(double s,double x,double e){
		double x1;
		x1=(x+s/x)/2;
		if (x-x1>e||x1-x>e){
		x1=root1(s,x1,e);
		return x1; 
}
		return x;


} 
		int main(){
		double s,x,e,y;
		cin>>s>>x>>e;
		y=root1(s,x,e);
		cout<<y;

}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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;
void sqrtfunc(double &s){
int n,i=1;double t;
double a;
t=sqrt(s);
double epsilon = 0.0001;
cin>>a;
while(abs(a-t) > 0.01){
a=(a+(s/a))/2.0;
}
cout<<a;
}
int main(){
double s;
cin>>s;
if(s>0){
cout<<fixed;
cout.precision(5);
sqrtfunc(s);
}
else cout<<" wrong";
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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;
int main()
{
double S,eps;
cin>>S;
cin>>eps;
double x=S/2,y;
y=(x+S/x)/2;
while(abs(x-y)>eps)
{
  x=y;
  y=(x+S/x)/2;
}
cout<<fixed;
cout.precision(5);
cout<<y;
}

Grading criterion: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
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;
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: Whether babylonian method is implemented in a function
Rating A: Separate function is used and function signature is correct
Rating B: Separate function is used but function signature is not correct
Rating C: totally wrong
Rating D: 0
Assigned grade: C