marcind
BAN USER- 0of 0 votes
AnswersThere's a major problem in the implementation of the following class. Can you spot it? How can you fix
the problem? You can propose more than one solution, depending on the requirement specifications of
the class.
- marcind in United States#include<iostream> using namespace std; template <class T> class Array { private: T *m_pData; unsigned int m_nSize; public: Array(unsigned int nSize) : m_nSize(nSize) { if(m_nSize > 0) m_pData = new T[m_nSize]; } virtual ~Array() { if(m_pData != NULL) delete [] m_pData; } bool Set(unsigned int nPos, const T& Value) { if(nPos < m_nSize) { m_pData[nPos] = Value; return true; } else { return false; } } T Get(unsigned int nPos) { if(nPos < m_nSize) return m_pData[nPos]; else return T(); } };
| Report Duplicate | Flag | PURGE
C++
<pre lang="" line="1" title="CodeMonkey97872" class="run-this">public static String getSMSText(String str)
{
String patterns[]={"10", "ABC2", "DEF3", "GHI4", "JKL5", "MON6",
"PQRS7", "TUV8", "WXYZ9", " *","#"};
int possitions[]={2,4,4,4,4,4,5,4,5,2,1};
StringBuilder ParsedString = new StringBuilder();
Character c = str.charAt(0);
int counter=0;
int index = 0;
int possition = 0;
for(int i=1;i<str.length();i++)
{
//System.out.println(c);
if(str.charAt(i) == c)
{
counter++;
}
else
{
if(c!='#')
{
if(c=='*') index=9;
else index = ((int)c-48)-1;
possition = counter%possitions[index];
char toAdd = patterns[index].charAt(possition);
if(toAdd!='0')
ParsedString.append(toAdd);
c=str.charAt(i);
counter=0;
}else
{
c=str.charAt(i);
}
}
}
if(c!='#')
{
if(c=='*') index=9;
else
index = ((int)str.charAt(str.length()-1)-48)-1;
possition = counter%possitions[index];
ParsedString.append(patterns[index].charAt(possition));
}
return ParsedString.toString();
}</pre><pre title="CodeMonkey97872" input="yes">
</pre>
Repnatetouche, Applications Developer at Alcatel Lucent
My name is NateTouche . I currently live in Seattle . One desire that has always been a constant since As a ...
Repemilinarula, Dev Lead at ABC TECH SUPPORT
Hi, i've been spotting for about 4 years.Teamwork: works well as a member of a team, pitches in ...
counting sort will do the job in O(n)
- marcind November 28, 2011