1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
| #include <iostream>
#include <fstream>
#include <Windows.h>
#include <tchar.h>
#include <conio.h>
using namespace std;
struct Data
{
char surname[15], name[10], patronymic[15], street[15];
int zone, number;
float S, tax;
};
Data D;
char filename[] = "List.dat";
FILE* f;
float c1, c2, c3, c4, c5;
void AddData();
void output();
void tax();
void tax_rate();
int main()
{
int _stateMenu;
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
system("color F0");
system("Cls");
printf("БАЗА ДАННЫХ ПОСЕЛЕНИЯ\n");
printf("\nВыберите нужный пункт\n");
printf("\n(1) Регистрация нового участка");
printf("\n(2) Информация о зарегестрированных участках");
printf("\n(0) Выход");
printf("\n\nВаш выбор: ");
scanf_s("%d", &_stateMenu);
switch (_stateMenu)
{
case 1: AddData(); break;
case 2: output(); break;
case 0: exit(0); break;
}
}
void AddData()
{
char s = '\0';
system("cls");
fopen_s(&f, filename, "rb+");
if(f)
{
do
{
fflush(stdin);
printf("\nФайл существует! Выберите действие:\n");
printf("0- создать файл заново\n");
printf("1- добавить данные в существующий файл\n");
printf("2 - отказаться от ввода\n");
s = getchar();
if (s == '0')
{
fclose(f);
fopen_s(&f, filename, "wb+");
}
else
if (s == '1')
{
fclose(f);
fopen_s(&f, filename, "ab+");
}
} while (s != '0' && s != '1' && s != '2');
}
else fopen_s(&f, filename, "wb+");
if (s != '2')
{
do
{
rewind(stdin);
printf("\nФамилия: "); gets_s(D.surname);
printf("\nИмя: "); gets_s(D.name);
printf("\nОтчество: "); gets_s(D.patronymic);
printf("\nЗона: "); scanf_s("%d", &D.zone);
rewind(stdin);
printf("\nУлица: "); gets_s(D.street);
printf("\nНомер: "); scanf_s("%d", &D.number);
printf("\nПлощадь: "); scanf_s("%f", &D.S);
fwrite(&D, sizeof(D), 1, f);
printf("Участок зарегестрирован");
printf("\n Продолжть ввод [д/н]:\n");
rewind(stdin); s = getchar();
} while (s == 'д' || s == 'Д');
} fclose(f);
}
void output()
{
system("cls");
fopen_s(&f, filename, "rb+");
if (!f) printf("Файл не найден!");
else
{
while (fread(&D, sizeof(D), 1, f))
{
printf("\n\n%s" , D.surname); printf(" %s", D.name); printf(" %s", D.patronymic);
printf("\nЗона : %d", D.zone);
printf("\nУлица: %s", D.street);
printf("\nНомер: %i", D.number);
printf("\nПлощадь: %f", D.S);
printf("\nНалог: %f", D.tax);
}
printf("\n");
fclose(f);
}
system("Pause");
}
void tax()
{
float z, s;
tax_rate();
fopen_s(&f, filename, "rb+");
while(fread(&D, sizeof(D), 1, f))
{
z = D.zone;
s = D.S;
if (z == 1) D.tax = c1 * s;
if (z == 2) D.tax = c2 * s;
if (z == 3) D.tax = c3 * s;
if (z == 4) D.tax = c4 * s;
if (z == 5) D.tax = c5 * s;
scanf_s("%f", &D.tax);
}
fwrite(&D, sizeof(D), 1, f);
rewind(stdin);
fclose(f);
}
void tax_rate()
{
ifstream tax_rate("tax_rate.txt");
tax_rate >> c1 >> c2 >> c3 >> c4 >> c5;
tax_rate.close();
} |