(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:
-
). For example, my-variable-name
or my-function-name
are examples of the kebab case._
). For example, my_variable_name
or my_function_name
are examples of the snake case.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
A line contains only lowercase letters and hyphens.
The Snake case and the Camel case for the input string. Please refer to the sample output for details.