In your solution you should:
-
Use templates so as to avoid code duplication
-
Use STL/boost algorithm types
e.g: basic_string and basic_regex
-
avoid dynamic memory utilisation: new,delete,malloc,free
-
ensure a clear and compact class interface using const&, const and static
-
ensure a secure interface without crashes when delivering short strings or zero pointers
-
using test cases is an advantage
C++ template:
class MyClass {
public:
getNiCount(...)
{
}
replaceNiWithNI(...)
{
}
};
int main() {
const char *szTestString1 = "Ni nI NI nI Ni";
const wchar_t *szTestString2 = L"Ni nI NI nI Ni";
//Invoke getNiCount(...) of class MyClass
//Invoke replaceNiWithNI(...) of class MyClass
//Display on screen: "Found X occurrences of Ni. New string: Y"
}
Task description:
- Implement the 2 functions getNiCount and replaceNiWithNI of the class MyClass:
- getNiCount should return the number of occurrences of "Ni" within szTestString1/2 (case sensitive)
- replaceNiWithNI should replace all occurrences of "Ni" in szTestString1/2 with "NI" (case sensitive)
-
invoke the 2 functions getNiCount and replaceNiWithNI.
-
Display the string given in the last comment on screen. X and Y should be replaced with the real values
-
the class MyClass should be able to deal both with szTestString1 (ASCII) and szTestString2 (Unicode).
You code should be:
- easy to understand and maintain (priority 1)
- techincally elegant (priority 2)
- as (CPU) efficent as possible (priority 3).
you are allowed to use all technics, toolkits and frameworks which are based on the C++ language