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>
#define MAX 13
using namespace std;
void swap( char *first,char *second)
{
 int temp=*first;
*first=*second;
*second=temp;
}
int string_cmp(char first[][MAX],char second[][MAX], int x,int b)
{
int i=0;
           while (true){
                       if (first[x][i] == 0 && second[x+1][i] == 0) return 0;
                       if (first[x][i] == 0) return -1;
                       if (second[x+1][i] == 0) return +1;
                       if (first[x][i] < second[x+1][i]) return -1;
                       if (first[x][i] > second[x+1][i]) return +1;
                       i++;
                       b++;
                       }
                       return 0;
}
void bubble_sort(char string[][MAX], int n,int a,int b)
{
    for (int i = 0; i < n - 1; i++)
    {
        
        for (int j = 0; j < n - i - 1; j++)
        {
            if (string_cmp(string,string,j,b)=-1)
                {swap(&string[j], &string[j + 1]);
                a++;
        }
    }
}
}
int main(){
          int n,a=0,b=0;
          cin>>n;
          char string[n][MAX];
          for (int i=0;i<n;i++){
                               cin.getline(string[i],12);
                               }
         bubble_sort(string,n,a,b);
         for (int i=0;i<n;i++){
                              int x=0;
                              while(string[i][x]!=0)x++;
                              for(j=0;j<=x;j++){cout<<string[i][j];}
                              cout<<endl; 
                              }
          
          cout<<b<<" "<<a;
}

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 main(){
int n;
cin>>n;
 char a[n][12];
 
 for(int i=0;i<n;i++){
 
  cin>>a[i];
  cout<<a[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>
using namespace std;

char string_compare(char* a,char* b)
{
for(int i=0;i<n;i++)
{
if(a[i]<b[i])
{return 1;}
else if(a[i]>b[i])
{return 2;}
else {return 0;}
}
}

int main()
{
int n;
cin>>n;

char**p=new char*[n];
for(int i=0;i<n;i++)
{
p[i]=new char[n];
}

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

for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<p[i][j];
} cout<<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<cstring>
#include<iostream>
using namespace std;
void int string_length (char *x){
int L = 0;
while (x[L] != ‘\0’) L++;
return L;
}
int main(){
char sq[1][11];
int count=0;
cout << "Enter at most 1 line with at most 11 characters :\n";
while (cin.getline(name[count++], 12)); 
for (int i=0; i<count; i++)
cout << "\t" << i << ". [" << sq[i] << "]" << endl;
}
int cin.getline(x,11);
char stringx[11]=" ";
char *x= stringx;
int string_length(stringx);
cout<<"L"<<" ";
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_reverse(char* s, char* rev_s){
int n = string_length(char *x);
for(int i=0;i<n;i++) rev_s[n-1-i] = s[i]; 
rev_s[n] = 0;
}
string_reverse();

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 *first, char *second,int &nc){
	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 copy (char *s, char *t){
while (*s++ = *t++);
}

void swap(char *a, char *b,int &ms){
	char temp[12];
	copy(temp,a);
	copy(a,b);
	copy(b,temp);
}


void bubble_sort(char A[][12], int n, int &ms, int &nc){
    int i, j;
    for (i = 0; i < n - 1; i++)
    {
        // Last i elements will be in place after this for loop
        for (j = 0; j < n - i - 1; j++)
        {
        	nc++;
            if (string_compare(A[j],A[j+1],nc)==-1){
                swap(A[j], A[j + 1]);
                ms++;
            }
        }
    }
}

int main(){
	int n;cin>>n;
	int numswap=0;
	int numcom=0;

	char a[n][12];

	for(int i=0;i<n;i++)
		cin >> a[i];

	bubble_sort(a,n,numswap,numcom);

	for(int i=0;i<n;i++)
		cout << a[i]<< " ";
	cout <<endl<< numcom << " "<< numswap;
}

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

int string_compare(char** A,int j)
{
	int i=0;

	while(true)
	{
		if(A[j][i]== 0 && A[j+1][i] == 0) return 0;
		if(A[j][i]== 0) return -1;
		if(A[j+1][i]== 0) return +1;
		if(A[j][i]<A[j+1][i]) return -1;
		if(A[j][i]>A[j+1][i]) return +1;
		i++;
	}

	return 0;
}

void swap(char** A,int j)
{
	char temp[MAX];

	for(int i=0;i<12;i++)
	temp[i]=A[j][i];
	for(int i=0;i<12;i++)
	A[j][i]=A[j+1][i];
	for(int i=0;i<12;i++)
	A[j+1][i]=temp[i];


}

char** string_sort(char** A,int n,int& c,int& s)
{
	int i,j;
	c=0;s=0;
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-i-1;j++)
		{	int f;
			f=string_compare(A,j);
			if(f==-1)
			 {
			swap(A,j);
			s++;
			 }
			c++;

		}
	}

	return A;

}

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

	char** A=new char*[n];
	for(int i=0;i<n;i++)
		{
			A[i]=new char[MAX];
		}

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


	char** Ar=new char*[n];
	for(int j=0;j<n;j++)
		{
			Ar[j]=new char[MAX];
		}

	Ar=string_sort(A,n,c,s);

	for(int i=0;i<n;i++)
		{
			cout<<Ar[i]<<" ";

		}
		cout<<endl<<c<<" "<<s;
}

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 11

char**allocate_2d(char**A,int n)
{
A=new int*[m];
for(int i=0;i<MAX;i++)
{
A[i]=new int[MAX];
}

return A;
}

int string_compare(char*f,char*s)
{
int i=0;
while(true)
{
if(*(f+i)==0 &&*(s+i)==0)) return 0;
if(*(f+i)==0 ) return -1;
if(*(s+i)==0) return +1;
if(*(f+i)<*(s+i)) return -1;
if(*(f+i)>*(s+i)) return +1;
i++;
}
}
int string_length (char *x)
{
	int L = 0;
	while (x[L] != ‘\0’) L++;
return L;
}

void string_reverse_in_place (char* s){
int n = string_length(s);
for(int i=0;i<n/2;i++) swap(&s[i],&s[n-1-i]);
s[n] = 0;
}

void  string_sort(char*c)
{

for(int i=0;i<n;i++)
{
for(int j=0;j<n-1-i;j++)
{ int l=string_compare(c[j],c[j+1]);
  if (l==+1) { char*temp=c[j];
                      c[j+1]=c[j];
                      c[j]=temp;
                }
}
}

int main(){

char**c;
int n;
cin>>n;
c=allocate_2d(c,n);
for(int i=0;i<n;i++)
{  cin>>c[i];

}
for(i=0;i<n;i++)
{
 string_reverse_in_place(c[i]);
}
for(int i=0;i<n;i++){
 string_Sort(c[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<cstring>
using namespace std;
void input_arr(char A[][12], int n)
{
int count=0;
for(int i=0;i<=n;i++)
{
cin.getline(A[count++],12);
}
}
int string_compare (char *first, char * second)
{
int i = 0;
while (true)
{
if (first[i] == 0 && second[i] == 0) 
{
cout<<"Number of string_compare operations = "<<i;return 0;}
if (first[i] == 0) {cout<<"Number of string_compare operations = "<<i;return -1;}
if (second[i] == 0) {cout<<"Number of string_compare operations = "<<i;return +1;}
if (first[i] < second[i]) {cout<<"Number of string_compare operations = "<<i;return -1;}
if (first[i] > second[i]) {cout<<"Number of string_compare operations = "<<i;return +1;}
i++;
}

return 0;
}
void swap (char& a, char& b )
{
char temp = a; a = b; b = temp; 
}
void bubble_sort(char *A, int l )
{
for (int i = 0; i < l- 1; i++)
{
for (int j = 0; j < l - i - 1; j++)
{
if (A[j] < A[j + 1])
swap(A[j],A[j + 1]);
}
}
}
void string_sort(char A[][12], int n)
{
for(int i=0;i<n;i++)
{
int l=strlen(A[i]);
bubble_sort(A[i],l);
}
}
void output_arr(char A[][12], int n)
{
for(int i=0;i<=n;i++)
cout<<A[i]<<endl;
}
int main()
{
char A[20][12];
int n;
char first[12];
char second[12];
cin>>first;
cin>>second;
cout<<string_compare(first, second);
cin>>n;
input_arr(A,n);
string_sort(A,n);
output_arr(A,n);
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: 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;
#define MAX 100

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 swap(char*&a, char*&b){
	char*t = a;
	a = b;
	b = t;
}

void reorder(char arr[][MAX], int n, int &comp_count, int &swap_count){
	
	for(int i=0;i<n;i++){
		for(int j=0; j<n-i-1;j++){
			if(string_compare(arr[j], arr[j+1]) == 1){
				swap(arr[j], arr[j+1]);
				swap_count++;
			}
			comp_count++;
		}
	}

}

int main(){

	int n, comp, swap;
	cout<<"Enter number of words : ";
	cin >> n;
	char arr[n][MAX];
	for(int i=0; i<n ;i++){
		cin>>arr[i];
	}
	comp=0;
	swap=0;
	reorder(arr, n,comp,swap);
	for(int i=0; i<n; i++){
		cout<<arr[i]<< endl;
	}
	cout<<comp<<endl;
	cout<<swap<<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: 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>
#include<cstring>
using namespace std;

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++;
}compared++;

return 0;}



void string_reverse(char* a, int n){
int i,j;
int swapped;
for (int i=0;i<n-1;i++)
	{for(j=0;j<n-1-i;j++)
{ if (a[j]<a[j+1]){
  swapped=0;
  swap(&a[i],&a[n-1-i]);
swapped++;
}}
cout<<a;
cout<<swapped<<"times swapped"<<endl;
}

}


int main(){
int n;
int compared;
cin>>n;
	char A[n][12];
	int count=0;
	while(cin.getline(A[count++],12));
	cout<<"strings taken"<<endl;
for(int i=0;i<count;i++) cout<<i<<A[i]<<endl;
for(int k=0;k<n;k++)
{
	for(int l=0;l<n; l++)
 	{
	 compared=0;
 	string_compare(A[k],A[l]);
	compared++;
	}
}
cout<<compared<<"times compared"<<endl;

for(int i=0;i<n;i++)
	{	
	string_reverse(A[i],strlen(A[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: B