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"
}
タスクの説明:
getNiCount次の2つの関数とreplaceNiWithNIクラスを実装しますMyClass。getNiCount内の「Ni」の出現回数を返す必要がありますszTestString1/2(大文字と小文字を区別)replaceNiWithNI「Ni」のすべての出現箇所szTestString1/2を「NI」に置き換える必要があります(大文字と小文字を区別)
getNiCount2つの関数とを呼び出しreplaceNiWithNIます。- 画面の最後のコメントで指定された文字列を表示します。実際の値に置き換える必要があります
X。Y - クラスは(ASCII)と(Unicode)
MyClassの両方を処理できる必要があります。szTestString1szTestString2 
一般的な要件:
コードは次のようになります
- わかりやすく、メンテナンスしやすい(優先度1)
 - 技術的にエレガント(優先度2)
 - 可能な限り(CPU)効率的(優先度3)
 
C ++言語に基づくすべての手法、ツールキット、およびフレームワークを使用できます。
私の解決策(不完全)
ロジックは以下のとおりです...しかし、私のシステムでは、function2「replace」がクラッシュしています。修正できません。
#include<iostream>
#include<string>
using namespace std;
class MyClass
{
public:
 void getNiCount(const char*,const wchar_t*);
  //cout<<"\nCount is :"<<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<<"\nFound "<<count<<" occurences of Ni in String 1";
       cout<<"\nFound "<<ycount<<" 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<<"\nNew String 1 is :";
     puts(a);
     cout<<"\nNew String 2 is :";<<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;
}