Самостаятельная работа(Deadline) По предмету "Програмирование"
Download 0.62 Mb.
|
Самостаятельная работа(Deadline) По предмету ”Програмирование” Студента I-SWD209-2 Факультета “Мобильные системы” Ташкентский университет информационных технологий имени Мухаммада аль-Хорезми Аблаева Акима Задание
#include #include #include #include #include #include #include #include #include #pragma warning(disable : 4996) // using namespace std; struct tek_sost { int r; int p; }; struct bank { char fio[11]; int n_s; struct tek_sost t_s; }; int col_rec(FILE* file); bank reading(FILE* file, int i); void record(FILE* file, int i, bank dat); void print(bank vsp); void vivod(FILE* file); int main() { setlocale(LC_ALL, "Russian"); FILE* f, * f1; int n, i, v, n_s, j, pol, k, m, c; bank a, b, B, V, d; char s[40], s1[40], l; v = 1; f = fopen("file", "w"); f1 = fopen("file1.tmp", "w"); n = col_rec(f); while (v == 1 || v == 2 || v == 3 || v == 4 || v == 5 || v == 6) { cout << endl; cout << " "; cout << endl; cout << "1- "; cout << endl; cout << "2- "; cout << endl; cout << "3- "; cout << endl; cout << "4- "; cout << endl; cout << "5- "; cout << endl; cout << "6- "; cout << endl; cout << " "; cout << endl; cin >> v; // ////////////////////////////////////////////////////// if (v == 1) { f = fopen("file", "a+b"); fseek(f, n * sizeof(bank), SEEK_SET); cout << " "; cout << endl; cin >> a.fio; cout << " "; cout << endl; cin >> a.n_s; cout << " "; cout << endl; cin >> a.t_s.r; cout << " "; cout << endl; cin >> a.t_s.p; fwrite(&a, sizeof(bank), 1, f); n++; vivod(f); } // /////////////////////////////////////////////////////// if (v == 2) { f = fopen("file", "r+b"); f1 = fopen("file1.tmp", "wb"); cout << " "; cout << endl; cin >> n_s; i = 1; while ((fread(&a, sizeof(bank), 1, f)) && (i < n_s)) { fwrite(&a, sizeof(bank), 1, f1); i++; } while (fread(&a, sizeof(bank), 1, f)) { fwrite(&a, sizeof(bank), 1, f1); } fclose(f); fclose(f1); f = fopen("file", "wb"); f1 = fopen("file1.tmp", "rb"); while (fread(&a, sizeof(bank), 1, f1)) { fwrite(&a, sizeof(bank), 1, f); } fclose(f); fclose(f1); f = fopen("file", "rb"); vivod(f); }; // ///////////////////////////////////////////////// if (v == 3) { f = fopen("file", "r+b"); cout << " "; cout << endl; cin >> n_s; n_s = n_s - 1; fseek(f, n_s * sizeof(bank), SEEK_SET); fread(&a, sizeof(bank), 1, f); cout << " (" << a.fio << ")"; cout << endl; cin >> b.fio; cout << " (" << a.n_s << ")"; cout << endl; cin >> b.n_s; cout << " (" << a.t_s.r << ")"; cout << endl; cin >> b.t_s.r; cout << " (" << a.t_s.p << ")"; cout << endl; cin >> b.t_s.p; fseek(f, n_s * sizeof(bank), SEEK_SET); fwrite(&b, sizeof(bank), 1, f); vivod(f); }; // ////////////////////////////////////////////////// if (v == 4) { i = 0; j = 0; k = 0; m = 0; f = fopen("file", "r+b"); n = col_rec(f); cout << endl << " " << endl; cout << "1- " << endl; cout << "2- " << endl; cout << "3- " << endl; cout << "4- " << endl; cin >> pol; // for (i = 0; i < n; i++) { B = reading(f, i); j = 0; switch (pol) { case 1: { while (strcmp(B.fio, reading(f, j).fio) > 0) j++; break; }; case 2: { while (B.n_s > reading(f, j).n_s) j++; break; }; case 3: { while (B.t_s.r > reading(f, j).t_s.r) j++; break; }; case 4: { while (B.t_s.p > reading(f, j).t_s.p) j++; break; }; default: {cout << " !!!" << endl; }; }; for (k = i - 1; k >= j; k--) { m = k; V = reading(f, k); record(f, ++m, V); } record(f, j, B); }; vivod(f); }; // //////////////////////////////////////////////////////// if (v == 5) { f = fopen("file", "rb"); cout << endl; cout << "1- " << endl; cout << "2- " << endl; cout << "3- " << endl; cout << "4- " << endl; cin >> pol; cout << " " << endl; switch (pol) { case 1: {cin >> s1; break; }; case 2: {cin >> c; break; }; case 3: {cin >> l; break; }; case 4: {cin >> c; break; } default: {cout << " !!!" << endl; } }; i = 0; cout << "-------------------------------------------------"; cout << endl; cout << "|"; cout.width(11); cout << " "; cout << "|"; cout.width(11); cout << " "; cout << "|"; cout.width(11); cout << " "; cout << "|"; cout.width(11); cout << " "; cout << "|"; cout << endl; cout << "-------------------------------------------------"; cout << endl; while (fread(&a, sizeof(bank), 1, f)) { switch (pol) { case 1: { if (!strcmp(s1, a.fio)) { print(a); i++; }; break; }; case 2: { if (c == a.n_s) { print(a); i++; }; break; }; case 3: { if (l == a.t_s.r) { print(a); i++; }; break; }; case 4: { if (c == a.t_s.p) { print(a); i++; }; break; }; default: { }; }; } fclose(f); }; // /////////////////////////////////////////// if (v == 6) { f = fopen("file", "rb"); vivod(f); }; } } int col_rec(FILE* file) { int n = 0; bank dat; fseek(file, 0, SEEK_SET); while (fread(&dat, sizeof(bank), 1, file)) n++; return n; }; bank reading(FILE* file, int i) { bank vsp; fseek(file, i * sizeof(bank), SEEK_SET); fread(&vsp, sizeof(bank), 1, file); return vsp; }; void record(FILE* file, int i, bank dat) { fseek(file, i * sizeof(bank), SEEK_SET); fwrite(&dat, sizeof(bank), 1, file); }; void print(bank vsp) { cout.width(11); cout << vsp.fio; cout.width(11); cout << vsp.n_s; cout.width(11); cout << vsp.t_s.r; cout.width(11); cout << vsp.t_s.p; cout << endl; }; void vivod(FILE* file) { bank a; fseek(file, 0 * sizeof(bank), SEEK_SET); cout << "-------------------------------------------------"; cout << endl; cout << "|"; cout.width(11); cout << " "; cout << "|"; cout.width(11); cout << " "; cout << "|"; cout.width(11); cout << " "; cout << "|"; cout.width(11); cout << " "; cout << "|"; cout << endl; cout << "-------------------------------------------------"; cout << endl; while (fread(&a, sizeof(bank), 1, file)) { cout.width(11); cout << a.fio; cout.width(11); cout << a.n_s; cout.width(11); cout << a.t_s.r; cout.width(11); cout << a.t_s.p; cout << endl; } fclose(file); } Спасибо за внимание! Download 0.62 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling