C++ 链表实现错题本管理系统 - 轻松管理你的学习错误
使用 C++ 链表实现的错题本管理系统,帮助你高效整理学习中的错误。该系统支持以下功能:
- 添加错题信息:输入题目、错误信息、答案分析、心得体会、错题来源、错题原因、难易程度、题目类型、知识点等信息,将错题添加到错题本中。
- 浏览错题信息:显示所有错题信息,方便你回顾和学习。
- 查询错题信息:支持按知识点和题目类型两种方式查询错题,快速找到你需要的信息。
- 修改错题信息:对已有的错题信息进行修改,更新你的学习记录。
- 删除错题信息:根据指定的信息(知识点和题目类型)删除错题,清理不必要的记录。
- 文件导入和导出:从文件中读取若干条错题信息,或者将错题信息输出到文件中,方便你备份和迁移数据。
此外,该系统还考虑了以下细节:
- 标签分类管理: 通过标签对错题进行分类管理,提高操作效率。
- 选择操作: 当查找结果存在多条记录时,提供选择操作,方便你选择需要修改或删除的记录。
程序菜单:
错题本管理程序
1 添加错题信息
2 浏览错题信息
3 查询错题信息
4 删除错题信息
5 文件导入
6 文件导出
7 退出
请选择功能:
示例代码:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
// 定义错题的结构体
struct Mistake {
string question;
string mistakeInfo;
string answerAnalysis;
string experience;
string source;
string reason;
string difficulty;
string type;
string knowledgePoint;
};
// 定义链表节点
struct Node {
Mistake data;
Node* next;
};
// 添加错题信息
void addMistake(Node*& head) {
Mistake mistake;
cout << "请输入题目:";
getline(cin, mistake.question);
cout << "请输入错误信息:";
getline(cin, mistake.mistakeInfo);
cout << "请输入答案分析:";
getline(cin, mistake.answerAnalysis);
cout << "请输入心得体会:";
getline(cin, mistake.experience);
cout << "请输入错题来源:";
getline(cin, mistake.source);
cout << "请输入错题原因:";
getline(cin, mistake.reason);
cout << "请输入难易程度:";
getline(cin, mistake.difficulty);
cout << "请输入题目类型:";
getline(cin, mistake.type);
cout << "请输入知识点:";
getline(cin, mistake.knowledgePoint);
Node* newNode = new Node;
newNode->data = mistake;
newNode->next = nullptr;
if (head == nullptr) {
head = newNode;
} else {
Node* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = newNode;
}
cout << "错题信息添加成功!" << endl;
}
// 显示所有错题信息
void displayMistakes(Node* head) {
if (head == nullptr) {
cout << "没有任何错题信息!" << endl;
return;
}
Node* current = head;
while (current != nullptr) {
Mistake mistake = current->data;
cout << "题目:" << mistake.question << endl;
cout << "错误信息:" << mistake.mistakeInfo << endl;
cout << "答案分析:" << mistake.answerAnalysis << endl;
cout << "心得体会:" << mistake.experience << endl;
cout << "错题来源:" << mistake.source << endl;
cout << "错题原因:" << mistake.reason << endl;
cout << "难易程度:" << mistake.difficulty << endl;
cout << "题目类型:" << mistake.type << endl;
cout << "知识点:" << mistake.knowledgePoint << endl;
cout << "-------------------------" << endl;
current = current->next;
}
}
// 查询错题信息
void searchMistakes(Node* head) {
if (head == nullptr) {
cout << "没有任何错题信息!" << endl;
return;
}
string keyword;
cout << "请输入要查询的关键字:";
getline(cin, keyword);
Node* current = head;
int count = 0;
while (current != nullptr) {
Mistake mistake = current->data;
if (mistake.knowledgePoint == keyword || mistake.type == keyword) {
cout << "题目:" << mistake.question << endl;
cout << "错误信息:" << mistake.mistakeInfo << endl;
cout << "答案分析:" << mistake.answerAnalysis << endl;
cout << "心得体会:" << mistake.experience << endl;
cout << "错题来源:" << mistake.source << endl;
cout << "错题原因:" << mistake.reason << endl;
cout << "难易程度:" << mistake.difficulty << endl;
cout << "题目类型:" << mistake.type << endl;
cout << "知识点:" << mistake.knowledgePoint << endl;
cout << "-------------------------" << endl;
count++;
}
current = current->next;
}
if (count == 0) {
cout << "没有找到相关错题信息!" << endl;
}
}
// 修改错题信息
void modifyMistake(Node* head) {
if (head == nullptr) {
cout << "没有任何错题信息!" << endl;
return;
}
string keyword;
cout << "请输入要修改的关键字:";
getline(cin, keyword);
Node* current = head;
vector<Node*> matches;
while (current != nullptr) {
Mistake mistake = current->data;
if (mistake.knowledgePoint == keyword || mistake.type == keyword) {
matches.push_back(current);
}
current = current->next;
}
if (matches.empty()) {
cout << "没有找到相关错题信息!" << endl;
return;
}
cout << "找到以下匹配的错题信息:" << endl;
for (int i = 0; i < matches.size(); i++) {
Mistake mistake = matches[i]->data;
cout << i + 1 << ". " << "题目:" << mistake.question << endl;
cout << " 错误信息:" << mistake.mistakeInfo << endl;
cout << " 答案分析:" << mistake.answerAnalysis << endl;
cout << " 心得体会:" << mistake.experience << endl;
cout << " 错题来源:" << mistake.source << endl;
cout << " 错题原因:" << mistake.reason << endl;
cout << " 难易程度:" << mistake.difficulty << endl;
cout << " 题目类型:" << mistake.type << endl;
cout << " 知识点:" << mistake.knowledgePoint << endl;
cout << "-------------------------" << endl;
}
int choice;
cout << "请选择要修改的错题序号:";
cin >> choice;
cin.ignore(); // 忽略之前的换行符
if (choice < 1 || choice > matches.size()) {
cout << "输入的序号无效!" << endl;
return;
}
Node* selectedNode = matches[choice - 1];
Mistake& selectedMistake = selectedNode->data;
cout << "请输入新的题目(原题目:" << selectedMistake.question << "):";
getline(cin, selectedMistake.question);
cout << "请输入新的错误信息(原错误信息:" << selectedMistake.mistakeInfo << "):";
getline(cin, selectedMistake.mistakeInfo);
cout << "请输入新的答案分析(原答案分析:" << selectedMistake.answerAnalysis << "):";
getline(cin, selectedMistake.answerAnalysis);
cout << "请输入新的心得体会(原心得体会:" << selectedMistake.experience << "):";
getline(cin, selectedMistake.experience);
cout << "请输入新的错题来源(原错题来源:" << selectedMistake.source << "):";
getline(cin, selectedMistake.source);
cout << "请输入新的错题原因(原错题原因:" << selectedMistake.reason << "):";
getline(cin, selectedMistake.reason);
cout << "请输入新的难易程度(原难易程度:" << selectedMistake.difficulty << "):";
getline(cin, selectedMistake.difficulty);
cout << "请输入新的题目类型(原题目类型:" << selectedMistake.type << "):";
getline(cin, selectedMistake.type);
cout << "请输入新的知识点(原知识点:" << selectedMistake.knowledgePoint << "):";
getline(cin, selectedMistake.knowledgePoint);
cout << "错题信息修改成功!" << endl;
}
// 删除错题信息
void deleteMistakes(Node*& head) {
if (head == nullptr) {
cout << "没有任何错题信息!" << endl;
return;
}
string keyword;
cout << "请输入要删除的关键字:";
getline(cin, keyword);
Node* current = head;
Node* prev = nullptr;
int count = 0;
while (current != nullptr) {
Mistake mistake = current->data;
if (mistake.knowledgePoint == keyword || mistake.type == keyword) {
if (prev == nullptr) {
head = current->next;
} else {
prev->next = current->next;
}
delete current;
count++;
} else {
prev = current;
}
current = current->next;
}
if (count == 0) {
cout << "没有找到相关错题信息!" << endl;
} else {
cout << "成功删除 " << count << " 条错题信息!" << endl;
}
}
// 文件导入
void importMistakes(Node*& head) {
string filename;
cout << "请输入要导入的文件名:";
cin >> filename;
cin.ignore(); // 忽略之前的换行符
ifstream file(filename);
if (!file.is_open()) {
cout << "无法打开文件!" << endl;
return;
}
int count = 0;
while (!file.eof()) {
Mistake mistake;
getline(file, mistake.question);
getline(file, mistake.mistakeInfo);
getline(file, mistake.answerAnalysis);
getline(file, mistake.experience);
getline(file, mistake.source);
getline(file, mistake.reason);
getline(file, mistake.difficulty);
getline(file, mistake.type);
getline(file, mistake.knowledgePoint);
Node* newNode = new Node;
newNode->data = mistake;
newNode->next = nullptr;
if (head == nullptr) {
head = newNode;
} else {
Node* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = newNode;
}
count++;
}
file.close();
cout << "成功导入 " << count << " 条错题信息!" << endl;
}
// 文件导出
void exportMistakes(Node* head) {
if (head == nullptr) {
cout << "没有任何错题信息!" << endl;
return;
}
string filename;
cout << "请输入要导出的文件名:";
cin >> filename;
cin.ignore(); // 忽略之前的换行符
ofstream file(filename);
if (!file.is_open()) {
cout << "无法打开文件!" << endl;
return;
}
Node* current = head;
while (current != nullptr) {
Mistake mistake = current->data;
file << mistake.question << endl;
file << mistake.mistakeInfo << endl;
file << mistake.answerAnalysis << endl;
file << mistake.experience << endl;
file << mistake.source << endl;
file << mistake.reason << endl;
file << mistake.difficulty << endl;
file << mistake.type << endl;
file << mistake.knowledgePoint << endl;
current = current->next;
}
file.close();
cout << "成功导出错题信息到文件!" << endl;
}
// 释放链表内存
void releaseMemory(Node*& head) {
Node* current = head;
while (current != nullptr) {
Node* temp = current;
current = current->next;
delete temp;
}
head = nullptr;
}
int main() {
Node* head = nullptr;
int choice;
while (true) {
cout << "错题本管理程序" << endl;
cout << "1 添加错题信息" << endl;
cout << "2 浏览错题信息" << endl;
cout << "3 查询错题信息" << endl;
cout << "4 删除错题信息" << endl;
cout << "5 文件导入" << endl;
cout << "6 文件导出" << endl;
cout << "7 退出" << endl;
cout << "请选择功能:";
cin >> choice;
cin.ignore(); // 忽略之前的换行符
switch (choice) {
case 1:
addMistake(head);
break;
case 2:
displayMistakes(head);
break;
case 3:
searchMistakes(head);
break;
case 4:
deleteMistakes(head);
break;
case 5:
importMistakes(head);
break;
case 6:
exportMistakes(head);
break;
case 7:
releaseMemory(head);
return 0;
default:
cout << "输入的选项无效!" << endl;
break;
}
cout << endl;
}
}
原文地址: https://www.cveoy.top/t/topic/qzA3 著作权归作者所有。请勿转载和采集!