CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include <iostream>
using namespace std;
 
int x,n;
char string_compare[];
ci.getline(x,n)

cin>>x>>n;
 int main() {
 
 int string_compare (char *first,char *second){
 int i=0;
 while(true){
 if (first[i]==0 && second [i]==0) return 0;
 if (first[i]==0 return +1;
 if (second[i]==0 return -1;
 if (first[i] < second[i]) return +1;
 if (first[i] > second[i]) return-1;
 i++;
 }return 0;}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include <cstring>
#include <iostream>
using namespace std;
int compc=0,swapc=0;
void swap(char *first, char *second)
{	
	char temp[11];
	int i=0;
	for(i=0;first[i]!='\0';i++)
	{
		temp[i] = first[i];
	}
	temp[i] = first[i];
	
	i=0;
	for(i=0;second[i]!= '\0';i++)
        {
                first[i] = second[i];
        }
        first[i] = second[i];
	
	i=0;
	for(i=0;temp[i]!= '\0';i++)
        {
                second[i] = temp[i];
        }
        second[i] = temp[i];
	

}
int compare(char *first, char * second)
{
	int i = 0;
	while (true)
	{
		if (first[i] == 0 && second[i] == 0) return 0;
		if (first[i] == 0) return -1;
		if (second[i] == 0) return +1;
		if (first[i] < second[i]) return -1;
		if (first[i] > second[i]) return +1;
		i++;
	}
	return 0;
}
void string_sort(char A[][11], int n)
{
	int i,j,compc=0,swapc=0;
	char temp[11];
	for (i = 0; i < n - 1; i++)
    	{
        
        	for (j = 0; j < n - i - 1; j++)
        	{
            		if (compare(A[j],A[j+1])<0)
                	{
				swap(A[j],A[j+1]);
				swapc++;
        		}
			compc++;
    		}
	}
	 j=0;
        for(int i=0;i<n;i++)
        {       
                j=0;
                while(A[i][j]!='\0')
                {
                        cout<<A[i][j]; j++;
                }
                cout<<"\n";
        }
	cout<<compc<<" "<<swapc;

}




int main()
{
	int n;
	cin>>n;
	char arr[n][11];
	for(int i=0;i<n;i++)
	{
		cin.getline(arr[i],11);
	}
	string_sort(arr,n);
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;

int string_compare(char A[][100],int n1,int n2){
	for(int i=0;A[n1][i]!=0&&A[n2][i]!=0;i++){
		if(A[n1][i]<A[n2][i]){return 1;}
		if(A[n1][i]>A[n2][i]){return -1;}
	}
	return 0;	
}
void swap(char&a,char&b){
char temp;
temp=a;
a=b;
b=temp;
}

void string_sort(char a[][100],int n1){
	for(int i=0;a[n1][i]!=0;i++){
		for(int j=0;a[n1][j]!=0;j++){
			if(a[n1][j]<a[n1][j+1]){swap(a[n1][j],a[n1][j+1]);}	
		}
	}
}
int main(){
int n,n1,n2,n3;
cin>>n;
char A[n][100];
for(int i=0;i<n;i++){
	cin>>A[i];
}
cin>>n1>>n2;
cout<<string_compare(A,n1,n2);
string_sort(A,n3);
for(int i=0;A[n3][i]!=0;i++){
	cout<<A[n3][i];
}
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int i,n;
float a,r,sum,err;
sum=0;
cin>>n;
for(i=0;i<n;i++)
{
r=pow(-0.5,i);
sum=sum+r;
}
a=2/3;
err=(sum-a)/a;
cout<<fixed;
cout.precision(6);
cout<<sum<<" ";
cout<<err;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include <iostream>
#include <cstring>
 using namespace std;
 int swaptimes;
int  len(char *s1){
    int i;
    for (i=0;i<11;i++){
        if(s1[i]=='\0'){break;}
    }
    return i;
}
bool same(char *s1,char *s2){
    int yes=0;
    for (int i=0;i<(len(s2));i++){
        if(s1[i]==s2[i]){yes++;}
    }
    if ( yes == len (s1)){return 1;}
    else return 0;
}
int string_compare(char *s1,char *s2){
    swaptimes++;
    for(int i=0;i<11;i++){
        if ((len(s1)==len(s2))&&same(s1,s2)){return 0;}
        else if ((s1[i]-s2[i])==0){continue;}
        else if ((s1[i]-s2[i])>0){return 1;}
        else if  ((s1[i]-s2[i])<0){return -1;}
    }
}
void string_sort(char c[][11],int n,int &times){
    for(int i=0;i<n-1;i++){
        for(int j=0;j<n-i-1;j++){
            if(string_compare(c[j],c[j+1])==-1){
                times++;
                char s[11];
                strcpy(s,c[j]);
                strcpy(c[j],c[j+1]);
                strcpy(c[j+1],s);}
                }
    }
}
int main(){
    int n;
    cin >> n;
    char c[n][11];
    for(int i=0;i<n;i++){
        cin >> c[i];
    }
    int times=0;
    string_sort(c,n,times);
    for(int i=0;i<n;i++){
        cout << c[i];
        if(i!=n-1){cout << " ";}
    }
    cout<< endl;
    cout << swaptimes << " ";
    cout << times;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
int string_compare(char *s1,char *s2);
void string_sort(char **str,int n){
int i,j;
for(i=0;i<n-1;i++){
 for(j=0;j<n-i-1;j++){
 if(string_compare(str[i],str[i+1])>0){char *s;
       s=str[i];str[i]=str[i+1];str[i+1]=s;
}
   }
  }
}
int string_compare(char *s1,char *s2){
int i=0;
while(true){
 if(s1[i]==0&&s2[i]==0)return 0;
 if(s1[i]==0)return 1;
 if(s2[i]==0)return -1;
 if(s1[i]<s2[i])return 1;
 if(s1[i]>s2[i])return -1;
 i++;
}
return 0;
}

int main(){
int n;
cin>>n;
int strings[n];
struct inpstr{char str[12];};
inpstr set[n];
for(int i=0;i<n;i++){cin>>set[i].str;}
int A[];
/*for(int i=0;i<n;i++){
 for(int j=0;j<n;j++){A[i]=string_compare(set[i].str,set[j].str);}
*/
string_sort(set[n],n);}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
#define MAX 12
using namespace std;
int string_compare(char *first,char *second){
   int i=0;
   while(1){
      if(first[i]==0 && second[i]==0)return 0;
      if(first[i]==0)return 1;
      if(second[i]==0)return -1;
      if(first[i]<second[i])return 1;
      if(first[i]>second[i])return -1;
      i++;
      return 0;
    }
}
void string_sort(int n,char array[][MAX]){
int i,j,C=0,S=0;
for(i=0;i<n-1;i++){
   for(j=0;j<n-i-1;j++){C++;
  int x= string_compare(array[j],array[j+1]);
  if(x==1){swap(array[j],array[j+1]);S++;}
  else continue;
   }
}
cout<<C<<S;}

int main(){
int n;
cin>>n;
char array[n][MAX];
for(int i=0;i<n;i++){
  cin.getline(array[i],12);}
string_sort(n,array);
for(int i=0;i<n;i++){cout<<array[i]<<endl;}
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include <iostream>
using namespace std;
#define MAX 12
void string_copy (char *dest, const char* source) {
	int i;
	for(i=0;source[i]!=0;i++){
		dest[i] = source[i];
	}
	dest[i] = source[i];
	}
int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
if (first[i] == 0) return -1;
if (second[i] == 0) return +1;
if (first[i] < second[i]) return -1;
if (first[i] > second[i]) return +1;
i++;
}
return 0;
}
void string_sort (char A[][MAX],int n,int &calls,int &swaps)
{
int i=0;int j=0;
while (j<n-1)
{
while (i<n-1-j)
{
int a=string_compare(A[i],A[i+1]);calls++;
if (a==1) {char* temp;string_copy(temp,A[i]);string_copy(A[i],A[i+1]);string_copy(A[i+1],temp);swaps++;}
i++;
}
i=0;
j++;
}
}
int main()
{
int n;
cin >> n;
char A[15][12];
int count=0;
int c,s;
while (count<n) {char s[MAX];cin.getline(s,MAX);string_copy(A[count],s);count++;}
string_sort(A,n,c,s);
int k=0;
while (k<n)
{
cout << A[k];
}
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
void input(int n){
	while (int i=0){
		
	}
	}
void compare(char first[],char second[]){
	int i=0;
	if(first[i]>second[i])return 1;
	if(first[i]<second[i]) return -1;
	if(first[i]==second[i])return 0;
}
	
}

void sortAndOutput(char arr[],int n){
	
	

int main(){
int n=12;
char arr[n];
input(arr,n);
sortAndOutput(arr,n);




}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include <iostream>
using namespace std;
void rev_string(char *string,int l){
int counter =0;
while(counter<l){
for(int i=0;i<l-counter;i++){
if (string[i]>string[i+1]){
char temp=string[i];
string[i]=string[i+1];
string[i+1]=temp;
}

}
counter++;

}
for(int i=l;i>=0;i--){
cout <<string[i];

}
cout << endl;}

int string_compare(char *string1, char *string2){
int i=0;
while(true){
if(string1[i]==0 && string2[i]==0) return 0;
if(string1[i]==0) return 1;
if(string2[i]==0) return -1;
if(string1[i]<string2[i]) return 1;
if(string1[i]>string2[i]) return -1;
i++;
}
return 0;
}



int main(){
int n;
cin >> n;
char string1[n];
char string2[n];
cin >> string1;
cin >> string2;
int l1=0,l2=0;
while (string1[l1]!=0){
l1++;}
while (string2[l2]!=0){
l2++;}

cout << string_compare(string1, string2)<<endl;
rev_string(string1,l1);
rev_string(string2,l2);


}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;

void swap(char &a,char &b)
{
char temp=a;
a=b;
b=temp;
}

void string_swap(char *A,char *B)
{
int la=0,lb=0,n1=0,n2=0,c1,c2;
while(A[la]!=0) la++;
while(B[lb]!=0) lb++;
while(n1<la && n2<lb)
{
swap(A[n1],B[n2]);
n1++;
n2++;
}
c1=n1; c2=n2;

while(n1<la)
{
B[n2]=A[n1];
n1++; n2++;
if(n1==la)
{
A[c1]=0;
B[n2]=0;
}
}

while(n2<lb)
{
A[n1]=B[n2];
n1++; n2++;
if(n2==lb)
{
B[c2]=0;
A[n1]=0;
}
}

}

int string_compare(char *first,char *second)
{
int i=0;
while(true)
{
if(first[i]==0 && second[i]==0) return 0;
if(first[i]==0) return 1;
if(second[i]==0) return-1;
if(first[i]<second[i]) return 1;
if(second[i]<first[i]) return -1;
i++;
}
return 0;
}

void string_sort(char A[][12],int n,int &c,int &d)
{
int s;
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1-i;j++)
{
s=string_compare(A[j],A[j+1]); c++;
if(s==1)
{
string_swap(A[j],A[j+1]);
d++;
}
}
}
}

int main()
{
int j,n,c=0,d=0;
cin>>n;

char A[n][12]; 

for(int i=0;i<n;i++)
{
cin>>A[i];
}

for(int i=0;i<n;i++)
{
j=0;
while(97<=A[i][j]<=122) j++;
A[i][j]=0;
}

for(int i=0;i<n;i++)
{
for(int j=0;j<11;j++)
{
cout<<A[i][j];
}
cout<<"\n";
}

string_sort(A,n,c,d);


for(int i=0;i<n;i++)
{
for(int j=0;j<11;j++)
{
cout<<A[i][j];
}
cout<<"\n";
}

cout<<c<<"\n"<<d;

}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Variable Names
Rating D: 0
Assigned grade: B