-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sfiles.cpp
117 lines (94 loc) · 2.38 KB
/
Sfiles.cpp
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
#include <string>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
#include "fun.h"
#include "Sfiles.h"
bool Is_file (string name)
{
ifstream file_text;
file_text.open(name.c_str());
if (file_text)
{
file_text.close();
return true;
}
else
{
file_text.close();
return false;
}
return false;
}
void outpute_sbox(string name, map <string, string> s_box, int mode)
{
ofstream out_file;
if (mode == 2) out_file.open(name.c_str(), ios_base::app);
else out_file.open(name.c_str());
map <string, string> ::iterator it;
for (it = s_box.begin(); it != s_box.end(); it++)
{
out_file << (*it).first <<" "<< (*it).second << endl;
}
out_file.close();
}
void outpute_pbox(string name, map <int, int> p_box, int mode)
{
ofstream out_file;
if (mode == 2) out_file.open(name.c_str(), ios_base::app);
else out_file.open(name.c_str());
map <int, int> ::iterator it;
for (it = p_box.begin(); it != p_box.end(); it++)
{
out_file << (*it).first << " " << (*it).second << endl;
}
out_file.close();
}
void outpute_info(string name, string login, int m, int n, int j, int mode)
{
ofstream out_file;
if (mode == 2) out_file.open(name.c_str(), ios_base::app);
else out_file.open(name.c_str());
out_file << login << endl;
out_file << m << endl;
out_file << n << endl;
out_file << j << endl;
out_file.close();
}
void outpute_file_full(string name, string login, int m, int n, int j, map <string, string> s_box, map <int, int> p_box)
{
outpute_info(name, login, m, n, j, 1);
outpute_sbox(name, s_box, 2);
outpute_pbox(name, p_box, 2);
}
data_file inpute_file_full(string name)
{
data_file temp;
ifstream file_text;
file_text.open(name.c_str());
if (file_text)
{
file_text >> temp.login;
file_text >> temp.m;
file_text >> temp.n;
file_text >> temp.j;
file_text.close();
return temp;
}
return temp;
}
void outpute_deltaA(string name, vector <pair_text> pair2, string delta, int mode)
{
ofstream out_file;
if (mode == 2) out_file.open(name.c_str(), ios_base::app);
else out_file.open(name.c_str());
out_file << "ΔA: " << delta << endl;
out_file << "X Y X' Y' ΔC" << endl;
for (int i = 0; i < (int) pair2.size(); i++)
{
out_file << pair2[i].x <<" "<< pair2[i].y <<" "<< pair2[i].x_ <<" " << pair2[i].y_ <<" "<< pair2[i].C << endl;
}
out_file.close();
}