CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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: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. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<simplecpp>
using namespace std;
int main(){
int n;
void string_length (a);
    cin>>n;
	int a;
	    while(n<15 && a<11){
		    cin>> char x[a]; cin.getline(a,n);
	}
	



int string_compare(char* first, char* second){
int i=0;
while(true){
	if (first[i]==0 && second==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 *a, int n){
	int i, j;
	for(i=1;i<n;i++){
		j=i;
		while(j>0 && a[j-1]>a[j]){
			swap(&a[j],&a[j-1]);
			j=j-1
		}
	}
	
}
		   
		  
void string_reverse(char* a, char* rev_a){
	int n= string_length(a)
		for(int i=0; i<n; i++) rev_a= a[i]
		rev_[n]=0
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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: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. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<simplecpp>
#define max 100
int compare(char a[],char b[],int &k);
void sort(char a[][max],int n);

main_program{
	int n,i;
	cin>>n;
	char a[max][max];
	
	for(i=0;i<n+1;i++)
	scanf("%s",a[i]);
	
	sort(a,n);
}

void sort(char a[][max],int n)
{
	int i,j,k=0,p=0;
	
	
    for (i=1;i<n;i++){
    if(a[i]==0)
    {continue;}
    
        j=i;
     	while (j > 0 && (compare(a[j],a[j-1],k)==-1) ){ 
            swap (a[j],a[j-1]);
            p++;
            j = j - 1;
        }
    }
	for(i=n-1;i>=0;i--)
	{ if(a[i]==0)
    {continue;}
    
	cout<<a[i]<<endl;}
	
	cout<<k<<endl<<p;
}

int compare(char a[],char b[],int &k)
{
k++;
	int l = 0;
while (1)
{
	if (a[l] == 0 && b[l] == 0) 
	return 0;
	if (a[l] == 0) 
	return -1;
	if (b[l] == 0) 
	return +1;
	if (a[l] < b[l]) 
	return -1;
	if (a[l] > b[l])
 	return +1;
	l++;
	}
return 0;
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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: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. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#define MAX 20
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 myswap(char* m,char* n){
char s[MAX];int i=0;
for(i=0;m[i]!=0;i++){
s[i]=m[i];}s[i]=0;
for(i=0;n[i]!=0;i++){
m[i]=n[i];}m[i]=0;
for(i=0;s[i]!=0;i++){
n[i]=s[i];}n[i]=0;}

void string_sort(char a[][MAX],int n,int& l,int& z){
for(int i=1;i<=n-1;i++){
for(int j=i-1;j>=0;j--){
int k=string_compare(a[j+1],a[j]);l++;
if(k==-1){myswap(a[j+1],a[j]);z++;}
if(k==+1){break;}}}}

using namespace std;
int main(){
int n;int l,z;l=z=0;
cin>>n;
char a[n][MAX];
for(int i=0;i<=n-1;i++){
cin>>a[i];}
string_sort(a,n,l,z);
for(int i=n-1;i>=0;i--){
cout<<a[i]<<endl;}
cout<<l<<endl;
cout<<z;
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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: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. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;
#define max 11
int e=0, z=0;
int string_compare(char arr[][max],int i,int j){
	e++;
	int k=0;
	while(true){
		if(arr[i][k]==0 && arr[j][k]==0) return 0;
		if(arr[i][k]==0) return -1;
		if(arr[j][k]==0) return 1;
		if(arr[i][k]<arr[j][k]) return -1;
		if(arr[i][k]>arr[j][k]) return 1;
		k++;}
		return 0;
	}
void reverse(char arr[][max],int i,int j){
	char temp[max];
	int p;
	for( p=0;arr[j][p]!='\0';p++){
		temp[p]= arr[j][p];}
	temp[p]='\0';
	int m;
	for( m =0;arr[i][m]!='\0';m++){
		arr[j][m]=arr[i][m];}
	arr[j][m]='\0';
	int b;
	for( b=0;temp[b]!='\0';b++){
		arr[i][b]= temp[b];}
	arr[i][b]='\0';}
void string_sort(char arr[][max],int n){
	int i,j;
	for(i=1;i<n;i++){
		j=i;
		
		while(j>0 && string_compare(arr,j,j-1)==1){
			z++;
			reverse( arr,j-1,j);
			j=j-1;
		}
	}
}

int main(){
int n;
cin>>n;
char arr[n][max];
for(int u=0;u<n;u++){
	cin>>arr[u];}
string_sort(arr,n);
for(int k=0;k<n;k++){
	for(int j=0;arr[k][j]!='\0';j++){
		
		cout<<arr[k][j];}
	cout<<"\n";}
cout<<e-2<<"\n"<<z-2;
	}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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: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. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#define max 100
using namespace std;
int count=0;
void swap(char*&a,char*&b){

char t[max];
int i=0;

while(a[i]!='\0'){
t[i]=a[i];i++;}
t[i]='\0';

i=0;

while(b[i]!='\0'){
a[i]=b[i];i++;}
a[i]='\0';

i=0;

while(t[i]!='\0'){
b[i]=t[i];i++;}
b[i]='\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 (first[i] > second[i]) return +1;
i++;
}
return 0;
}

void insertion_sort (char a[][max], int n) {
    int i, j;
    for (i=1;i < n;i++){ 
        j = i;
        int num=string_compare(a[j],a[j-1]);
        while (j > 0 && (num==-1)) {
            count++; 
            swap (a[j],a[j-1]);
            j = j - 1;
        }
    }
}

int main(){
int n;
cin>>n;
char arr[n][max];
for(int i=0;i<n;i++){
cin>>arr[i];
}
insertion_sort(arr,n);
for(int i=n;i>0;i--){
cout<<arr[i]<<endl;}
cout<<count;
}

Grading criterion: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
Rating D: totally wrong
Assigned grade: B
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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: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. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#define MAX 100
using namespace std;
int p=0;
int q=0;

int string_compare(char A[][MAX],int i,int j){
q=q+1;
while(true){
int k=0;
if (A[i][k]==0 && A[j][k]==0) return 0;
if (A[i][k]==0) return -1;
if (A[j][k]==0) return 1;
if (A[i][k]<A[j][k]) return -1;
if (A[i][k]>A[j][k]) return 1;
k=k+1;
}
return 0;
}
char swap (char A[][MAX],int i,int j){
char temp[MAX];
int k=0;
while(A[i][k]!='/0'){
temp[k]=A[i][k];
k=k+1;
}
temp[k]='/0';
k=0;
while(A[j][k]!='/0'){
A[i][k]=A[j][k];
k=k+1;
}
A[i][k]='/0';
k=0;
while(temp[k]!='/0'){
A[j][k]=temp[k];
k=k+1;
}
A[j][k]='/0';
p=p+1;
}
void string_sort(char A[][MAX],int n){
for(int i=1;i<n;i++){
int j=i;
while(j>0 && string_compare(A,j-1,j)==-1){
swap (A,j-1,j);
}
}
}
int main(){
char A[MAX][MAX];
int n;
cin>>n;
for(int i=0;i<n;i++){
cin.getline(A[i],12);
string_sort(A,n);
for(int i=0;i<n;i++){
int k=0;
while(A[i][k]!='/0'){
cout<<A[i][k];
k=k+1;
}
cout<<endl;
}
cout<<p<<endl<<q;
}
}

Grading criterion: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
Rating D: totally wrong
Assigned grade: B
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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: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. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#include<cstring>
#include<cmath>
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;
}
void swapt(char *a, char *b){
char tempt[100];
for(int i=0; i<15; i++)
{
tempt[i]=a[i];
a[i]=b[i];
b[i]=tempt[i];
}}

void string_sort (char A[][12], int n) {
    int i, j,c;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0 && A[j-1] < A[j]){
            swapt(&A[j],&A[j-1]);c++;
            j = j - 1;
        }
    }
}

int main(){
int n;
cin>>n;
//char a[n][12];
//for(int i=0;i<n;i++)
//{
//cin>>a[i];
//}
//char b[n][12]=string_sort(a,n);
//cout<<b[n][12];
//}
char name[n][12];
int count=0;
cout << "Enter at most 5 names with at most 19 characters each:\n";
while (cin.getline(name[count++], 20)); // terminated by ctrl-Z
cout << "The names are:\n";
for (int i=0; i<count; i++)
cout << "\t" << i << ". [" << name[i] << "]" << endl;
}

Grading criterion: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
Rating D: totally wrong
Assigned grade: C
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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: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. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

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

void swap(char*&a,char*&b){
	char t[max];
	int i=0;
	while(a[i]!='\0'){
		t[i]=a[i];i++;}
	t[i]='\0';
	i=0;
	while(b[i]!='0'){
		a[i]=b[i];i++;}
	a[i]='\0';
	i=0;
	while(t[i]!='\0'){
		b[i]=t[i];i++;}
	b[i]='\0';
	}

int string_compare(char *a,char*b){
	int i=0;
	while(true){
		if(a[i]=='\0' && b[i]=='\0') return 0;
		else if(a[i]=='\0') return -1;
		else if(b[i]=='\0') return 1;
		else if(a[i]>b[i]) return 1;
		else if(a[i]<b[i]) return -1;
		i++;}
	}

int string_sort(char a[][max],int n,int *noc){
	int count=0;
	for(int i=0;i<n;i++){
		bool flag=false;
		if(i==0) continue;
		else{
			int j=i;
			int gf=string_compare(a[j],a[j-1]);*noc+=1;
			while(string_compare(a[j],a[j-1])==1){
				swap(a[j],a[j-1]);count++;
				j--;flag=true;
				*noc+=1;
				if(j==0)break;}}
		if (flag==false)break;}
	return count;}

int main(){
	int n,noc=0;
	cin>>n;
	char words[n][max];
	for(int i=0;i<n;i++){
		cin>>words[i];}
	int h=string_sort(words,n,&noc);
	for(int i=0;i<n;i++){
		cout<<words[i]<<'\n';}
	cout<<noc<<"\n"<<h;}

Grading criterion: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
Rating D: totally wrong
Assigned grade: C