Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <Windows.h>
- #include <fstream>
- #include <sstream>
- using namespace std;
- struct Student
- {
- string name;
- int mark[4];
- };
- void PrintStudent(Student std);
- void PrintTable(Student stds[], int size);
- Student BestStudent(Student stds[], int size);
- void SaveData(Student stds[], int size);
- void LoadData(Student stds[], int size);
- int main()
- {
- int size = 4;
- Student* stds = new Student[size];
- SaveData(stds, size);
- LoadData(stds, size);
- cout << setw(11) << "# " << setw(15) << "Full name" << setw(13) << " Math " << setw(12) << "Programming" << setw(8) << " OS " << setw(13) << "Algebra &" << endl;
- cout << setw(10) << " " << setw(16) << " " << setw(13) << " " << setw(12) << " " << setw(8) << " " << setw(13) << "Geometry" << endl;
- cout << " _______________________________________________________________" << endl;
- PrintTable(stds, size);
- BestStudent(stds, size);
- delete[]stds;
- }
- void PrintStudent(Student std)
- {
- string name = "";
- for (auto c : std.name)
- {
- if (c == '_') {
- c = ' ';
- }
- name += c;
- }
- cout << setw(15) << name << setw(8);
- for (int i = 0; i < 4; i++)
- {
- cout << std.mark[i] << setw(11);
- }
- cout << endl;
- }
- void PrintTable(Student stds[], int size)
- {
- for (int i = 0; i < size; i++)
- {
- cout << setw(10) << i + 1 << ". ";
- PrintStudent(stds[i]);
- }
- }
- void SaveData(Student stds[], int size) {
- Student std = { "Ivanchuk_S.O", {4,5,3,4} };
- Student std_1 = { "Panachenko_I.A", {5,4,4,5} };
- Student std_2 = { "Zayec_I.M", {3,4,4,4} };
- Student std_3 = { "Kravchenko_I.I",{3,5,4,5} };
- stds[0] = std;
- stds[1] = std_1;
- stds[2] = std_2;
- stds[3] = std_3;
- ofstream outfile("Out.txt");
- for (int i = 0; i < size; ++i){
- outfile << stds[i].name << " " ;
- for (int j = 0; j < 4; ++j) {
- outfile << stds[i].mark[j] << " ";
- }
- outfile << endl;
- }
- outfile.close();
- }
- void LoadData(Student stds[], int size) {
- ifstream inputFile("Out.txt");
- if (!inputFile.is_open())
- {
- cout << "Помилка відкриття файлу!" << endl;
- }
- for (int i = 0; i < size; i++)
- {
- inputFile >> stds[i].name;
- for (int j = 0; j < 4; j++)
- {
- inputFile >> stds[i].mark[j];
- }
- }
- inputFile.close();
- }
- Student BestStudent(Student stds[], int size)
- {
- Student best = stds[0];
- for (int i = 0; i < size; i++)
- {
- if (stds[i].mark[1] > best.mark[1])
- {
- best = stds[i];
- }
- }
- cout << "Best Student: " << endl;
- for (int i = 0; i < size; i++)
- {
- if (stds[i].mark[1] == best.mark[1])
- {
- cout << stds[i].name << endl;
- }
- }
- return best;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement