SHOW:
|
|
- or go back to the newest paste.
1 | - | #pragma hdrstop |
1 | + | #include <stdio.h> |
2 | - | #include<stdio.h> |
2 | + | #include <stdlib.h> |
3 | - | #include<conio.h> |
3 | + | #include <windows.h> |
4 | - | #include<string.h> |
4 | + | #include <string.h> |
5 | - | #pragma argsused |
5 | + | struct student |
6 | - | struct Library{ |
6 | + | { int grup; |
7 | - | char surname[10], initials[4], title[20], place_of_publication[20]; |
7 | + | char secondName[20]; |
8 | - | int year; |
8 | + | char firstName[20]; |
9 | - | } Lib[100], LibRes[100]; |
9 | + | float mathAnalysis; |
10 | float algebra; | |
11 | - | void Add(FILE *file1) |
11 | + | float programming; |
12 | } roll[20], roll2[20], buffer; | |
13 | - | int i, n; |
13 | + | void write(FILE *file); |
14 | - | clrscr(); |
14 | + | void printer(FILE *file); |
15 | - | printf("Enter number of books\n"); |
15 | + | void result(FILE *file, FILE *file2); |
16 | - | scanf("%d", &n); |
16 | + | void print_result(FILE *file); |
17 | void write(FILE *file) | |
18 | - | fflush(stdin); |
18 | + | { int n, i; |
19 | - | for(i=0;i<n;i++){ |
19 | + | printf("Введіть кількість студентів: "); |
20 | - | printf("Surname: ");scanf("%s", &Lib[i].surname); |
20 | + | scanf("%d", &n); |
21 | - | printf("Initials: "); scanf("%s", &Lib[i].initials); |
21 | + | for(i=0; i<n; i++) |
22 | - | printf("Title: "); scanf("%s", &Lib[i].title); |
22 | + | { |
23 | - | printf("Place of publication: "); scanf("%s", &Lib[i].place_of_publication); |
23 | + | printf("%d Група: ", i+1); |
24 | - | printf("Year: "); scanf("%d", &Lib[i].year); |
24 | + | scanf("%d", &(roll[i].grup)); |
25 | - | fwrite(&Lib[i], sizeof(struct Library), 1, file1); |
25 | + | printf(" Прізвище: "); |
26 | - | clrscr(); |
26 | + | scanf("%s", (roll[i].secondName)); |
27 | - | } |
27 | + | printf(" Iм'я: "); |
28 | scanf("%s", (roll[i].firstName)); | |
29 | printf(" Бали:\n"); | |
30 | printf(" Математичний аналіз - "); | |
31 | scanf("%f", &(roll[i].mathAnalysis)); | |
32 | - | void Review (FILE *file) |
32 | + | printf(" Алгебра - "); |
33 | scanf("%f", &(roll[i].algebra)); | |
34 | - | int i=0; |
34 | + | printf(" Програмування - "); |
35 | scanf("%f", &(roll[i].programming)); | |
36 | - | while( fread(&Lib[i], sizeof(struct Library), 1, file)) |
36 | + | fwrite(&(roll[i]), sizeof(struct student), 1, file); |
37 | } | |
38 | - | printf("Surname and initials: %s %s \n", Lib[i].surname, Lib[i].initials); |
38 | + | |
39 | - | printf("Title: ");puts(Lib[i].title); |
39 | + | void printer(FILE *file) |
40 | - | printf(" place of publication and year: %s %d\n", Lib[i].place_of_publication, Lib[i].year); |
40 | + | |
41 | - | i++; |
41 | + | int i=0; |
42 | while(fread(&roll[i], sizeof(struct student), 1, file)) | |
43 | { | |
44 | printf("\n%d Група: ", i+1); | |
45 | - | void Result (FILE *file1, FILE *file2) |
45 | + | printf("%d", (roll[i].grup)); |
46 | printf("\n Прізвище: "); | |
47 | - | int i=0, j, n=0, k=0; |
47 | + | printf(roll[i].secondName); |
48 | - | while( fread(&Lib[i], sizeof(struct Library), 1, file1)) |
48 | + | printf("\n Iм'я: "); |
49 | printf(roll[i].firstName); | |
50 | - | if(Lib[i].year == 1993) |
50 | + | printf("\n Бали:"); |
51 | printf("\n Математичний аналіз - "); | |
52 | - | LibRes[k]=Lib[i]; |
52 | + | printf("%f", roll[i].mathAnalysis); |
53 | - | k++; |
53 | + | printf("\n Алгебра - "); |
54 | printf("%f", roll[i].algebra); | |
55 | printf("\n Програмування - "); | |
56 | printf("%f", roll[i].programming); | |
57 | i++; | |
58 | - | for(i=0;i<k;i++) |
58 | + | } |
59 | - | for(j=0;j<k-1;j++) |
59 | + | |
60 | } | |
61 | - | int l=strcmp(LibRes[j].surname,LibRes[j+1].surname); |
61 | + | |
62 | - | if(l>=1) |
62 | + | void result(FILE *file, FILE *file2) |
63 | - | { |
63 | + | |
64 | - | struct Library t=LibRes[j]; |
64 | + | int i=0, n, j; |
65 | - | LibRes[j]=LibRes[j+1]; |
65 | + | while( fread(&roll[i], sizeof(struct student), 1, file)) |
66 | - | LibRes[j+1]=t; |
66 | + | |
67 | - | } |
67 | + | roll2[i]=roll[i]; |
68 | i++; | |
69 | - | file2 = fopen("Res_Library.dat", "wb"); |
69 | + | |
70 | - | for(i=0;i<k;i++) |
70 | + | n=i; |
71 | for(i=0;i<n;i++) | |
72 | - | fwrite(&LibRes[i], sizeof(struct Library), 1, file2); |
72 | + | for(j=0;j<n-1;j++) |
73 | { | |
74 | if((roll2[j].mathAnalysis+roll2[j].algebra+roll2[j].programming)<(roll2[j+1].mathAnalysis+roll2[j+1].algebra+roll2[j+1].programming)) | |
75 | buffer=roll2[j]; | |
76 | - | int main(int argc, char* argv[]) |
76 | + | roll2[j]=roll2[j+1]; |
77 | roll2[j+1]=buffer; | |
78 | - | int i=1, n; |
78 | + | |
79 | - | FILE *file1, *file2; |
79 | + | for(i=0; i<n; i++) |
80 | - | while(i) |
80 | + | |
81 | fwrite(&roll2[i], sizeof(struct student), 1, file2); | |
82 | - | printf("1 - New File 2 - Add to File 3 - Open 4 - Review 5 - EXIT\n"); |
82 | + | |
83 | - | scanf("%d", &n); |
83 | + | |
84 | - | if(n == 1) |
84 | + | |
85 | ||
86 | - | file1 = fopen("Library.dat", "wb"); |
86 | + | |
87 | - | Add(file1); |
87 | + | void print_result(FILE *file) |
88 | - | fclose(file1); |
88 | + | |
89 | int i=0; | |
90 | while( fread(&roll2[i], sizeof(struct student), 1, file)) | |
91 | - | if(n==2) |
91 | + | { |
92 | printf("\nПрізвище : %s", roll2[i].secondName); | |
93 | - | file1 = fopen("Library.dat", "ab"); |
93 | + | printf("\n Середній бал: %0.2f", (roll2[i].mathAnalysis+roll2[i].algebra+roll2[i].programming)/3 ); |
94 | - | Add(file1); |
94 | + | i++; |
95 | - | fclose(file1); |
95 | + | } |
96 | } | |
97 | int main() | |
98 | - | if(n==3) |
98 | + | |
99 | FILE *file, *file2; | |
100 | - | file1 = fopen("Library.dat", "rb" ); |
100 | + | int point=1, i; |
101 | SetConsoleCP(1251); | |
102 | SetConsoleOutputCP(1251); | |
103 | ||
104 | - | if(n==4) |
104 | + | while(point) |
105 | { system("cls"); | |
106 | - | file1 = fopen("Library.dat", "rb"); |
106 | + | printf("Для вибору дії натисніть: \n"); |
107 | - | Review(file1); |
107 | + | printf("1-Створити 2-Відкрити 3-Закрити 4-Переглянути 5-Додати 6-Результат 7-Вихід\n"); |
108 | - | fclose(file1); |
108 | + | scanf("%d", &i); |
109 | - | getch(); |
109 | + | if(i==1) |
110 | { | |
111 | file=fopen("BF_12.dat", "wb"); | |
112 | - | if(n==5) |
112 | + | write(file); |
113 | fclose(file); | |
114 | - | fclose(file1); |
114 | + | system("cls"); |
115 | - | i=0; |
115 | + | } |
116 | if(i==2) | |
117 | { | |
118 | - | file1 = fopen("Library.dat", "rb"); |
118 | + | file=fopen("BF_12.dat", "rb"); |
119 | - | file2 = fopen("Res_Library.dat", "wb"); |
119 | + | } |
120 | - | Result(file1, file2); |
120 | + | if(i==3) |
121 | - | fclose(file2); |
121 | + | { |
122 | - | file2 = fopen("Res_Library.dat", "rb"); |
122 | + | fclose(file); |
123 | - | Review(file2); |
123 | + | } |
124 | - | fclose(file1); |
124 | + | if(i==4) |
125 | - | fclose(file2); |
125 | + | { |
126 | file=fopen("BF_12.dat", "rb"); | |
127 | - | getch();return 0; |
127 | + | printer(file); |
128 | fclose(file); | |
129 | getch(); | |
130 | } | |
131 | if(i==5) | |
132 | { | |
133 | file = fopen("BF_12.dat", "ab"); | |
134 | write(file); | |
135 | fclose(file); | |
136 | } | |
137 | if(i==6) | |
138 | { | |
139 | file=fopen("BF_12.dat", "rb"); | |
140 | file2 =fopen("BF_12_2.dat", "wb"); | |
141 | result(file, file2); | |
142 | fclose(file2); | |
143 | file2 =fopen("BF_12_2.dat", "rb"); | |
144 | print_result(file2); | |
145 | fclose(file); | |
146 | fclose(file2); | |
147 | getch(); | |
148 | } | |
149 | if(i==7) | |
150 | { | |
151 | point=0; | |
152 | } | |
153 | } | |
154 | return 0; | |
155 | } |