Add 学生成绩管理系统

main
plpfeuxa7 1 year ago
parent 5136130ab7
commit 660923ccfd

@ -0,0 +1,92 @@
#include <iostream>
#include <fstream> // For file operations
const int MAX_STUDENTS = 100; // Maximum number of students
struct Student {
std::string name;
int score;
};
Student students[MAX_STUDENTS];
int num_students = 0;
void input_scores() {
// Implementation for inputting student scores
// Ensure robust input and range checking
}
void modify_delete_data() {
// Implementation for modifying or deleting student data
}
void calculate_statistics() {
// Implementation for calculating statistics like max, min, average scores
}
void save_to_file() {
std::ofstream file("student_scores.txt");
if (file.is_open()) {
for (int i = 0; i < num_students; ++i) {
file << students[i].name << "," << students[i].score << "\n";
}
file.close();
} else {
std::cerr << "Unable to save to file." << std::endl;
}
}
void load_from_file() {
std::ifstream file("student_scores.txt");
if (file.is_open()) {
num_students = 0;
std::string line;
while (std::getline(file, line)) {
std::istringstream ss(line);
std::string name;
int score;
if (std::getline(ss, name, ',') && ss >> score) {
students[num_students].name = name;
students[num_students].score = score;
num_students++;
}
}
file.close();
}
}
void display_menu() {
// Implementation for displaying menu and handling user input
}
int main() {
load_from_file(); // Load data from file on startup
bool exit_program = false;
while (!exit_program) {
display_menu();
int choice;
std::cin >> choice;
switch (choice) {
case 1:
input_scores();
break;
case 2:
modify_delete_data();
break;
case 3:
calculate_statistics();
break;
case 4:
save_to_file();
exit_program = true;
break;
default:
std::cout << "Invalid choice. Please try again." << std::endl;
break;
}
}
return 0;
}
xueshengcehngjiguanlixitong
Loading…
Cancel
Save