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;
double root(double s)
{double x=1;
double y=(1+s)/2.0000000;
double eps=0.00001;
while(y-x>=eps||x-y>=eps)
{y=x;
x=(x+s/x)/2.0000000;
}
return x;
}
int main(){
double s;
cin>>s;
cout << fixed;
cout.precision(5);
cout<<root(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 sqrt(double s,double e)
{
	double x0=95,n,m;
	n=(x0+s/x0)/2;m=(n+s/n)/2;
	while(n-m>e)
	{
	n=m;m=(n+s/n)/2;	
	}
	return m;
}
int main()
{
	double a,s,e;
	cin>>s>>e;
	a=sqrt(s,e);
	cout<<fixed;
	cout.precision(5);
	cout<<a;
}

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 squareroot(double x){


double x1;
double x0=5;


double epsilon;

bool flagL((x1-x0)>epsilon);

if(flagL==true)
for(int i=1;i<=50;i++){

double x1;


x1=(x0+(x/x0))/2;
x0=x1;

}
return x0;
}




int main()
{
double x,x0,x1;
double ans;
double epsilon;
cin>>x;
cin>>epsilon;
ans=squareroot(x);

cout<<ans;
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 <stdlib.h>
using namespace std;
int main(){
int n;
cin>>n;
int curr1=1,curr2=1,prev1=0;
double sn=0, k,error;
const double psi=3.35989;
for(int i=2;i<=n;i++){
curr1=curr1+prev1;
k=1.0/curr2;
prev1=curr2;
curr2=curr1;
//k=1.0/curr2;
sn+=k;
}
if(n==2){sn=1;}
error=(abs(sn-psi))/psi;
cout<<fixed;
cout.precision(5);
cout<<sn<<endl;
cout<<error;
}

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

void squareRoot(double S, double epsilon )
{
double num1=1,num2=2;
while(num1-num2 >= epsilon || num2-num1 >= epsilon)
{num2=num1;
num1 = (num1 + S/num1)/2;
}
cout << fixed;
cout.precision(5);
cout<<num2;
}



int main(){

double epsilon, S;
cin>>S>>epsilon;
squareRoot(S,epsilon);
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 square_root(double S,double epsilon,double x0)
{
 double x1=(x0+S/x0)/2.0;
 if (fabs(x1-x0)<epsilon ) return x0;
 else
{x0= square_root(S,epsilon,x1);
}
 return x0;
}
int main(){
double S,epsilon;
cin>>S>>epsilon;
double x0=S;
double root;
root=square_root(S,epsilon,x0);
cout<<fixed;
cout.precision(5);
cout<<root;
}

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>
using namespace std;
# include <cmath> 
float root(double s,double e){float x;x=2;double y,z=2;y=0;
while(abs(z-y)>e){y=((x+(s/x))/2);z=x;x=y;}
return y;}
int main(){double  s;double e;cin>>s>>e;
cout<<root(s,e);}

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 sqrt(double s, double x, double eps){
    double prev=x+1;
    double curr=x;
    while (fabs(curr-prev)>eps){
        prev=curr;
        curr=(prev + (s/prev))/2;
    }
    return curr;
}

int main (){
    double s,eps;
    cin >> s >> eps;
    cout<< fixed;
    cout.precision(5);
    cout<< sqrt(s,s/3,eps);
}

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>
float bsq(float x0,float x,float s,float eps){
	x=abs(x0+(s/x0));
	x=x/2;
	if (abs(x-x0)<=eps){
		return x;
	}
	else{
		return bsq(x,x,s,eps);
	}
}
main_program{
	double s,x0,xn,eps;
	
	cin>>s;
	cin>>eps;
	x0=5;
	cout<<bsq(x0,xn,s,eps);
	
}

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 sqrt( double S, double eps)
  {
   double a; cin >> a;
   while ( fabs(a-sqrt(S)) > eps )
       {  a = (a + S/a)/2; }
   return a;
  }

int main()
{  double S; double eps= 0.0000001;
   cin >> S;
   cout << sqrt(S,eps);
}

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>

using namespace std;
double getroot(double S,double epsilon){
 double x0,x1,x2;
 x0=1.5;
 x1=0;
 x2=1;
while(abs(x2-x1)>epsilon){
  x2=x1;
  x1=(x0+(S/x0))/2;
  x0=x1;
  }
return x2;
}
int main(){
double S,epsilon;  
cout<<fixed;
cout.precision(5);
cin>>S;
cin>>epsilon;
cout<<getroot(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: 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()
{
     float squareroot(float s,int x0,int n);
      int i=1,n;
      
       for(int i=1;i<=n+1;i++){
          x(i) = (x0+s/x0)/2;
             x(n+1)-x(n)<=0.01;
             }
         return x(i);
         
         
    float s,x0,n;
    
    cin>>s>>x0>>n;
    cout<<float squareroot(s,x0,n); 
    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>
using namespace std;


double sqrt(double S, double epsilon)
{
double x = 1.0;
double x_1 = 2.0;
double temp;

while((x-x_1)>epsilon || (x_1-x)>epsilon)
{
temp = x_1;
x_1 = (x + (S/x))/2;
x = temp;


}


return x_1;
}




int main()
{

double a, b;
cin>>a>>b;
cout<<fixed;
cout.precision(5);
cout<<sqrt(a,b);
















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>
using namespace std;
double diff(double p,double q){
	if (p>q){return p-q;}
	else {return q-p;}
}
double nonrecsqrt(double x,double& s,double y){
	double x1 = (x+(s/x))/2;
	while (diff(x,(x+(s/x))/2)>y){
		x = x1;
		x1 = (x+(s/x))/2;
	}
	return x;
}
int main(){
	double s,eps;
	cin >> s>>eps;
	cout<<fixed;
	cout.precision(5);
	cout << nonrecsqrt(s,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: A