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>
#define MAX 12
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 sort(char A[][MAX], int n)
{
    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++)
        {
            if (string_compare(A[j],A[j+1])==-1)
                swap(*A[j], *A[j+1]);
        }
    }
}
main_program{
    int n;
    cin>>n;
char name[n][MAX];
int count=0;
cout << "Enter n names with at most 11 characters each:\n";
while (cin.getline(name[count++], 12)); // terminated by ctrl-Z
sort(name,n);
cout << "The names in order are:\n";
for (int i=0; i<count; i++)
cout << "\t" << i << ". [" << name[i] << "]" << endl;

}
/*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 in reverse alphabetical order using the bubble-sort algorithm taught in class. You will automatically lose 50% of the marks for this program if you implemented the sorting within main. 

Your program should then print out the strings in sorted reverse alphabetical order, starting from the first to the last. 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. Feel free to refer to the lecture slides for help. 

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*/

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C