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;
void swap(char*a,char*b)
{char* temp=a;
 a=b;
b=temp;
return;
}
int string_length(char*a)
{  int l=0;
while(a[l]!='\0')l++;
return l;
}

void bubble(char*A,int n)
{   int i,j;
  for(int i=0;i<n-1;i++)
   {
      for(j=0;j<n-i-1;j++)
       { 
         if(A[j]<A[j+1])
          swap(&A[j],&A[j+1]);
       }
  }
}
char string_sort(char*a, int l)
{
  char b[11];
for(int i=0;i<l;i++)
 {      b[i]=int('a[i]');
}
 bubble(b,l);
char c[11];
for(int i=0;i<l;i++)
{  c[i]=char(b[i]);
}
return ;
int string_compare(char*a,char*b)
{      int i=0;
while(true)
   {      if(a[i]==0&&b[i]==0) return 0;
          if(a[i]==0) return -1;
          if(b[i]==0) return +1;
          if(a[i]<b[i]) return -1;
          if(a[i]>b[i]) return +1;
i++;
} return 0;
}



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

Grading criterion: Sorting algorithm implemented is Bubble sort.
Rating A: Fully corrrect
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: 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 IsIncreasingDecreasing(int *A, int n){
 int i=1; int b=A[0]; int c=0, d=0;
 while(i<n){
  if(b>A[i]) c+=1; 
  else d+=1;
  b=A[i];
  i+=1; }
 if(n==1) return 1;
 if (c==n-1) return 2; 
 else if(d==n-1) return 1;
 else return 3; }
int main(){
 int n; cin>>n;
 int arr[n]; 
 for(int i=0; i<n; i++) {cin>>arr[i];}
 cout<<IsIncreasingDecreasing(arr, n);}

Grading criterion: Sorting algorithm implemented is Bubble sort.
Rating A: Fully corrrect
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 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 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_copy (char dest[] , char source[] ) {
	int i;
	for(i=0; source[i] != 0 ;i++){
		dest[i] = source[i];
	}
	dest[i] = source[i];
	}

void string_swap(char a[][12] , int n1 , int n2 ){
    char temp[12];
    string_copy( temp , a[n2]);
    string_copy( a[n2] , a[n1] );
    string_copy( a[n1] , temp );
}


void string_sort(char a[][12], int n ){
    int p=0 , q=0;
    
    for(int i=0 ; i<n-1 ; i++){
        for(int j=0 ; j<n-1-i ; j++){
            p++;
            if( string_compare( a[j] , a[j+1] )==1 ) {
                
                string_swap( a , j , j+1);
                q++;
            }
        }
       
    }
    for(int i=0 ; i<n ; i++){
        cout<<a[i]<<endl;
    }
    cout<<p<<endl;
    cout<<q<<endl;
}

int main(){
    int n;
    cin>>n;
    char arr[n][12];
    for(int i=0 ; i< n ; i++){
        cin>>arr[i];
    }
    string_sort( arr , n); //to sort in rev order and print
    
}

Grading criterion: Sorting algorithm implemented is Bubble sort.
Rating A: Fully corrrect
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: A
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 100
using namespace std;
int len(char *s){
int L = 0;
while (x[L] != ‘\0’) L++;
return L;

}
int string_compare(char *s1,char *s2){
int i=0;
while(1){
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;
}

void string_sort(char *s){
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1;;j++){
if(string_compare(A[j],A[j+1])==1){

}
}
}
}

}
int main(){
int n;
cin>>n;
char str[12];
char A[max][max];
for(int i=0;i<n;i++){
cin>>str;
for(int j=0;j<12;j++){
A[i][j]=str[j];
}
}

}
}

Grading criterion: Sorting algorithm implemented is Bubble sort.
Rating A: Fully corrrect
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 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 x[][12], int m, int n)
{
int i = 0;
while (true){
if (x[m][i] == 0 && x[n][i] == 0) return 0;
if (x[m][i] == 0) return +1;
if (x[n][i] == 0) return -1;
if (x[m][i] < x[n][i]) return +1;
if (x[m][i] > x[n][i]) return -1;
i++;
}
return 0;
}

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

int main ()
{
int n;
cin>>n;
char x[n][12];

for (int i=0; i<n+1; i++)
	{
	cin.getline(x[i], 12);
	}
string_sort (x, n);
for (int i=0; i<n+1; i++)
	{
	cout<<x[i]<<'\n';
	}

}

Grading criterion: Sorting algorithm implemented is Bubble sort.
Rating A: Fully corrrect
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 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, char*b){
int i=0; while(true){
if (a[i]==0 && b[i]==0) cout<<"0";break;
if (a[i]==0) cout<<" +1";break;
if (b[i]==0) cout<<" -1";break;
if (a[i]<b[i]) cout<< "+1";break;
if( b[i]<a[i]) cout<<" -1";break;
i++;
}
return 0;
}

int main(){
char a[11];char b[11];
cin>>a;
cin>>b;
string_compare(a,b);
}

Grading criterion: Sorting algorithm implemented is Bubble sort.
Rating A: Fully corrrect
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 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_length (char *x)
{
	int L = 0;
	while (x[L] !=0) L++;
return L;
}

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


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 string_sort(char A[][12],int n){
	int i, j;
	for (i = 0; i < n - 1; i++){
		for (j = 0; j < n - i - 1; j++){
			if(string_compare(A[j],A[j+1])==-1){
	                swap(A[j], A[j + 1]);
	                q++;
	                }
        }
    }
    return q;
}

int main(){
	int n,p=0,q=0;
	cin>>n;
	char A[n][12];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<n;i++){
		string_sort(A,n);
		cout<<A[i]<<endl;
		}
	cout<<p<<endl;
	cout<<q;
}

Grading criterion: Sorting algorithm implemented is Bubble sort.
Rating A: Fully corrrect
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: 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<simplecpp>
#include<cstring>
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++;
}

}

void swap(char* a, char* b){
	char temp[11];
	
	strcpy (temp,a);
	strcpy (a,b);
	strcpy (b,temp);
	
	}

void string_sort(char c[][11], int n){
	int cswap, ccomp;
	cswap=ccomp=0;
	int i, j;
    for (i = 0; i < n - 1; i++)
    {
        for (j = 0; j < n - i - 1; j++)
        {	ccomp=ccomp+1;
        	if ((string_compare(c[j],c[j+1])==-1)){
        		swap(c[j], c[j+1]);
        		cswap=cswap+1;
        	}                    
        }
    }

  
    for (int i=0; i<n; i++){
		cout << c[i]<< " ";
}
cout << endl;
		  cout << ccomp << endl;
	cout<<cswap;

	
	
}


main_program{
	int n;
	cin >> n;
	char c[n][11];
	for (int i=0; i<n; i++){
		cin >> c[i];
	}
string_sort(c, n);

}

Grading criterion: Sorting algorithm implemented is Bubble sort.
Rating A: Fully corrrect
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: B
Problem: In this problem, you are required to write only two functions in the file implementation.cpp. A main program (main.cpp) is already provided and must not be modified.

Function 1: noOfDays

int noOfDays(int m)

Write a function named noOfDays that takes a single integer m (1 to 12 inclusive) and returns the number of days in that month for the year 2025.

You may refer to a calendar to determine the correct number of days for each month.

Examples:

noOfDays(7) must return 31  
noOfDays(2) must return 28  

When this function is called:
- Argument m is guaranteed to be between 1 and 12.

--------------------------------------------------

Function 2: oneWeekLater

int oneWeekLater(int d, int m)

Write another function named oneWeekLater which MUST USE the function noOfDays.

This function takes two integers:
- d represents the day.
- m represents the month.

The function should return a single integer representing the day (between 1 and 31) that occurs exactly 7 days after the given day and month.

Examples:

oneWeekLater(20, 8) must return 27  
oneWeekLater(24, 2) must return 3  

Explanation:
- 27 August is 7 days after 20 August.
- 3 March is 7 days after 24 February.

When this function is called:
- Argument d is guaranteed to be between 1 and 31.
- Argument m is guaranteed to be between 1 and 12.

--------------------------------------------------

Main Program

A main program (main.cpp) is already provided. It reads the day and month from input and calls the functions noOfDays and oneWeekLater with appropriate arguments.

You must only implement the required functions in implementation.cpp.

--------------------------------------------------

Note

- Do not print any extra messages such as:
  cout << "Enter a number"
  cout << "The computed answer is"
- Use cout only to print the computed final output.
- Do not print unnecessary spaces.
- Do not hard-code the answers.
- If any test case passes by simply printing output without logic, marks will not be awarded.

Student submission:
#include <simplecpp>

int noOfDays(int m);{
cin >> m;
   m<=12 && m>=1;
          if (( m= 1|| m=3 || m=5 || m=7 || m=8 || m=10 || m=12);
                cout <<"31");
               else if ( m=2;
                cout << "28");
             else if (( m= 4|| m=6 || m=9 || m=11);
               cout << "30");




}
int oneWeekLater(int d, int m);{
cin >> d >> m;
       if ( d=d+7<= noOfDays(m);
           cout << "d+7");
            else if (( d=d+7> noOfDays(m));
                     cout << d+7-noOfDays(m));





}

main_program
{
    int day, month;
    cin >> day >> month;
    cout << noOfDays(month) << " " << oneWeekLater(day, month) << endl;
}

Grading criterion: Function noOfDays: Declaration and header
Rating A: Correctly declares the function and definition i.e. correct return type along with the name of the function and its arguments

Rating B: Some issue. 

Rating C: Major issue. 

Rating D: 0
Assigned grade: B
Problem: In this problem, you are required to write only two functions in the file implementation.cpp. A main program (main.cpp) is already provided and must not be modified.

Function 1: noOfDays

int noOfDays(int m)

Write a function named noOfDays that takes a single integer m (1 to 12 inclusive) and returns the number of days in that month for the year 2025.

You may refer to a calendar to determine the correct number of days for each month.

Examples:

noOfDays(7) must return 31  
noOfDays(2) must return 28  

When this function is called:
- Argument m is guaranteed to be between 1 and 12.

--------------------------------------------------

Function 2: oneWeekLater

int oneWeekLater(int d, int m)

Write another function named oneWeekLater which MUST USE the function noOfDays.

This function takes two integers:
- d represents the day.
- m represents the month.

The function should return a single integer representing the day (between 1 and 31) that occurs exactly 7 days after the given day and month.

Examples:

oneWeekLater(20, 8) must return 27  
oneWeekLater(24, 2) must return 3  

Explanation:
- 27 August is 7 days after 20 August.
- 3 March is 7 days after 24 February.

When this function is called:
- Argument d is guaranteed to be between 1 and 31.
- Argument m is guaranteed to be between 1 and 12.

--------------------------------------------------

Main Program

A main program (main.cpp) is already provided. It reads the day and month from input and calls the functions noOfDays and oneWeekLater with appropriate arguments.

You must only implement the required functions in implementation.cpp.

--------------------------------------------------

Note

- Do not print any extra messages such as:
  cout << "Enter a number"
  cout << "The computed answer is"
- Use cout only to print the computed final output.
- Do not print unnecessary spaces.
- Do not hard-code the answers.
- If any test case passes by simply printing output without logic, marks will not be awarded.

Student submission:
#include<simplecpp>
int noOfDays(int m)
{
        int n;
        if(m>7)
        {
                if(m%2==0)
                {
                        n=31;
                }
                else
                {
                        n=30;
                }
        }
        else
        {
                if(m==2)
                {
                        n=28;
                }
                else if(m%2==0)
                {
                        n=30;
                }
                else
                {
                        n=31;
                }
        }
        return n;
}

    int oneWeekLater(int d,int m)
{
        int k;
        k=noOfDays(m);
        int n=d;
        for(int i=0;i<7;i++)
        {
                n++;
                if(n>k)
                {
                        n=1;
                }
        }
        return n;
}

Grading criterion: Function noOfDays: Declaration and header
Rating A: Correctly declares the function and definition i.e. correct return type along with the name of the function and its arguments

Rating B: Some issue. 

Rating C: Major issue. 

Rating D: 0
Assigned grade: A