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

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

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
using namespace std;
double sqrt(double &S,double &e){
 double a=S/2;
double x1,x2;
        x1=(a+S/a)/2;
       x2=(x1+S/x1)/2;
       while  (x1-x2>e){
         
x1=(x2+S/x2)/2;
x2=(x1+S/x1)/2; }
   
 return x2;
}
int main(){
double S,e;
cin>>S>>e;
sqrt(S,e);
cout<<fixed;
cout.precision(5);
cout<<sqrt(S,e);
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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<simplecpp>

main_program{
  double s,eps,x0=1,x1=1,x2=2;
  cin>>s>>eps;
  while(fabs(x1-x2)>=eps){
   x1=(x0+(s/x0))/2;
   x2=x0;
   x0=x1;
   }
  cout<<fixed;
  cout.precision(5);
  cout<<x0;
  }

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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;
void Square_Root(double S, double epsilon)
{
double a=1;
double b;
double c=a;
while(abs(b-c)>=epsilon)
{
c=a;
b=(a+S/a)/2;
a=b;
}
cout<<fixed;
cout.precision(5);
cout<<b;

}

int main()
{
double x,epsilon;
cin>>x>>epsilon;
Square_Root(x,epsilon);
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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 fsqrt(double x, double epsilon)
{
	double x0 = x/2.0;
	double x1 = (x0+x/x0)/2.0;
	while(fabs(x0-x1)>epsilon)
	{
		x0 = x1;
		x1 = (x0+x/x0)/2.0;
	};
	return x1;
}
int main()
{
	double s;
	cin >> s;
	double eps;
	cin>> eps;
	cout<<fixed;
	cout.precision(5);
	cout<< fsqrt(s, eps);
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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 sqrt(int S,long double eps,long double xo)
           {
           
           long  double x1=(xo+S/xo)/2;
           while(fabs(xo-x1)>=eps){
           xo=x1;
           x1=(xo+S/xo)/2;
           }
           xo=x1;
           return xo;
           }






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

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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<simplecpp>
main_program{
double

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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 seq(double s, double x, int n){
	if (n==0) return x;
	else return (seq(s,x,n-1)+s/seq(s,x,n-1))/2;
}
int main(){
	double s;
	cin>>s;
	double x=1;
	double eps;
	cin>>eps;
	int n=0;
	while(fabs(seq(s,x,n)-seq(s,x,n+1))>=eps){
		n++;
	}
	cout<<fixed;
	cout.precision(5);
	cout<<seq(s,x,n);
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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 sequence(double x, double S, double epsilon){
	if(fabs((x+S/x)/2-x)<epsilon){
		return x;
	}
	return sequence((x+S/x)/2, S, epsilon);
}
int main(){
	double n, epsilon;
	cin >> n >> epsilon;
	cout << fixed;
	cout.precision(5);
	cout << sequence(1,n, epsilon) << endl;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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:
//Q1
#include<iostream>
#include<cmath>
using namespace std;

double square_root(double S, double epsilon, double x0)
{
	double x1 = (x0 + S/x0)/2.0;
	while(abs(x1-x0)>epsilon)
	{
		x0 = x1;
		x1 = (x1+S/x1)/2.0;
	}
	return x1;
}
int main()
{
	double S,epsilon,x0;
	cin>>S>>epsilon;
	x0 = S/2.0; //initial guess : chosen arbitrarily
	cout<<fixed;
	cout.precision(5);
	cout<<square_root(S,epsilon,x0);

}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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 acc(int n, int s, double x0){
    if (n==1) return x0;
    x0= acc(n-1,s,(x0+ (double)s/x0)/2);
}


void sqr(int s, double eps){

    
    int n=1;
    double ans;
    while (abs(acc(n+1,s,1)-acc(n,s,1))>eps){
        ans= acc(n+1,s,1);
        n++;
    }
    cout<<fixed;
    cout.precision(5);
    cout<<ans;
}
int main()
{
   int s;
   double eps;
   cin>>s>>eps;
   sqr(s,eps);
}

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

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

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include <iostream>
using namespace std;
double ans(double s,double e){
	double xi=s/2;
	double xf=(xi + s/xi)/2;
	while(abs(xf-xi)>e){
		xi=xf;
		 xf=(xi + s/xi)/2;
	}
	return xf;
}

int main(){
	double s,e;
	cin>>s>>e;
	
	cout<<fixed;
	cout.precision(5);
	cout<<ans(s,e);
	
	return 0;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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<simplecpp>



main_program{
float x0=1;
float s;
cin>>s;
float x1=(x0+s/x0)/2;
float xn=x1,xn1=x0;
float ep=0.01;

float diff=xn-xn1;
if (xn-xn1<0){diff=diff*(-1);}

if (diff<ep){
	cout<<xn;
}
else if (diff>ep){
	while(diff>ep){
		float temp=xn;
		xn=(xn+s/xn)/2;
		xn1=temp;
		diff=xn-xn1;
		if (xn-xn1<0){diff=diff*(-1);}
	}
	cout<<xn;
}
}

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

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

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>

using namespace std;

int main(){
	double s,x1,x,eps=0.01;
	cin>>s>>x;
	if(s>0){
	x1=( x+(s/ x)*0.5);
	
	cout<<x1;
	}
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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 squareroot(double S, double epsilon) {
float x=S;
float _x;
do {
_x = (x + S/x)/2;
float xx =(_x + S/_x)/2;
x = _x;
_x=xx;
}
while (fabs(_x -x)>epsilon);
return x;
}
int main() {
double a,b;
cin>>a>>b;
cout << squareroot(a,b);
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
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;
float sqrtfunct(float S,float epsilon);
int main()
{
float S,epsilon;
cin>>S>>epsilon;
float p=sqrtfunct(S,epsilon);
cout<<fixed;
cout.precision(5);
cout<<p;
}

float sqrtfunct(float S, float epsilon)
{
float xn,xn1=2;

do
{
xn=xn1;
xn1=(xn+float(S)/float(xn))/float(2);
}
while(abs(xn1-xn)>epsilon);
return xn1;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or no comments
Rating D: 0
Assigned grade: C