programming task ask
<pre><code>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"
}
</code></pre>

<p>Task description:</p>

<ol>
<li>Implement the two functions <code>getNiCount</code> and <code>replaceNiWithNI</code> of the class <code>MyClass</code>: 
<ul>
<li><code>getNiCount</code> should return the number of occurrences of "Ni" within <code>szTestString1/2</code> (case sensitive)</li>
<li><code>replaceNiWithNI</code> should replace all occurrences of "Ni" in <code>szTestString1/2</code> with "NI" (case sensitive)</li>
</ul></li>
<li>Invoke the two functions <code>getNiCount</code> and <code>replaceNiWithNI</code>.</li>
<li>Display the string given in the last comment on screen. <code>X</code> and <code>Y</code> should be replaced with the real values.</li>
<li>The class <code>MyClass</code> should be able to deal with both <code>szTestString1</code> (ASCII) and <code>szTestString2</code> (Unicode).</li>
</ol>

<p>General requirements:</p>

<p>The code should be</p>

<ul>
<li>easy to understand and maintain (Priority 1)</li>
<li>technically elegant (Priority 2)</li>
<li>as (CPU) efficient as possible (Priority 3)</li>
</ul>

<p>You’re allowed to use all techniques, toolkits and frameworks which are based on the C++ language.</p>

<p>my solution (incomplete)</p>

<p>The logic is below...
However in my system the function2 "replace" is crashing. Cannot get it fixed.</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;string&gt;
using namespace std;

class MyClass
{
public:
 void getNiCount(const char*,const wchar_t*);
  //cout&lt;&lt;"\nCount is :"&lt;&lt;count;

void replaceNiWithNI(const char*,const wchar_t*);

};

void MyClass::getNiCount(const char* x,const wchar_t* y)
{
     int count=0;
     int ycount=0;
   for(int i=0; x[i]!='\0';i++)
   {
       if(x[i]=='N')
       {   if(x[i+1]=='i')
                          count++;
       }
       }
   for(int i=0; y[i]!='\0';i++)
   {
       if(y[i]=='N')
       {   if(y[i+1]=='i')
                          ycount++;
       }
       }
       cout&lt;&lt;"\nFound "&lt;&lt;count&lt;&lt;" occurences of Ni in String 1";
       cout&lt;&lt;"\nFound "&lt;&lt;ycount&lt;&lt;" occurences of Ni in String 2";
}

void MyClass:: replaceNiWithNI(const char* x,const wchar_t* y)
{    char* a;
     wchar_t* b;
     strcpy(a,x);


     for (int i=0;a[i]!='\0';i++)
     {
         if (a[i]=='N')
         {  if(a[i+1]=='i')
            {
                           a[i+1]='I';
                           }
         }
         }
     for (int i=0;y[i]!='\0';i++)
     {
         b[i]=y[i];
     }
     for (int i=0;b[i]!='\0';i++)
     {
         if (b[i]=='N')
         {  if(b[i+1]=='i')
            {
                           b[i+1]='I';
                           }
         }
     }

     cout&lt;&lt;"\nNew String 1 is :";
     puts(a);
     cout&lt;&lt;"\nNew String 2 is :";&lt;&lt;b

}


int main()
{
 const char *szTestString1 = "Ni nI NI nI Ni";
 const wchar_t *szTestString2 = L"Ni nI NI nI Ni";
 MyClass ob1;
 ob1.getNiCount(szTestString1,szTestString2);
 ob1.replaceNiWithNI(szTestString1,szTestString2);
 getchar();
 return 0;
}
</code></pre>
