diff --git a/成绩管理.cpp b/成绩管理.cpp new file mode 100644 index 0000000..97e77a9 --- /dev/null +++ b/成绩管理.cpp @@ -0,0 +1,87 @@ +#include +#include +#include + +using namespace std; + +struct Student { + string name; + int score; +}; + +const int MAX_STUDENTS = 100; +Student students[MAX_STUDENTS]; +int numStudents = 0; + +void saveDataToFile() { + ofstream file("student_data.txt"); + if (file.is_open()) { + for (int i = 0; i < numStudents; i++) { + file << students[i].name << " " << students[i].score << endl; + } + file.close(); + } +} + +void loadDataFromFile() { + ifstream file("student_data.txt"); + if (file.is_open()) { + while (!file.eof()) { + file >> students[numStudents].name >> students[numStudents].score; + numStudents++; + } + file.close(); + } +} + +void inputData() { + // 实现录入数据的功能 +} + +void modifyData() { + // 实现修改数据的功能 +} + +void viewData() { + // 实现查看数据的功能 +} + +void displayMenu() { + cout << "1. 数据录入" << endl; + cout << "2. 数据修改/删除" << endl; + cout << "3. 统计查看" << endl; + cout << "4. 退出系统" << endl; +} + +int main() { + char choice; + cout << "是否读取文件?(Y/N): "; + cin >> choice; + if (choice == 'Y' || choice == 'y') { + loadDataFromFile(); + } + + do { + displayMenu(); + cout << "请选择功能:"; + cin >> choice; + switch (choice) { + case '1': + inputData(); + break; + case '2': + modifyData(); + break; + case '3': + viewData(); + break; + case '4': + saveDataToFile(); + break; + default: + cout << "无效的选项" << endl; + } + } while (choice != '4'); + + return 0; +}