Problem: At college X, students and professors often use abbreviations for long titles of academic papers and projects. In this problem, you are asked to verify whether a given abbreviation matches the first letters of the words in a string, ignoring case. The abbreviation is valid only if it follows the exact order of the first letters of each word.

Examples:

For the words:
United Nations
united nations
United nations
united Nations

Valid abbreviations are:
UN, un, Un, uN

For the words:
Machine Learning college X

Valid abbreviations are:
MLIB (or any combination of upper and lowercase letters in the same order, such as mLiB).

Your Task

Main Program:

Write a C++ program that accepts four characters from the user and stores them in four character variables. Pass these characters to a function named isValidAbbreviation, which returns true if the abbreviation is valid, otherwise returns false. In the main function, print "yes" or "no" (lowercase letters) based on the returned value.

isValidAbbreviation Function:

1. Accept the words character by character as input.
2. Check whether the first letter of each word matches the corresponding abbreviation character (case insensitive).
3. Return false if there is any mismatch.
4. Return true if the entire abbreviation is correct.

To read character sequences with spaces:
First write:
cin >> noskipws;

Then a loop like the following may be used:
for (cin >> c; c != '\n'; cin >> c)

Output Format:

Print:
yes
or
no

accordingly.

Note:

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

Student submission:
#include <simplecpp>

bool isValidAbbreviation(char c1, char c2, char c3, char c4){
    char c;
    bool is_first_letter = true, result;
    int abb_count = 0;
    for (cin >> c; c!='\n'; cin >> c){
        if (c == ' ') {is_first_letter = true; continue;}
        if (!is_first_letter) continue;

        // Below code is executed only when the letter is the first letter of the word
        switch (abb_count){
            case 0:
                // Checks if letter is equal (considering lower and upper cases)
                if ((c == c1) || c == (c1^32)){
                    is_first_letter = false;
                    result = true;
                }
                // If not equal, exit out of the loop with false
                else return false;
                abb_count += 1;
                break;
            case 1:
                if ((c == c2) || c == (c2^32)){
                    is_first_letter = false;
                    result = true;
                }
                else return false;
                abb_count += 1;
                break;
            case 2:
                if ((c == c3) || c == (c3^32)){
                    is_first_letter = false;
                    result = true;
                }
                else return false;
                abb_count += 1;
                break;
            case 3:
                if ((c == c4) || c == (c4^32)){
                    is_first_letter = false;
                    result = true;
                }
                else return false;
                abb_count += 1;
                break;
            default:
                // When words are more than 4, this will execute and return false
                result = false;
                abb_count += 1;
                return result;
                break;
        }
    }
    // When no. of words is less than 3, this will overwrite result = false
    if (abb_count != 4) result = false;
    return result;
}

main_program{
    cin >> noskipws;
    char c1, c2, c3, c4, new_line_char;
    cin >> c1 >> c2 >> c3 >> c4;
    // Remove new line character after storing four letter abbreviation
    cin >> new_line_char;
    bool is_abbreviation = isValidAbbreviation(c1, c2, c3, c4);
    (is_abbreviation) ? cout << "yes" : cout << "no";
}

Grading criterion: Checking the first letter of a word
Rating A: Correctly implements an algorithm for checking the first letter of a word

Rating B: some issue
Rating C: major isuue
Rating D: 0
Assigned grade: A