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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 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;
}
int main()
{
	int n;
	cin>>n;
	char s1[n],s2[n];
	cin>>s1;
	cin>>s2;
	string_compare(s1,s2);
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 myswap( char arr1, char arr2){
char temp = arr1;
arr1=arr2;
arr2=temp;}
void getarray(char  arr[][100],int n1,int n2){
for (int i=0;i<n1;i++){
for (int j=0;j<n2;j++){
cin >> arr[i][j];}}}
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  printarray ( char arr[][100],int n1,int n2){
for (int i=0;i<n1;i++){
for (int j=0;j<n2; j++){
cout << arr[i][j];}}}
void selection_sort ( int  arr, int n){
for (int i=0;i<n;i++){
int p= string_compare (arr[i],arr[i+1]);
if( p=-1){
myswap (arr[i],arr[i+1]);}
if (p=0) { i++;}

}}
int main (){
int n;
cin>>n;
char arr [n][100];
getarray (arr,n, 100);
 selection_sort( arr, n);
printarray (arr,n,100);
 
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 c2=0;
int c1=0;

int string_compare (char *first, char * second){
c1++;
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;
}


int argmax (char name[][12], int n)
{
	int maxindex = 0;
	for(int j=1; j<n; j++){
		if(string_compare(name[j], name[maxindex])) maxindex = j;
	}
	return maxindex;
}
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];
	}


void selection_sort (char name[][12], int n)
{
    
    for(int i=n; i>1;i--)
    {
        int maxindex = argmax(name,i); 
        char t[12];
        char *temp = t;
        temp = name[i-1]; 
        c2++;
        string_copy(name[i-1],name[maxindex]);  
        string_copy(name[maxindex],temp);
    }
}

   

int main()
{
int n;
cin>>n;
char name[n][12];
int count=0;
for (int i=0;i<=n;i++) cin.getline(name[count++], 12); 
selection_sort(name,n);
int i;
for (i=n;i>0;i--)
{
    cout << name[i] << endl;
}
cout << name[i];
cout << c1<< endl;
cout << c2;
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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<simplecpp>
int const max=11;
int string_compare(char a[][max],char b[][max])
{
	for(int i=0;i<max;i++)

	{
		if(a[i][max] == 0 && b[i] [max]== 0) return 0;
		if(a[i][max]==0)return 1;
		if(b[i][max]==0)return 1;
		if(a[i][max]<b[i][max])
			return 1;
		if(a[i][max]>b[i][max])
			return -1;
		if(a[i][max]==b[i][max])
			continue;
		return 0;
	}
}
string string_sort(char a[][max])
{
	string temp;
	for(int i=0;i<n;i++)
	{
		string max1=0;
		for(int j=i;j<n;j++)
		{
			if(string_compare((a[i][max]),(a[j][max]))==-1)
			{
				max1=char[j][max];
				index=k;
			}

		}
		temp=a[k][max];
		a[i][max]=max1;
		a[k][max]=temp;


	}
	for(int i=0;i<n;i++)
	{
		cout<<a[i][max];
	}


}
main_program
{
	int n;
	cin>>n;
	char arr[n][max];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<max;j++)
		{
			char x;
			arr[i][j]=x;

		}

	}


}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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_length (char *x)
{
	int L = 0;
	while (x[L] != 0) L++;
    return L;
}
void myswap(char *a,char *b){
    int m=string_length(a);
	int n=string_length(b);
	char t[m+n];
	for(int i=0;i<m+n;i++){
		t[i]=0;
	}
	for(int i=0;i<m;i++){
		t[i]=a[i];
		a[i]=0;
	}
	for(int i=0;i<n;i++){

		a[i]=0;
	}
	for(int i=0;i<n;i++){
		a[i]=b[i];
		b[i]=0;
	}
	for(int i=0;i<m;i++){
		b[i]=0;
    }
	for(int i=0;i<m;i++){
		b[i]=t[i];
	}
}
int string_compare(char *a,char *b){
	int m=string_length(a);
	int n=string_length(b);
	if(m==n){
	   int c=0;
	   for(int i=0;i<m;i++){
	      if(a[i]!=b[i]){
	         if(a[i]>b[i]) return -1;
	         else return +1;
	      }
	      else c=c+1;
	   }
	   if(c==m)return 0;
	}
	else{
	   int i=0,j=0,c=0;
	   while(i<m&&j<n){
	      if(a[i]>b[i])return -1;
	      else if(a[i]<b[i])return +1;
	      else c=c+1;
	      i=i+1;
	      j=j+1;
	   }
	   if(c==m)return +1;
	   else if(c==n)return -1;
	}
	return 0;
}
void string_sort(char a[][12],int m){
    int c=0,h=0;
	for(int i=0;i<m-1;i++){
	   int y=0;
       y=string_compare(a[i],a[i+1]);
       c=c+1;
       if(y==0)continue;
       else if(y==1){
          myswap(a[i],a[i+1]);
          h=h+1;
          i=0;
       }
       else if(y==-1)continue;
	}
	for(int i=0;i<m;i++){
	   cout<<a[i]<<endl;
	}
	cout<<c<<endl<<h;
}
int main(){
	int n;
	cin>>n;
	char a[n][12];
	for(int i=0;i<n;i++){
	   cin>>a[i];
	}
	string_sort(a,n);
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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<simplecpp>
using namespace std;

main_program{
	int n;
	cin>>n;
	for (int i=0;i=1;i++){
		for (int j=1;j<i;j++){
			cout<<"n is positive integer"<<
			cin>>n ;n<15
		}
		cout<<endl;
    }

	for (int m=15+n;m>80;m--){
		for (int p=n/2+1;p>1;p=p-1){
			cout<<"reverse alphabetical order"<<
		}
		cout<<endl;
	}
	cout<<endl;


 return 0;






}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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:
void GaussElim (float A[][MAX], float *b, int n){
        int i,j,k;
        float ratio;

        for(i=0;i<n-1;i++){
                if (A[i][i] == 0) {cout << "mathematical error"; return;}
                for(j=i+1;j<n;j++){
                        ratio = A[j][i]/A[i][i];
                        for(k=0;k<n;k++){
                                A[j][k] = A[j][k]-ratio*A[i][k];
                        }
                        b[j] = b[j]-ratio*b[i];
                }
        }
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 *x, char * y){
int i = 0;
while (true){
if (x[i] == 0 && x[i] == 0) return 0;
if (x[i] == 0) return -1;
if (y[i] == 0) return +1;
if (x[i] < y[i]) return -1;
if (x[i] > y[i]) return +1;
i++;
}
return 0;
}
int main()
{
int n;
cin>>n;
char arr[n];
cin.getline(arr,n);
int string_compare( arr[i], arr[i+1]);
return 0;
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 i=0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
if (first[i] < second[i]) return 1;
if (first[i] > second[i]) return -1;
i++;
}
}

void string_sort(char* s, char* rev_s){
int n = string_length(s);
for(int i=0;i<n;i++){
rev_s[n-1-i] = s[i];
rev_s[n] = 0;
}
}
int main(){

unsigned int n;
cin>>n;

char chr[n];
char reverse[n];

for(int i=0;i<n;i++){
cin>>chr;
}

sting_sort(chr, reverse);

for(int i=0;i<n;i++){
cout<<reverse<<endl;
}
return 0;
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 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;
}
int main(){
//int n;
//cin>>n;
char first[11];
char second[11];
cin.getline(first,11);
cin.getline(second,11);
cout<<string_compare(first,second);}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 input_strings(char a[][max],int n)
{
	for(int i=0;i<n;i++)
	{	
		for(int j=0;j<11;j++){cin>>a[i][j];
		if(a[i][j]==0)i++;j=0;}
		a[i][11]=0;
	}
}

int string_compare(char p[],char q[])
{
	for(int i=0;i<12;i++)
	{
		if(p[i]>q[i]){return 1;break;}
		if(p[i]<q[i]){return -1;break;}
		else return 0;
	}
}	
			
void string_sort(char p[],char q[])
{
	char temp[12];
	for(int i=0;i<12;i++)
	{
		temp[i]=p[i];p[i]=q[i];q[i]=temp[i];
	}
}

void output_strings(char a[][max],int n)
{
 	for(int i=0;i<n;i++)
 	{
 		for(int j=0;j<12;j++)
 		{
 			if(a[i][j]==0){i++;j=0;}
 			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
}

int main()
{
	int n,z,x=0,y=0;
	cin>>n;
	char a[n][max];
	input_strings(a,n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n-i-1;j++)
		{
		z=string_compare(a[j],a[j+1]);
		x=x+1;
		if(z==1)
		{string_sort(a[j],a[j+1]);y=y+1;}
		}
	}
	output_strings(a,n);
	cout<<endl<<x<<endl<<y;
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D