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

📄 def.cpp

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

#include "stdafx.h"

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

#include "def.h"

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

Definition::Definition( char* w, char* def[] )
{
	word = new char[ strlen(w) + 1 ];
	strcpy( word, w );

	nMeanings = 0;
	for (; def[ nMeanings ] && nMeanings != MAXMEANS; nMeanings++ )
	{
		meanings[ nMeanings ]= new char[ strlen( def[nMeanings] ) + 1 ];
		strcpy( meanings[ nMeanings ], def[ nMeanings ] );
	}
}

Definition& Definition::operator =( Definition& def )
{
	word = new char[ strlen(def.word) + 1 ];
	strcpy( word, def.word );

	nMeanings = def.nMeanings;

	for ( int i = 0; i < nMeanings; ++i )
	{
		meanings[i] = new char[ strlen( def.meanings[i] ) + 1 ];
		strcpy( meanings[i], def.meanings[i] );
	}

	return *this;
}

Definition::~Definition()
{
	delete[] word;

	for ( int i = 0; i < nMeanings; ++i )
		delete[] meanings[i];
}

void Definition::PutWord( char* s )
{
	word = new char[ strlen(s) + 1 ];
	strcpy( word, s );
	nMeanings = 0;
}

void Definition::AddMeaning( char* s )
{
	if ( nMeanings < MAXMEANS )
	{
		meanings[ nMeanings ] = new char[ strlen(s) + 1 ];
		strcpy( meanings[ nMeanings++ ], s );
	}
}

char* Definition::GetMeaning( int level )
{
	if ( 0 <= level && level < nMeanings )
		return meanings[ level ];
	else
		return NULL;
}

void Definition::Print()
{
	cout << endl << word << ":" << endl;
	for ( int i = 0; i < nMeanings; ++i )
		cout << "  " << meanings[i] << endl;
}

⌨️ 快捷键说明

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