PDA

مشاهده نسخه کامل : سورس کلاس دیکشنری در Cpp



ravegoat
15-08-09, 15:55
کلاس لیست لغات + عمل گر ها



#ifndef DICTIONARY_H
#define DICTIONARY_H
class Dictionary


{
public:
Dictionary();
~Dictionary();
void AddValue(char* key, char* val);
void RemoveValue(char* key);
void SetValue(char* key, char* val);
char* GetValue(char* key);
char* Dictionary::operator[] (char* key);
bool Dictionary::operator> (Dictionary dict2);
bool Dictionary::operator< (Dictionary dict2);
bool Dictionary::operator>=(Dictionary dict2);
bool Dictionary::operator<=(Dictionary dict2);
bool Dictionary::operator!=(Dictionary dict2);
bool Dictionary::operator==(Dictionary dict2);
void Reset();
private:
char* vKeyVal[600][2];
int nCurPointer;
};

Dictionary::Dictionary()


{
nCurPointer = 0;
}

Dictionary::~Dictionary()


{
Reset();
}

void Dictionary::AddValue(char* key, char* val)


{
vKeyVal[nCurPointer][0] = key;
vKeyVal[nCurPointer][1] = val;
nCurPointer += 1;
}

void Dictionary::RemoveValue(char* key)


{
for (int i = 0; i <nCurPointer; i++)


{


if (vKeyVal[i][0] == key) {
vKeyVal[i][0] = "";
vKeyVal[i][1] = "";
}

}

}

void Dictionary::SetValue(char* key, char* val)


{
for (int i = 0;i < nCurPointer; i++)


{


if (vKeyVal[i][0] == key) {
vKeyVal[i][1] = val;
}

}

}

char* Dictionary::GetValue(char* key)


{
for (int i = 0;i < nCurPointer; i++)


{


if (vKeyVal[i][0] == key) {
return vKeyVal[i][1];
}

}

return "";
}

char* Dictionary::operator[] (char* key)


{
return GetValue(key);
}

bool Dictionary::operator> (Dictionary dict2)


{
return (nCurPointer > dict2.nCurPointer);
}

bool Dictionary::operator< (Dictionary dict2)


{
return (nCurPointer < dict2.nCurPointer);
}

bool Dictionary::operator>= (Dictionary dict2)


{
return (nCurPointer >= dict2.nCurPointer);
}

bool Dictionary::operator<= (Dictionary dict2)


{
return (nCurPointer <= dict2.nCurPointer);
}

bool Dictionary::operator!= (Dictionary dict2)


{
return (nCurPointer != dict2.nCurPointer);
}

bool Dictionary::operator== (Dictionary dict2)


{
return (nCurPointer == dict2.nCurPointer);
}

void Dictionary::Reset()


{
for (int i = 0; i < 100; i++)


{
vKeyVal[i][0] = "";
vKeyVal[i][1] = "";
nCurPointer = 0;
}

}

#endif



منبع (Only the registered members can see the link)

ravegoat
15-08-09, 16:01
سورس دیکشنری ساده (C, C++ , Borland Cpp)

بانک لغت این برنامه فایل popdefs.txt است که می تونید تغییرش بدید.:cool:


دانلود (Only the registered members can see the link)
فایل ZIP
64 کیلوبایت


منبع (Only the registered members can see the link)