论文查重-第一次个人编程

发布时间 2023-09-20 20:32:39作者: lanzeye

1、github链接:https://github.com/lanzeye7/lanzeye7

2、PSP表格

PSP2.1

Personal Software Process Stages

预估耗时(分钟)

实际耗时(分钟)

Planning

计划

 60

 85

· Estimate

· 估计这个任务需要多少时间

 180

 210

Development

开发

 50

 45

· Analysis

· 需求分析 (包括学习新技术)

 30

 20

· Design Spec

· 生成设计文档

20

10

· Design Review

· 设计复审

 20

 10

· Coding Standard

· 代码规范 (为目前的开发制定合适的规范)

 45

 50

· Design

· 具体设计

 30

 30

· Coding

· 具体编码

 30

 25

· Code Review

· 代码复审

 25

 20

· Test

· 测试(自我测试,修改代码,提交修改)

 30

 28

Reporting

报告

 45

 30

· Test Repor

· 测试报告

 20

 10

· Size Measurement

· 计算工作量

 345

 278

· Postmortem & Process Improvement Plan

· 事后总结, 并提出过程改进计划

 做作业别玩手机

 好好做,多查文献

 

· 合计

 

 

 

3、代码

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

map<string, int> calculate_word_frequency(const string& content) {
map<string, int> frequency;
istringstream iss(content);
string word;

while (iss >> word) {
frequency[word]++;
}

return frequency;
}

double calculate_dot_product(const map<string, int>& vector1, const map<string, int>& vector2) {
double dotProduct = 0;

for (const auto& pair : vector1) {
dotProduct += pair.second * vector2.at(pair.first);
}

return dotProduct;
}

double calculate_magnitude(const map<string, int>& vector) {
double magnitude = 0;

for (const auto& pair : vector) {
magnitude += pow(pair.second, 2);
}

return sqrt(magnitude);
}

double calculate_cosine_similarity(const string& file1, const string& file2) {
ifstream ifs1(file1);
ifstream ifs2(file2);
stringstream ss1, ss2;
ss1 << ifs1.rdbuf();
ss2 << ifs2.rdbuf();
ifs1.close();
ifs2.close();

string content1 = ss1.str();
string content2 = ss2.str();

map<string, int> vector1 = calculate_word_frequency(content1);
map<string, int> vector2 = calculate_word_frequency(content2);

double dotProduct = calculate_dot_product(vector1, vector2);
double magnitude1 = calculate_magnitude(vector1);
double magnitude2 = calculate_magnitude(vector2);

return dotProduct / (magnitude1 * magnitude2);
}

void write_result_to_file(const string& file, double similarity) {
ofstream ofs(file);
ofs << "重复率: " << similarity << endl;
ofs.close();
}

int main() {
string file1 = "path/to/file1.txt";
string file2 = "path/to/file2.txt";
string resultFile = "path/to/result.txt";

double similarity = calculate_cosine_similarity(file1, file2);
write_result_to_file(resultFile, similarity);

cout << "重复率计算完成!" << endl;

return 0;
}

4、结果