⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diction.cpp

📁 《C++程序设计习题及解答》配套代码VC版
💻 CPP
字号:
// diction.cpp: implementation of the Dictionary class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "diction.h"

#include <string.h>
#include <iostream.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Dictionary::Dictionary( int n)
{
	nWords = 0;
	maxWords = n;
	words = new Definition[n];
}

Dictionary::~Dictionary()
{
	delete[] words;
}

long Dictionary::FindWord( char* s )
{
	for ( int i = 0; i < nWords; ++i )
		if ( strcmp( words[i].GetWord(), s ) == 0 )
			return i;

	return -1;
}

void Dictionary::AddWord( Definition& word )
{
	if ( nWords < maxWords )
	{
		words[ nWords ] = word;
		++ nWords;
	}
}

int Dictionary::GetDef( char* word, char* def[] )
{
	int nM = 0;
	int wordIdx = FindWord( word );
	if ( wordIdx != -1 )
	{
		nM = words[ wordIdx ].GetnMeans();
		for ( int i = 0; i < nM; i++ )
		{
			char* pMeaning = words[wordIdx].GetMeaning(i);
			delete def[i];
			def[i] = new char[ strlen( pMeaning ) + 1 ];
			strcpy( def[i], pMeaning );
		}
	}

	delete def[nM];
	def[nM] = NULL;

	return nM;
}

void Dictionary::Print( char* w )
{
	int wordIdx = FindWord( w );
	if ( wordIdx != -1 )
		words[ wordIdx ].Print();
	else
		cout << "couldn't find the word " << w << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -