#include <iostream>
#include <fstream>
#include <Windows.h>
#include <cstdlib>
#include <iomanip>
#include <Conio.h>
using namespace std;
const char* file = "jurnal";
char* r(char* buf);
char a[256];
char* r(char* b)
{
CharToOem(b, a);
return a;
}
inline void eatline()
{
while (cin.get() != '\n')
continue;
}
struct Stud {
int number;
char prizv[15];
char name[15];
char batk[15];
double istor_ukr;
double informatic;
double fizika;
double matem;
double ukr_mov;
double ukr_lit;
double in_mov;
double fizra;
double biologia;
double geografiy;
double seredniy_bal;
double clas;
};
class Base {
int a, num, j, b, g;
public:
Stud ob;
void menu()
{
system("cls");
cout << "*************************************************************************************************************************************" << endl;
cout << "\n\t\t\t\t\t\tКонтроль успішності учнів ліцею №11\t\t\t\t\t\t\n" << endl;
cout << "*************************************************************************************************************************************" << endl;
cout << "\n\t\t\t\t\t\t\t 1. Перегляд" << endl;
cout << "\t\t\t\t\t\t\t 2. Ввід" << endl;
cout << "\t\t\t\t\t\t\t 3. Редагування" << endl;
cout << "\t\t\t\t\t\t\t 4. Пошук" << endl;
cout << "\t\t\t\t\t\t\t 5. Сортування" << endl;
cout << "\t\t\t\t\t\t\t 6. Видалення" << endl;
cout << "\t\t\t\t\t\t\t 7. Вихід" << endl;
a = _getch();
switch (a) {
case '1':
look();
next();
break;
case '2':
enter();
next();
break;
case '3':
redac();
next();
break;
case '4':
poshyk();
next();
break;
case '5':
sort();
next();
break;
case '6':
delet();
next();
break;
case '7':
exit(1);
break;
default:
cout << "Помилка, повторіть ввід!";
}
}
void next()
{
cout << "Для виходу в головне меню натисніть (1)" << endl;
a = _getch();
switch (b) {
case '1':
menu();
break;
case '2':
exit(1);
}
}
void provirka()
{
fstream fil;
fil.open(file, ios::out | ios::in | ios::binary);
if (!file) {
cout << " Файл не знайдений !!!" << endl;
system("pause");
}
fil.close();
}
void look()
{
system("cls");
Stud ob;
ifstream in;
in.open(file, ios::in | ios::binary);
if (!in) {
cout << "Помилка";
}
cout << "******************************************************************************************************************************************" << endl;
cout << "|№| Прізвище | Ім'я | По батькові |Матем.|Укр.мова|Укр.літ|Інформ.|Ін.мова|Укр.історія|Географія|Фізика|Біологія|Фіз-ра|Середн.бал|Клас|" << endl;
while (in.read((char*)&ob, sizeof ob))
cout << "|" << ob.number << "|" << setw(10) << ob.prizv << "|" << setw(8) << ob.name << "|"
<< setw(13) << ob.batk << "| " << setw(2) << ob.matem << " | " << setw(2) << ob.ukr_mov << " | "
<< setw(2) << ob.ukr_lit << " | " << setw(2) << ob.informatic << " | " << setw(2) << ob.in_mov << " | "
<< ob.istor_ukr << " | " << setw(2) << ob.geografiy << " | " << setw(2) << ob.fizika << " | " << setw(2)
<< ob.biologia << " | " << setw(2) << ob.fizra << " | " << setw(4)
<< setw(2) << ob.seredniy_bal << " | " << setprecision(2) << ob.clas << "|" << endl;
cout << "******************************************************************************************************************************************" << endl;
in.close();
}
void enter()
{
Stud ob;
ofstream out;
out.open(file, ios::out | ios::app | ios::binary);
if (!out) {
cout << "Помилка";
}
system("cls");
cout << "Клас: ";
cin >> ob.clas;
cout << "Особистий номер: ";
cin >> ob.number;
eatline();
cout << "Прізвище: ";
cin.getline(ob.prizv, 15);
cout << "Ім'я: ";
cin.getline(ob.name, 15);
cout << "По батькові: ";
cin.getline(ob.batk, 15);
cout << "Математика: ";
cin >> ob.matem;
cout << "Українська мова: ";
cin >> ob.ukr_mov;
cout << "Українська література: ";
cin >> ob.ukr_lit;
cout << "Іноземна мова: ";
cin >> ob.in_mov;
cout << "Інформатика: ";
cin >> ob.informatic;
cout << "Фізика: ";
cin >> ob.fizika;
cout << "Історія України: ";
cin >> ob.istor_ukr;
cout << "Географія: ";
cin >> ob.geografiy;
cout << "Біологія: ";
cin >> ob.biologia;
cout << "Фіз-ра: ";
cin >> ob.fizra;
ob.seredniy_bal = (ob.matem + ob.ukr_mov + ob.informatic + ob.ukr_lit + ob.in_mov + ob.biologia + ob.istor_ukr + ob.fizika + ob.fizra + ob.geografiy) / 10;
eatline();
out.write((char*)&ob, sizeof ob);
out.close();
system("pause");
}
void poshyk()
{
system("cls");
int temp;
Stud ob;
fstream poshyk(file, ios::in | ios::binary);
look();
cout << "Пошук по особистому номером:" << endl;
cin >> temp;
eatline();
while (true) {
poshyk.read((char*)&ob, sizeof(Stud));
if (poshyk.eof()) {
cout << "Немає " << temp << endl;
return;
}
if (temp == ob.number) {
cout << "******************************************************************************************************************************************" << endl;
cout << "|№| Прізвище | Ім'я | По батькові |Матем.|Укр.мова|Укр.літ|Інформ.|Ін.мова|Укр.історія|Географія|Фізика|Біологія|Фіз-ра|Середн.бал|Клас|" << endl;
cout << "|" << ob.number << "|" << setw(10) << ob.prizv << "|" << setw(8) << ob.name << "|"
<< setw(13) << ob.batk << "| " << setw(2) << ob.matem << " | " << setw(2) << ob.ukr_mov << " | "
<< setw(2) << ob.ukr_lit << " | " << setw(2) << ob.informatic << " | " << setw(2) << ob.in_mov << " | "
<< ob.istor_ukr << " | " << setw(2) << ob.geografiy << " | " << setw(2) << ob.fizika << " | " << setw(2)
<< ob.biologia << " | " << setw(2) << ob.fizra << " | " << setw(4)
<< setw(2) << ob.seredniy_bal << " | " << setprecision(2) << ob.clas << "|" << endl;
cout << "******************************************************************************************************************************************" << endl;
return;
}
}
}
void sort()
{
system("cls");
fstream sort;
sort.open(file, ios::in | ios::binary);
Stud ob[1000];
Stud tem;
int count = 0;
while (!sort.eof()) {
sort.read((char*)&ob[count], sizeof(Stud));
count++;
}
count--;
cout << "Сортування по:\n1 - Особистому номеру\n2 - По прізвищу\nЗ - Середньому балу\n4 - Групі" << endl;
int a;
cin >> a;
eatline();
if (a == 1) {
for (int i = 0; i < count; i++)
for (int j = 0; j < count; j++) {
if (ob[i].number < ob[j].number) {
tem = ob[i];
ob[i] = ob[j];
ob[j] = tem;
}
}
if (a == 2)
for (int i = 0; i < count; i++)
for (int j = 0; j < count; j++)
if (ob[i].prizv[0] < ob[j].prizv[0]) {
tem = ob[i];
ob[i] = ob[j];
ob[j] = tem;
}
}
if (a == 3)
for (int i = 0; i < count; i++)
for (int j = 0; j < count; j++)
if (ob[i].seredniy_bal < ob[j].seredniy_bal) {
tem = ob[i];
ob[i] = ob[j];
ob[j] = tem;
}
if (a == 4)
for (int i = 0; i < count; i++)
for (int j = 0; j < count; j++)
if (ob[i].clas < ob[j].clas) {
tem = ob[i];
ob[i] = ob[j];
ob[j] = tem;
}
sort.close();
sort.clear();
sort.open(file, ios::out | ios::binary);
for (a = 0; a < count; a++)
sort.write((char*)&ob[a], sizeof(Stud));
sort.close();
cout << "Успішно!" << endl;
}
//////////////////////////////////////////////////
void redac()
{
system("cls");
int t = 0;
Stud ob[1000];
fstream del;
del.open(file, ios::in | ios::out | ios::binary);
if (!del.is_open()) {
cout << "Помилка!!!" << endl;
exit(1);
}
int count = 0;
while (!del.eof()) {
del.read((char*)&ob[count], sizeof(Stud));
count++;
}
look();
count--;
cout << "Введіть особистий номер учня для редагування: ";
double number;
cin >> number;
del.close();
del.clear();
del.open(file, ios::out | ios::binary);
for (int x = 0; x < count; x++)
if (ob[x].number != number)
del.write((char*)&ob[x], sizeof(Stud));
enter();
del.close();
cout << "Успішно!" << endl;
}
void delet()
{
system("cls");
int t = 0;
Stud ob[1000];
fstream del;
del.open(file, ios::in | ios::out | ios::binary);
if (!del.is_open()) {
cout << "Помилка!!!" << endl;
exit(1);
}
int count = 0;
while (!del.eof()) {
del.read((char*)&ob[count], sizeof(Stud));
count++;
}
look();
count--;
cout << "Введіть особистий номер учня каторого треба видалити: ";
double number;
cin >> number;
del.close();
del.clear();
del.open(file, ios::out | ios::binary);
for (int x = 0; x < count; x++)
if (ob[x].number != number)
del.write((char*)&ob[x], sizeof(Stud));
del.close();
cout << "Успішно!" << endl;
}
};
int main()
{
system("chcp 65001 > nul");
Base ob;
ob.provirka();
while (1) {
ob.menu();
}
return 0;
}