Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- using namespace std;
- FILE* f1;
- typedef struct
- {
- char imya[30];
- char familia[30];
- char otchestvo[30];
- char srball[30];
- int minzp;
- } Tabitur;
- Tabitur abitur[30];
- char name[20];
- int nst = 0;
- int menu();
- void nnf();
- void newf();
- void spisok();
- void opf();
- void resc();
- void resf();
- int main()
- {
- while (true)
- {
- switch (menu())
- {
- case 1:nnf(); break;
- case 2:newf(); break;
- case 3:spisok(); break;
- case 4:opf(); break;
- case 5:resc(); break;
- case 6:resf(); break;
- case 7:return 0;
- default:"Vibrano ne pravilno !";
- }
- puts("Press any key to continue");
- getch(); system("cls");
- }
- }
- int menu()
- {
- cout << "Viberite:" << endl;
- cout << "1.Vvod file name" << endl;
- cout << "2.New file" << endl;
- cout << "3.Vvesti spisok" << endl;
- cout << "4.Open file" << endl;
- cout << "5.Vivesti result" << endl;
- cout << "6.Vivesti v file" << endl;
- cout << "7.Exit" << endl;
- int i;
- cin >> i;
- return i;
- }
- void nnf()
- {
- cout << "Vvedite file name" << endl;
- cin >> name;
- }
- void newf()
- {
- if ((f1 = fopen(name, "wb")) == NULL)
- {
- cout << "Oshibka pri sozdanii" << endl;
- exit(1);
- }
- cout << "OK" << endl;
- fclose(f1);
- }
- void spisok()
- {
- if ((f1 = fopen(name, "rb+")) == NULL)
- {
- cout << "Oshibka pri sozdanii" << endl;
- exit(1);
- }
- cout << "Vvedite chislo abiturientov" << endl;
- cin >> nst;
- for (int i = 0; i < nst; i++)
- {
- cout << "Vvedite imya:";
- cin >> abitur[i].imya;
- cout << "Vvedite familiu:";
- cin >> abitur[i].familia;
- cout << "Vvedite otchestvo:";
- cin >> abitur[i].otchestvo;
- cout << "Vvedite srball:";
- cin >> abitur[i].srball;
- cout << "Vvedite minzp:";
- cin >> abitur[i].minzp;
- fwrite(&abitur[i], sizeof(Tabitur), 1, f1);
- }
- fclose(f1);
- }
- void opf()
- {
- if ((f1 = fopen(name, "rb")) == NULL)
- {
- cout << "Oshibka pri otkritii" << endl;
- exit(1);
- }
- nst = 0; Tabitur std;
- while (true)
- {
- int nwrt = fread(&std, sizeof(Tabitur), 1, f1);
- if (nwrt != 1) break;
- abitur[nst] = std;
- cout << abitur[nst].imya << "" << abitur[nst].familia << "" << abitur[nst].otchestvo << "" << abitur[nst].srball << "" << abitur[nst].minzp << endl;
- nst++;
- }
- fclose(f1);
- }
- void resc()
- {
- int i;
- for (i = 0; i < nst; i++)
- if (abitur[i].minzp < 15000)
- cout << abitur[i].imya << "" << abitur[i].familia << "" << abitur[i].otchestvo << "" << abitur[i].srball << "" << abitur[i].minzp << endl;
- }
- void resf()
- {
- char namet[30];
- FILE* f1;
- cout << "Vvedite imya file" << endl;
- cin >> namet;
- if ((f1 = fopen(namet, "w")) == NULL)
- {
- cout << "Oshibka pri sozdanii" << endl;
- exit(1);
- }
- char s[80];
- for (int i = 0; i < nst; i++)
- if (abitur[i].minzp < 15000)
- {
- strcpy(s, abitur[i].imya);
- strcat(s, "");
- fputs(s, f1);
- strcpy(s, abitur[i].familia);
- strcat(s, "");
- fputs(s, f1);
- strcpy(s, abitur[i].otchestvo);
- strcat(s, "");
- fputs(s, f1);
- strcpy(s, abitur[i].srball);
- strcat(s, "");
- fputs(s, f1);
- }
- fclose(f1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement