Результаты экзаменационной сессии студентов представлены в таблице, создать файл, содержащий данные этой таблицы и выводящий таблицу студентов(их данные), получивших из программирования оценки более 3 в С++
#include
#include
#include
using namespace std;
struct grade {
int math, algebra, programming, os;
};
struct student {
string FIO;
grade grades {0, 0, 0, 0};
};
void writeStrip(int count) {
for (int i = 0; i < count; i++)
cout << "-";
cout << endl;
}
void printAllStudents(student *students, int size) {
int fioWidth = 20;
int gradesWidth = 10;
writeStrip(fioWidth + gradesWidth * 4);
cout
<< setw(fioWidth) << "FIO|"
<< setw(gradesWidth) << "Math|"
<< setw(gradesWidth) << "Algebra|"
<< setw(gradesWidth) << "Programming|"
<< setw(gradesWidth) << "OS|"
<< endl;
writeStrip(fioWidth + gradesWidth * 4);
fioWidth--; gradesWidth--;
for (size_t i = 0; i < size; i++)
{
cout
<< setw(fioWidth) << students[i].FIO << "|"
<< setw(gradesWidth) << students[i].grades.math << "|"
<< setw(gradesWidth) << students[i].grades.algebra << "|"
<< setw(gradesWidth) << students[i].grades.programming << "|"
<< setw(gradesWidth) << students[i].grades.os << "|"
<< endl;
}
fioWidth++; gradesWidth++;
writeStrip(fioWidth + gradesWidth * 4);
}
void printStudentsWithGoodProgramming(student* students, int size) {
int cutSize = 0;
for (size_t i = 0; i < size; i++)
if (students[i].grades.programming > 3)
cutSize++;
student* cutStudents = new student[cutSize];
for (size_t i = 0; i < cutSize; i++)
cutStudents[i] = student();
for (size_t i = 0, j = 0; i < size; i++)
{
if (students[i].grades.programming < 4)
continue;
cutStudents[j] = students[i];
j++;
}
printAllStudents(cutStudents, cutSize);
cout << "Number: " << cutSize;

delete[] cutStudents;
}
int main() {

cout << "Number of students: ";
int size = 1;
do {
if (size < 1 || size > 100)
cout << "Incorrect number of students: ";
cin >> size;
} while (size < 1 || size > 100);
student* students = new student[size];
for (size_t i = 0; i < size; i++) {
cout << "FIO " << (i + 1) << " student: ";
cin.ignore();
getline(cin, students[i].FIO);
cout << "Enter math grade: ";
cin >> students[i].grades.math;
cout << "Enter physics grade: ";
cin >> students[i].grades.algebra;
cout << "Enter programming grade: ";
cin >> students[i].grades.programming;
cout << "Enter os grade: ";
cin >> students[i].grades.os;
}
cout << "Table of all students:" << endl;
printAllStudents(students, size);
cout << "The table of students who have a grade more than 3 in programming:" << endl;
printStudentsWithGoodProgramming(students, size);
delete[] students;
return 0;
}
Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Copyright © 2024 SCHOLAR.TIPS - All rights reserved.