#include #include using namespace std;

// 定义错题信息结构体 struct WrongQuestion { string question; string errorInfo; string answerAnalysis; string learningExperience; string source; string reason; string difficulty; string type; string knowledgePoint; WrongQuestion* next; };

// 全局变量:头指针和尾指针 WrongQuestion* head = nullptr; WrongQuestion* tail = nullptr;

// 函数声明 void addWrongQuestion(); void displayWrongQuestion(); void queryWrongQuestion(); void modifyWrongQuestion(); void deleteWrongQuestion(); void importFromFile(); void exportToFile();

int main() { 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 << "8 退出" << endl; cout << "请选择功能:"; cin >> choice;

    switch(choice) {
        case 1:
            addWrongQuestion();
            break;
        case 2:
            displayWrongQuestion();
            break;
        case 3:
            queryWrongQuestion();
            break;
        case 4:
            modifyWrongQuestion();
            break;
        case 5:
            deleteWrongQuestion();
            break;
        case 6:
            importFromFile();
            break;
        case 7:
            exportToFile();
            break;
        case 8:
            return 0;
        default:
            cout << "请选择正确的功能!" << endl;
    }
}

}

void addWrongQuestion() { WrongQuestion* newQuestion = new WrongQuestion; cout << "请输入题目:"; cin.ignore(); getline(cin, newQuestion->question); // 输入其他错题信息 newQuestion->next = nullptr; if (head == nullptr) { head = newQuestion; tail = newQuestion; } else { tail->next = newQuestion; tail = newQuestion; } }

void displayWrongQuestion() { WrongQuestion* current = head; int count = 1; while (current != nullptr) { cout << "第" << count << "题" << endl; cout << "题目:" << current->question << endl; // 显示其他错题信息 current = current->next; count++; } }

void queryWrongQuestion() { int queryChoice; string keyword; cout << "请选择查询方式:" << endl; cout << "1 按知识点查询" << endl; cout << "2 按题目类型查询" << endl; cout << "请选择:"; cin >> queryChoice; cout << "请输入关键词:"; cin.ignore(); getline(cin, keyword);

WrongQuestion* current = head;
int count = 1;
while (current != nullptr) {
    if ((queryChoice == 1 && current->knowledgePoint == keyword) || (queryChoice == 2 && current->type == keyword)) {
        cout << "第" << count << "题" << endl;
        cout << "题目:" << current->question << endl;
        // 显示其他错题信息
        count++;
    }
    current = current->next;
}

}

void modifyWrongQuestion() { string keyword; cout << "请输入要修改的题目关键词:"; cin.ignore(); getline(cin, keyword);

WrongQuestion* current = head;
int count = 1;
while (current != nullptr) {
    if (current->question == keyword) {
        cout << "第" << count << "题" << endl;
        cout << "请输入修改后的题目:";
        getline(cin, current->question);
        // 输入其他修改后的错题信息
        cout << "修改成功!" << endl;
        return;
    }
    current = current->next;
    count++;
}
cout << "未找到匹配的题目!" << endl;

}

void deleteWrongQuestion() { string keyword; cout << "请输入要删除的题目关键词:"; cin.ignore(); getline(cin, keyword);

WrongQuestion* current = head;
WrongQuestion* previous = nullptr;
int count = 1;
while (current != nullptr) {
    if (current->question == keyword) {
        cout << "第" << count << "题" << endl;
        if (previous == nullptr) {
            head = current->next;
        } else {
            previous->next = current->next;
        }
        delete current;
        cout << "删除成功!" << endl;
        return;
    }
    previous = current;
    current = current->next;
    count++;
}
cout << "未找到匹配的题目!" << endl;

}

void importFromFile() { ifstream inputFile("wrong_questions.txt"); if (!inputFile) { cout << "文件打开失败!" << endl; return; }

string question;
while (getline(inputFile, question)) {
    WrongQuestion* newQuestion = new WrongQuestion;
    newQuestion->question = question;
    // 从文件中读取其他错题信息
    newQuestion->next = nullptr;
    if (head == nullptr) {
        head = newQuestion;
        tail = newQuestion;
    } else {
        tail->next = newQuestion;
        tail = newQuestion;
    }
}

inputFile.close();
cout << "导入成功!" << endl;

}

void exportToFile() { ofstream outputFile("wrong_questions.txt"); if (!outputFile) { cout << "文件打开失败!" << endl; return; }

WrongQuestion* current = head;
int count = 1;
while (current != nullptr) {
    outputFile << "第" << count << "题" << endl;
    outputFile << "题目:" << current->question << endl;
    // 将其他错题信息输出到文件中
    current = current->next;
    count++;
}

outputFile.close();
cout << "导出成功!" << endl;
题目要求错题本管理程序:利用链表实现错题本管理程序。其中错题信息包括题目、错误信息、答案分析、心得体会、错题来源、错题原因、难易程度、题目类型、知识点等多项信息。具体实现的管理功能如下:1 输入并显示错题的信息;2 可实现错题信息的添加;3 查询至少提供按知识点和题目类型两种方式;4 修改提供查询后进行修改;5 删除依据指定的信息知识点和题目类型查找后删除错题;6文件的导入和导出从文件中读取若干条

原文地址: https://www.cveoy.top/t/topic/iTBn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录