14622 - Naming Convention   

Description

(This is a rework of 13891 - Polymorphic naming convention conversion.)

NOTE: You are required to implement both the SnakeCase class and the CamelCase class.

In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation, with the goal of enhancing program readability.

For the naming of identifiers, a common recommendation is “Use meaningful identifiers.” A single word may not be as meaningful, or specific, as multiple words. Consequently, some naming conventions specify rules for the treatment of “compound” identifiers containing more than one word. Three most popular naming conventions are explained below:

  • kebab-case is a naming convention where words are separated by hyphens (-). For example, my-variable-name or my-function-name are examples of the kebab case.
  • snake_case is a naming convention where words are separated by underscores (_). For example, my_variable_name or my_function_name are examples of the snake case.
  • CamelCase is a naming convention where the first letter of each word is capitalized and there are no separators. For example, MyVariableName or MyFunctionName are examples of the camel case.

(From Wikipedia, the free encyclopedia, https://en.wikipedia.org/wiki/Naming_convention(programming))_


In this problem, we consider an Integrated Development Environment (IDE) that supports naming convention conversion. We assume that the kebab case is the default naming convention. The IDE can convert to a different naming convention according to a programmer’s preference. The IDE can also revert back to the default naming convention for the integration among multiple program files.

We first design the abstract base class ‘Case’ as an interface, which contains two pure virtual member functions:

  • convert: convert to the desired naming convention;
  • revert: revert back to the default naming convention, i.e., the kebab case.

You are asked to implement the two derived classes SnakeCase and CamelCase by overriding the two virtual functions, convert and revert.

Note: It is highly recommended to practice std::stringstream in this problem. Here is a simple code that shows you how to use stringstream:

#include <iostream>
#include <sstream> // header file for stringstream
using namespace std;
int main(){
    string s;
    stringstream ss;
    getline(cin, s);
    ss << s;
    while(!ss.eof()){
        string t;
        getline(ss, t, ' ');
        cout << t << "\n";
    }
    return 0;
}
/*
- Sample Input
This is a sentence for testing this code.
- Sample Output
This
is
a
sentence
for
testing
this
code.
*/

For more information, please refer to the C++ reference in I’m reference

Input

A line contains only lowercase letters and hyphens.

Output

The Snake case and the Camel case for the input string. Please refer to the sample output for details.

Sample Input  Download

Sample Output  Download

Partial Judge Code

14622.cpp

Partial Judge Header

14622.h

Tags




Discuss