软工作业2
作业介绍
这个作业属于哪个课程 | 软件工程 https://edu.cnblogs.com/campus/gdgy/SoftwareEngineeringClassof2023 | |
---|---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/gdgy/SoftwareEngineeringClassof2023/homework/13324 | |
这个作业的目标 | 文本查重并测试,性能分析 | |
github | https://github.com/wzx8888/work/tree/main/Project14 |
psp
PSP | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 150 | 200 |
· Estimate | 估计这个任务需要多少时间 | 200 | 400 |
Development | 开发 | 300 | 455 |
· Analysis | 需求分析 (包括学习新技术) | 120 | 300 |
· Design Spec | 生成设计文档 | 20 | 45 |
· Design Review | 设计复审 | 30 | 30 |
· Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 10 | 10 |
· Design | 具体设计 | 30 | 30 |
· Coding | 具体编码 | 120 | 90 |
· Code Review | 代码复审 | 30 | 40 |
· Test | 测试(自我测试,修改代码,提交修改) | 60 | 150 |
Reporting | 报告 | 80 | 285 |
· Test Report | 测试报告 | ||
· Size Measurement | 计算工作量 | 20 | 40 |
· Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 50 | 125 |
Total | 合计 |
计算模块设计与实现
设计概述
类结构
TextProcessor
类:负责文本清洗和分词。SimilarityCalculator
类:负责相似度计算。ExampleManager
类:管理示例数据集,调用其他类来处理并展示结果。
函数设计
cleanText
: 清洗文本,去除标点符号并转换为小写。splitToWords
: 将清洗后的文本分割成单词集合。calculateJaccardSimilarity
: 计算两个集合之间的Jaccard相似度。processAndPrintSimilarity
: 处理并打印相似度结果。
性能改进
1,改进思路
2,减少内存分配。
3,优化字符串操作。
4,使用更高效的容器(如unordered_set)。
误场景说明
-空输入异常: 当用户未提供任何输入文本时,系统应提示用户输入有效的文本。
-文件读取异常: 当指定的文件路径不存在或无法访问时,系统应提示用户检查文件路径并重试。
-无效参数异常: 当传递给函数的参数不符合预期格式时,系统应提示用户修正参数。
算法例子模块
算法运行效果图
异常处理说明
·异常设计目标
·空输入异常。
·文件读取异常。
·无效参数异常。
·异常处理样例
void processAndPrintSimilarity(const std::string& origContent, const std::string& plagContent) {
if (origContent.empty() || plagContent.empty()) {
throw std::invalid_argument("Input texts cannot be empty.");
}
// 其他逻辑...
}
单元测试
1,在用c++进行单元测试时,一直出错,cmake运用不成熟,故没有单独写,而是放在main函数里运行
2,用的VS自身的单元测试,但一直出现编译错误,按照网上教程也无法解决问题