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

📄 cpd.h

📁 这个程序主要是实现检查是否抄袭作业
💻 H
字号:
#ifndef CPD_H
#define CPD_H
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include <cstdlib>

using namespace std;

// Debugging block
#define EBUG
#ifdef DEBUG

#define DEBUGFUNCTION
#define _DEBUG_Evl_Chunk
#define _DEBUG_Ins_Chunk
#define DEBUG_Evaluate
#define _DEBUG_Compare
#define _DEBUG_Suck
#define _DEBUG_Insert

#endif

//! Node in the hash table
/*! Which is really a node in the hash table */
typedef struct NodeInTheHashTable{
    //!< The string indicated by FileBlock
    int HashKey;
    //!< The start point of the block in FileName 
    int StartPoint;
    //!< The length of the block
    unsigned int Length;
    //!< The name of file
    string FileName;
    //!< A pointer to next element in the hash chain
    NodeInTheHashTable *Next;
}FileBlock;

//! The max slots of the hash table
const unsigned long MAX= 10009;

//! The path of the repository
const string REPOSITORYPATH= "./Repository/";

//! The cut char in size of 2
const string DoubleCutChar(" ,。.-!? ");

//! The cut char in size of 1
const string SingleCutChar(" []{}()<>,.!?\n");

//! The main class of the project.
/*! Which is easily used by invoking two member functions */
class HawkEye{
    public:
	HawkEye();
	~HawkEye();
	void CheckIn(string FileName);
	void Exam(string FileName);
	void CleanUpHashTalbe();
	void SetHashTable(string filename);
	void SetStringSizeTreshold(int threshold);
	void RebuildHashTable();
	// Load Hash Table from a File
	void LoadHashTable();

    private:
	string GetSuffix(string AbsPath);
	string GetFileName(string AbsPath);

	//! Longest Common Subsequence
	int LCS(string str1, string str2);

	//! Loop counter
	unsigned int i, j;

	//! The least similarity of two strings be judged as a violation in per cent
	int LCS_Treshold;

	//! The least string length in byte
	unsigned int String_Size_Treshold;

	//! Used in Process() and destructor
	string OutputMessage;

	//! The modes of process()
	enum ProcessMode{ CONCATENATE, PRINT };

	//! The file name of the hash table
	string m_HashTableName;

	//! Debugging function.
	void OutputFileBlock(FileBlock *fbp);

	// Suck string from a FileBlock
	string Suck(FileBlock *fbp);

	// Delete all Carriage Return(i.e. Enter) in file
	bool ReturnKiller(string inFileName, string outFileName);

	// Check a string if it violated to repository
	// This function repeatly invokes Evaluate() until all the chunks has been checked
	void Evaluate(string Str);

	// Process violation
	void Process(string str, ProcessMode pm);

	// Save Hash Table to a File
	void SaveHashTable();

	// Hash Table to hold registered document data
	FileBlock *HashTable[MAX];

	// Compare two string
	bool Compare(string StrA, string StrB);

	// Insert a FileBlock into the hash list
	void Insert(FileBlock *ToBeLinked);

	// Chunk file to be inserted, i.e, insertion for registered files
	// This function repeatly invokes Insert() until all the chunks has been inserted
	void Ins_Chunk(string FileName);

	// Chunk file to be examined, i.e, insertion for student's files
	void Evl_Chunk(string FileName);

	// Get the hash key of a string
	long Hash(string str);
};

#endif

⌨️ 快捷键说明

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