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>
#define MAX 12 //Maximum length is 11 + the NULL character
using namespace std;

void swap(char *& a,char * &b)
{
	char t;
	for(int i=0;i<MAX;i++)
	{
		t=a[i];
		a[i]=b[i];
		b[i]=t;
	}
}

int string_compare(char *a,char *b)
{
	
	for(int i=0;i<MAX;i++)
	{
		if(a[i]=='\0' && b[i]=='\0')
		{
			return 0; //If both strings ends at same position they are equal
		}
		
		//If any string ends first then it should be smaller
		else if(a[i]=='\0')
		{
			return 1; 
		}
		
		else if(b[i]=='\0')
		{
			return -1;
		}
		
		//Normal comparison
		else if(a[i]<b[i])
		{
			return 1;
		}
		else if(a[i]>b[i])
		{
			return -1;
		}
		
		//if nothing can be said at i th char go next
	}
	return 0;
}

int findMax(char str[][MAX],int low,int high,int &strcom) //String comparison is performed for finding maximum element index in str[low] to str[high - 1] //high may not be a valid index of str
{
	int max=low; //initial guess for max for comparison
	for(int i=low+1;i<high;i++)
	{
		strcom++; //String comparison counter increament
		if(string_compare(str[max],str[i])>0)
		{
			max=i; //If someone greater is found than current max, update it
		}
	}
	
	return max; //position of the maximum element in the given subarray
}


void string_sort(char str[][MAX],int n,int &strcom,int &strswap)
{
	for(int i=0;i<n;i++)
	{
		int curMax=findMax(str,i,n,strcom); //Select the maximum in remaining array
		if(i==curMax)
		{
			continue; //We don't need to swap if it's at correct position
		}
		
		{
			swap(str[i],str[curMax]); // Give the current Maximum it's correct position
			strswap++; //increament the swap counter
		}
	}
	return;
}

void getStrings(char str[][MAX],int n)
{
	for(int i=0;i<n;i++)
	{
		cin>>str[i];
	}
	return;	
}

void printStrings(char str[][MAX],int n)
{
	for(int i=0;i<n;i++)
	{
		cout<<str[i]<<endl;
	}
	return;
}

int main()
{
	int n;
	cin>>n;
	int strcom=0; //string comparison counter
	int strswap=0; //string swapped counter
	
	char str[n][MAX];
	getStrings(str,n);
		
	string_sort(str,n,strcom,strswap); //Sort using Selection sort
	
	printStrings(str,n);
	cout<<strcom<<endl<<strswap;
	
	return 0;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables.
Rating D: 0
Assigned grade: A