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

📄 structure.cpp

📁 The subject which is to us propos¨&brvbar is as follows: calculation of the degr¨&brvbar d&iexcl &ma
💻 CPP
字号:
#pragma warning (disable: 4267)

#include "Structure.h"
#include <iterator>

CSetAtom::CSetAtom() {}
CSetAtom::~CSetAtom() {}

/* CRegle class */

CRegle::CRegle() {};

CRegle::~CRegle()
{
    bodyPlus.clear();
    bodyMinus.clear();
}

void CRegle::SetHead(int nNewHead)
{
    this->nHead = nNewHead;
}
        
int CRegle::GetHead()
{
    return this->nHead;
}

void CRegle::AddBodyPlusEntry(int newEntry)
{
    bodyPlus.insert(newEntry);
}
        
void CRegle::AddBodyMinusEntry(int newEntry)
{
    bodyMinus.insert(newEntry);
}

void CRegle::WriteInformation()
{
    cout << "Head : " << nHead << endl;
    cout << "BodyPlus : ";
    copy(bodyPlus.begin(), bodyPlus.end(), ostream_iterator<int>(cout, " - "));
    cout << "BodyMinus : ";
    copy(bodyMinus.begin(), bodyMinus.end(), ostream_iterator<int>(cout, " - "));
    cout << endl;
}


CSetAtom CRegle::GetBodyPlus()
{
	return this->bodyPlus;
}

CSetAtom CRegle::GetBodyMinus()
{
	return this->bodyMinus;
}


/* CReglePos class method definition */

CReglePos::CReglePos() : CRegle()
{}

CReglePos::~CReglePos() {};

void CReglePos::SetDegree(int nNewDegree)
{
    this->nDegree = nNewDegree;
}
        
int CReglePos::GetDegree()
{
    return this->nDegree;
}

void CReglePos::WriteInformationPos()
{
    CRegle : WriteInformation();
    cout << "Degree : " << nDegree << "\n" << endl;
}

/* CProgLog class methods definitions */
CProgLog::CProgLog() {}
CProgLog::~CProgLog()
{
    // Destruction of the two lists
    int sizeVector = m_vSetOfRegle.size();
    for (int i = 0; i < sizeVector; i++)
    {
        delete (m_vSetOfRegle[i]);
    }

    sizeVector = m_vDictionnary.size();
    for (int i = 0; i < sizeVector; i++)
    {
        free(m_vDictionnary[i]);
    }

    m_vSetOfRegle.clear();
    m_vDictionnary.clear();
}

void CProgLog::AddRegle(CRegle* pRegle)
{
    m_vSetOfRegle.push_back(pRegle);
}
        
int CProgLog::AddDictionnaryEntry(char* newEntry)
{
    int place = FindPlaceInDictionnary(newEntry);

    if (place == -1)
    {
        char* strCopy;
        strCopy = (char*) malloc(sizeof(char)*strlen(newEntry)+1);
        strcpy(strCopy, newEntry);

        m_vDictionnary.push_back(strCopy);

        return (m_vDictionnary.size()-1);
    }

    return place;
}
        
void CProgLog::WriteInformation()
{
    this->WriteDictionnary();

    cout << "\n\nRULES :\n" << endl;

    int sizeVector = m_vSetOfRegle.size();
    for (int i = 0; i < sizeVector; i++)
    {
        m_vSetOfRegle[i]->WriteInformation();
        cout << "\n" << endl;
    }
}

void CProgLog::WriteDictionnary()
{
    cout << "\n\nDICTIONNARY :\n";

    int sizeVector = m_vDictionnary.size();
    for (int i = 0; i < sizeVector; i++)
    {
        cout << i << " - " << m_vDictionnary[i] << "\n";
    }

    cout << endl;
}

int CProgLog::FindPlaceInDictionnary(char* str)
{
    int sizeVector = m_vDictionnary.size();
    for (int i = 0; i < sizeVector; i++)
    {
        if (strcmp(m_vDictionnary[i], str) == 0)
            return i;
    }

    return -1;
}

vector<CRegle*> CProgLog::GetAllLogicRules()
{
	return this->m_vSetOfRegle;
}

char* CProgLog::GetDictionnaryEntry(int nPlace)
{
	return this->m_vDictionnary[nPlace];
}

/* CProgLogPos class methods definitions */
CProgLogPos::CProgLogPos() : CProgLog()
{}

CProgLogPos::~CProgLogPos()
{
    int sizeVector = m_vSetOfRegle.size();
    for (int i = 0; i < sizeVector; i++)
    {
        delete (m_vSetOfRegle[i]);
    }

    m_vSetOfRegle.clear();
}

void CProgLogPos::AddRegle(CReglePos* pRegle)
{
    m_vSetOfRegle.push_back(pRegle);
}

void CProgLogPos::WriteInformation()
{
    WriteDictionnary();

	cout << "\nRULES :\n" << endl;
        
    int sizeVector = m_vSetOfRegle.size();
    for (int i = 0; i < sizeVector; i++)
    {
        m_vSetOfRegle[i]->WriteInformationPos();
        cout << endl;
    }
}

vector<CRegle*> CProgLogPos::GetAllLogicRules()
{
    vector<CRegle*> vectReturn;
    vector<CReglePos*>::iterator iter = m_vSetOfRegle.begin();

    for (; iter != m_vSetOfRegle.end(); iter++)
    {
	vectReturn.push_back((CRegle*) *iter);
    }

    return vectReturn;
}

vector<CReglePos*> CProgLogPos::GetAllPossibilistRules()
{
  return m_vSetOfRegle;
}

⌨️ 快捷键说明

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