6. Please write a string class, its Construction and Destruction function, and then override those operators, + , =, == (8 ‘)
There is the string class header, please finished the string.cpp files, and then write a simple application to test the string class.
#pragma once
class CString
{
protected:
LPTSTR m_pBuffer;
public:
// Construction
CString(LPCTSTR pcszValue = TEXT(""));
//Destruction
~CString();
// = operator
const CString& operator =(LPCTSTR pcwszValue);
const CString& operator =(const CString& rSrc);
// == operator
BOOL operator == (LPCTSTR pcszValue) const;
BOOL operator == (const CString& rValue) const;
friend BOOL operator == (LPCTSTR pcwszValue, const CString& rValue);
// += operator
const CString& operator += (LPCTSTR rSrc);
const CString& operator += (const CString& rSrc);
// + operator
const CString& operator + (LPCTSTR pszSrc);
const CString& operator + (const CString& rSrc);
friend const CString& operator + (LPCTSTR pszSrc,const CString& rSrc);
private:
DWORD m_dwLength;
DWORD GetLength() const { return m_dwLength; }
};
7. Write a function to check if a word is in a dictionary, if the word exist in the dictionary, output “We found the word!”, else give the similar words. (10 ‘)
There have two rules for the “Similar words”
a) One letters less than the original words, and others letters are same.
b) One letters more than the original words, and others letters are same.
For Example:
The dictionary is [aback, abaft, abaisse, abbe, can, an, out, get,g, gtc,]
If we search “abaft”, the search result is “We found the word!”
If we search “gt”, the search result is “which word you try to find? get, g or gtc.”
If we search “notebook”, the search result is “notebook no found!”