Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- const int MAX_STUDENTS = 100;
- const int MAX_COURSE_PLANS = 100;
- const int MAX_PERFORMANCES = 100;
- struct Student {
- string fio;
- string recordBookNumber;
- string group;
- int course;
- bool socialScholarship;
- Student() : fio(""), recordBookNumber(""), group(""), course(0), socialScholarship(false) {}
- Student(string f, string r, string g, int c, bool s)
- : fio(f), recordBookNumber(r), group(g), course(c), socialScholarship(s) {}
- };
- struct CoursePlan {
- string subject;
- int hours;
- int semester;
- string formOfControl;
- CoursePlan() : subject(""), hours(0), semester(0), formOfControl("") {}
- CoursePlan(string sub, int h, int sem, string form)
- : subject(sub), hours(h), semester(sem), formOfControl(form) {}
- };
- struct Performance {
- string studentRecordBookNumber;
- string subject;
- int grade;
- Performance() : studentRecordBookNumber(""), subject(""), grade(0) {}
- Performance(string srb, string sub, int g)
- : studentRecordBookNumber(srb), subject(sub), grade(g) {}
- };
- class Deanery {
- private:
- Student students[MAX_STUDENTS];
- int studentCount;
- CoursePlan coursePlans[MAX_COURSE_PLANS];
- int coursePlanCount;
- Performance performances[MAX_PERFORMANCES];
- int performanceCount;
- public:
- Deanery() : studentCount(0), coursePlanCount(0), performanceCount(0) {}
- void loadStudents(const string &filename) {
- ifstream inFile(filename);
- if (inFile.is_open()) {
- while (inFile >> students[studentCount].fio
- >> students[studentCount].recordBookNumber
- >> students[studentCount].group
- >> students[studentCount].course
- >> students[studentCount].socialScholarship) {
- studentCount++;
- }
- inFile.close();
- } else {
- cerr << "Error opening file: " << filename << endl;
- }
- }
- void loadCoursePlans(const string &filename) {
- ifstream inFile(filename);
- if (inFile.is_open()) {
- while (inFile >> coursePlans[coursePlanCount].subject
- >> coursePlans[coursePlanCount].hours
- >> coursePlans[coursePlanCount].semester
- >> coursePlans[coursePlanCount].formOfControl) {
- coursePlanCount++;
- }
- inFile.close();
- } else {
- cerr << "Error opening file: " << filename << endl;
- }
- }
- void savePerformance(const string &filename) {
- ofstream outFile(filename);
- if (outFile.is_open()) {
- for (int i = 0; i < performanceCount; ++i) {
- outFile << performances[i].studentRecordBookNumber << " "
- << performances[i].subject << " "
- << performances[i].grade << endl;
- }
- outFile.close();
- } else {
- cerr << "Error opening file: " << filename << endl;
- }
- }
- void updateStudentFile(const string &filename) {
- ofstream outFile(filename);
- if (outFile.is_open()) {
- for (int i = 0; i < studentCount; ++i) {
- outFile << students[i].fio << " "
- << students[i].recordBookNumber << " "
- << students[i].group << " "
- << students[i].course << " "
- << students[i].socialScholarship << endl;
- }
- outFile.close();
- } else {
- cerr << "Error opening file: " << filename << endl;
- }
- }
- void updateCoursePlanFile(const string &filename) {
- ofstream outFile(filename);
- if (outFile.is_open()) {
- for (int i = 0; i < coursePlanCount; ++i) {
- outFile << coursePlans[i].subject << " "
- << coursePlans[i].hours << " "
- << coursePlans[i].semester << " "
- << coursePlans[i].formOfControl << endl;
- }
- outFile.close();
- } else {
- cerr << "Error opening file: " << filename << endl;
- }
- }
- void selectStudentsByGroup(const string &group) {
- for (int i = 0; i < studentCount; ++i) {
- if (students[i].group == group) {
- cout << students[i].fio << " "
- << students[i].recordBookNumber << " "
- << students[i].group << " "
- << students[i].course << " "
- << students[i].socialScholarship << endl;
- }
- }
- }
- void listFailingStudents() {
- for (int i = 0; i < studentCount; ++i) {
- bool failing = false;
- for (int j = 0; j < performanceCount; ++j) {
- if (performances[j].studentRecordBookNumber == students[i].recordBookNumber && performances[j].grade < 3) {
- failing = true;
- break;
- }
- }
- if (failing) {
- cout << students[i].fio << " " << students[i].recordBookNumber << endl;
- }
- }
- }
- void promoteStudents() {
- for (int i = 0; i < studentCount; ++i) {
- bool passing = true;
- for (int j = 0; j < performanceCount; ++j) {
- if (performances[j].studentRecordBookNumber == students[i].recordBookNumber && performances[j].grade < 3) {
- passing = false;
- break;
- }
- }
- if (passing) {
- students[i].course++;
- }
- }
- }
- void assignScholarships() {
- for (int i = 0; i < studentCount; ++i) {
- bool eligible = true;
- for (int j = 0; j < performanceCount; ++j) {
- if (performances[j].studentRecordBookNumber == students[i].recordBookNumber && performances[j].grade < 4) {
- eligible = false;
- break;
- }
- }
- if (eligible) {
- cout << "Scholarship assigned to: " << students[i].fio << endl;
- }
- }
- }
- void addPerformance(const string &recordBookNumber, const string &subject, int grade) {
- if (performanceCount < MAX_PERFORMANCES) {
- performances[performanceCount++] = Performance(recordBookNumber, subject, grade);
- } else {
- cerr << "Performance array is full" << endl;
- }
- }
- };
- int main() {
- Deanery deanery;
- // Загрузка данных студентов и учебных планов
- deanery.loadStudents("students.txt");
- deanery.loadCoursePlans("course_plans.txt");
- // Заполняем файл успеваемости студентов (пример)
- deanery.addPerformance("12345", "Math", 5);
- deanery.addPerformance("12345", "Physics", 4);
- deanery.addPerformance("67890", "Math", 2);
- deanery.addPerformance("67890", "Physics", 3);
- // Сохраняем успеваемость студентов
- deanery.savePerformance("performance.txt");
- // Вносим изменения в файлы
- deanery.updateStudentFile("students.txt");
- deanery.updateCoursePlanFile("course_plans.txt");
- // Делаем выборку по группе
- cout << "Students in group 'A1':" << endl;
- deanery.selectStudentsByGroup("A1");
- // Выводим неуспевающих студентов
- cout << "Failing students:" << endl;
- deanery.listFailingStudents();
- // Переводим студентов на следующий курс
- deanery.promoteStudents();
- deanery.updateStudentFile("students.txt");
- // Назначаем стипендию
- deanery.assignScholarships();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment