#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 fam[15];
char name[15];
char otchestvo[15];
double istor_bel;
double informatic;
double fizika;
double matem;
double bel_yz;
double bel_lit;
double rus_yz;
double rus_lit;
double chog;
double in_yz;
double fizra;
double biologia;
double geografiy;
double sredni_ball;
};
class Base {
int a, num, j, b, g;
public:
Stud ob;
void menu()
{
system("cls");
cout << r(" Контроль успеваемости учащихся СШ№ 3\n") << endl;
cout << r(" 1.Просмотр") << endl;
cout << r(" 2.Ввод") << endl;
cout << r(" 3.Редактирование") << endl;
cout << r(" 4.Поиск") << endl;
cout << r(" 5.Сортировка") << endl;
cout << r(" 6.Удаление") << endl;
cout << r(" 7.Выход") << endl;
a = _getch();
switch (a) {
case '1':
look();
next();
break;
case '2':
enter();
next();
break;
case '3':
redac();
next();
break;
case '4':
poisk();
next();
break;
case '5':
sort();
next();
break;
case '6':
delet();
next();
break;
case '7':
exit(1);
break;
default:
cout << r("Ошибка повторите ввод!!!");
}
}
void next()
{
cout << r("Для выхода в главное меню нажмите (1) для выхода (2)") << endl;
a = _getch();
switch (b) {
case '1':
menu();
break;
case '2':
exit(1);
}
}
void proverka()
{
fstream fil;
fil.open(file, ios::out | ios::in | ios::binary);
if (!file) {
cout << r(" Файл не найден !!!") << endl;
system("pause");
}
fil.close();
}
void look()
{
system("cls");
Stud ob;
ifstream in;
in.open(file, ios::in | ios::binary);
if (!in) {
cout << r("Ошибка");
}
cout << "********************************************************************************" << endl;
while (in.read((char*)&ob, sizeof ob))
cout << "|" << setw(2) << ob.number << "|" << setw(10) << ob.fam << "|" << setw(8) << ob.name << "|"
<< setw(13) << ob.otchestvo << "|" << setw(2) << ob.matem << "|" << setw(2) << ob.bel_yz << "|"
<< setw(2) << ob.bel_lit << "|" << setw(2) << ob.rus_yz << "|" << setw(2) << ob.rus_lit << "|"
<< setw(2) << ob.informatic << "|" << setw(2) << ob.in_yz << "|" << setw(2) << ob.chog << "|"
<< ob.istor_bel << "|" << setw(2) << ob.geografiy << "|" << setw(2) << ob.fizika << "|" << setw(2)
<< ob.biologia << "|" << setw(2) << ob.fizra << "|" << setw(4)
<< setprecision(2) << ob.sredni_ball << "|" << endl;
cout << "***************************************************" << endl;
in.close();
}
void enter()
{
Stud ob;
ofstream out;
out.open(file, ios::out | ios::app | ios::binary);
if (!out) {
cout << r("Ошибка");
}
system("cls");
cout << r("Личный номер:");
cin >> ob.number;
eatline();
cout << r("Фамилия:");
cin.getline(ob.fam, 15);
cout << r("Имя:");
cin.getline(ob.name, 15);
cout << r("Отчество:");
cin.getline(ob.otchestvo, 15);
cout << r("Математика:");
cin >> ob.matem;
cout << r("Белорусский язык:");
cin >> ob.bel_yz;
cout << r("Белорусская литература:");
cin >> ob.bel_lit;
cout << r("Русский язык:");
cin >> ob.rus_yz;
cout << r("Русская литература:");
cin >> ob.rus_lit;
cout << r("Иностранный язык:");
cin >> ob.in_yz;
cout << r("Информатика:");
cin >> ob.informatic;
cout << r("Физика:");
cin >> ob.fizika;
cout << r("Истрория Беларуси:");
cin >> ob.istor_bel;
cout << r("Ч.О.Г:");
cin >> ob.chog;
cout << r("География:");
cin >> ob.geografiy;
cout << r("Биология:");
cin >> ob.biologia;
cout << r("Ф-ра:");
cin >> ob.fizra;
ob.sredni_ball = (ob.matem + ob.bel_yz + ob.informatic + ob.bel_lit + ob.in_yz + ob.rus_yz + ob.rus_lit + ob.biologia + ob.istor_bel + ob.chog + ob.fizika + ob.fizra + ob.geografiy) / 13;
eatline();
out.write((char*)&ob, sizeof ob);
out.close();
system("pause");
}
void poisk()
{
system("cls");
int temp;
Stud ob;
fstream poisk(file, ios::in | ios::binary);
look();
cout << r("Поиск по личному номеру:") << endl;
cin >> temp;
eatline();
while (true) {
poisk.read((char*)&ob, sizeof(Stud));
if (poisk.eof()) {
cout << "net " << temp << endl;
return;
}
if (temp == ob.number) {
cout << "*****************************************************************************" << endl;
cout << "|" << setw(2) << ob.number << "|" << setw(10) << ob.fam << "|" << setw(8) << ob.name << "|"
<< setw(13) << ob.otchestvo << "|" << setw(2) << ob.matem << "|" << setw(2) << ob.bel_yz << "|"
<< setw(2) << ob.bel_lit << "|" << setw(2) << ob.rus_yz << "|" << setw(2) << ob.rus_lit << "|"
<< setw(2) << ob.informatic << "|" << setw(2) << ob.in_yz << "|" << setw(2) << ob.chog << "|"
<< ob.istor_bel << "|" << setw(2) << ob.geografiy << "|" << setw(2) << ob.fizika << "|" << setw(2)
<< ob.biologia << "|" << setw(2) << ob.fizra << "|" << setw(4)
<< setprecision(2) << ob.sredni_ball << "|" << 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 << r("Сортировка по:\n1 -Личному номеру\n2 - По фамилие\nЗ - Среднему баллу: ");
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].fam[0] < ob[j].fam[0]) {
tem = ob[i];
ob[i] = ob[j];
ob[j] = tem;
}
}
else if (a == 3)
for (int i = 0; i < count; i++)
for (int j = 0; j < count; j++)
if (ob[i].sredni_ball < ob[j].sredni_ball) {
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();
}
//////////////////////////////////////////////////
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 << r("Ошибка!!!") << endl;
exit(1);
}
int count = 0;
while (!del.eof()) {
del.read((char*)&ob[count], sizeof(Stud));
count++;
}
look();
count--;
cout << r("Введите личный номер ученика для редактирования: ");
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();
}
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 << r("Ошибка!!!") << endl;
exit(1);
}
int count = 0;
while (!del.eof()) {
del.read((char*)&ob[count], sizeof(Stud));
count++;
}
look();
count--;
cout << r("Введите личный номер ученика каторого надо удалить: ");
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();
}
};
int main()
{
Base ob;
ob.proverka();
while (1) {
ob.menu();
}
return 0;
}