-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab2.2_Y.cpp
63 lines (58 loc) · 1.16 KB
/
lab2.2_Y.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
#include "global_lab_header.hpp"
#include <iostream>
#include <fstream>
#include <thread>
namespace L2
{
namespace Y2
{
void fib(std::string name)
{
std::ofstream f(name, std::ios::out);
if (f.is_open())
{
std::cout << 1 << ' ' << 1;
f << 1 << ' ' << 1;
for (int a = 1, b = 1, i = 3; i <= 12; i++)
{
a += b;
std::swap(a, b);
std::cout << ' ' << b;
f << ' ' << b;
}
std::cout << std::endl;
f.close();
}
}
void notify(std::string name)
{
std::thread f(fib, name);
f.join();
std::cout << "Поток закончил работу." << std::endl;
}
void app(std::string name)
{
std::fstream f(name, std::ios::in | std::ios::out);
if (f.is_open())
{
int num, sum = 0;
while (f >> num) sum += num;
f.clear();
std::cout << "Сумма : " << sum << std::endl;
f << " : " << sum << std::endl;
f.close();
}
std::cout << "Поток дополнил файл." << std::endl;
}
int main()
{
std::string name = "Fibonacci.txt";
std::thread th(notify, name);
th.join();
th = std::thread(app, name);
th.join();
std::cin.get();
return 0;
}
}
}