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;
char ** allocate(int n1,int n2){
           char **A=new char*[n1];
           for(int l=0;l<n1;l++){
               A[l]=new char[n2];}
           return A;
                               }
void get_array(char **A,int n1,int n2){
           for(int i=0;i<n1;i++){
              for(int j=0;j<n2;j++){cin>>A[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;
                 }
int argmax(char**A,int L){
           int maxindex=0;int y=1;
           for(int j=1;j<L;j++){
           if(string_compare(A[y][maxindex],A[y][j])==1){ maxindex=j; }
                               }
           return maxindex;}
void swap(*a,*b){
           char temp=*a; *a=*b; *b=temp;
                }
void selection_sort(char **A,int n){
          for(int i=n;i>1;i++){
               int maxindex=argmax(A,i);
               swap(&A[1][maxindex],&A[1][i-1]);
                              }
        }
int string_length(char **A){
          int L=0;
          while(A[1][L]!='\0'){L++;}
          return L;}
void string_reverse(char **A){
           int p=string_length(A);
           for(int i=0;i<p/2;i++){swap(&A[i],A[p-i-1]); }
           A[p]=0;
           }
void print_strings(char **A,int n1,int n2){
           for(int i=0;i<n1;i++){
               for(int j=0;j<n2;j++){ cout<<A[i][j]<<endl; }
int main(){
           int n;cout<<"Enter no.of strings ";cin>>n;
           char **A;
           int i=1;
           A=allocate(i,n);
           cout<<"Enter strings ";
           get_array(A,i,n);
           selection_sort(A,n);
           string_reverse(A);
           print strings(A,i,n);
           cout<<(n*n/2)<<endl<<(n-1);
          }

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: B