Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <cmath>
- #define SIZE 1024
- using namespace std;
- long double **new_mas();
- void del_mas(long double **mas);
- bool cacheExist();
- void goInitializer(long double** cache, bool cacheExistAnswer);
- void initializerMasZero(long double** mas);
- void initializerMasCache(long double** mas);
- void copyInCache(long double** cache);
- void start_while(long double **cache1, long double **cache2);
- void cin_parametr(size_t *in_t, size_t *in_s);
- void work_func(size_t t, size_t s, long double *in_func, long double **cache1, long double **cache2);
- long double formul(long double **cache2, size_t t, size_t s);
- int main()
- {
- setlocale(0, "");
- bool cacheExistAnswer = cacheExist();
- long double **cache1 = new_mas();
- long double **cache2 = new_mas();
- goInitializer(cache1, cacheExistAnswer);
- start_while(cache1, cache2);
- copyInCache(cache1);
- del_mas(cache1);
- del_mas(cache2);
- return 0;
- }
- bool cacheExist()
- {
- ifstream fileCacheTest("cache.bin", ios_base::binary);
- bool answer = !(fileCacheTest);
- if (answer)
- cout << " [Файл кеша не найде, будет создан новый...]" << endl;
- else
- cout << " [Найден файл кеша...]" << endl;
- fileCacheTest.close();
- return answer;
- }
- long double **new_mas()
- {
- long double **mas = new long double *[SIZE];
- for (size_t y = 0; y < SIZE; y++)
- mas[y] = new long double[SIZE];
- return mas;
- }
- void goInitializer(long double** cache, bool cacheExistAnswer)
- {
- if (cacheExistAnswer)
- initializerMasCache(cache);
- else
- initializerMasZero(cache);
- }
- void initializerMasZero(long double** mas)
- {
- for (size_t i = 0; i < SIZE; i++)
- for (size_t j = 0; j < SIZE; j++)
- mas[i][j] = 0;
- }
- void initializerMasCache(long double** mas)
- {
- ifstream fileCache1("cache.bin", ios_base::binary);
- for (size_t i = 0; i < SIZE; i++)
- for (size_t j = 0; j < SIZE; j++)
- fileCache1.read((char*)(&mas[i][j]), sizeof(long double));
- fileCache1.close();
- }
- void copyInCache(long double** cache)
- {
- ofstream copyCache("cache.bin", ios_base::binary);
- for (size_t i = 0; i < SIZE; i++)
- for (size_t j = 0; j < SIZE; j++)
- copyCache.write((char*)(&cache[i][j]), sizeof(long double));
- copyCache.close();
- }
- void del_mas(long double **mas)
- {
- for (size_t y = 0; y < SIZE; y++)
- delete[] mas[y];
- delete[] mas;
- }
- void start_while(long double **cache1, long double **cache2)
- {
- size_t t, s;
- long double func;
- bool answer = 1;
- while (answer)
- {
- cin_parametr(&t, &s);
- work_func(t, s, &func, cache1, cache2);
- cout << "Результат = " << func << endl;
- cout << endl << "Ввести новые значения? (1/0)" << endl;
- cin >> answer;
- }
- }
- void cin_parametr(size_t *in_t, size_t *in_s)
- {
- cout << "Введите число t и число s" << endl;
- cin >> *in_t;
- cin >> *in_s;
- if (*in_t > 1024 || *in_s > 1024)
- {
- cout << "Введенное число больше 1024" << endl;
- exit(-1);
- }
- }
- void work_func(size_t t, size_t s, long double *in_func, long double **cache1, long double **cache2)
- {
- if (!cache1[t][s])
- cache1[t][s] = *in_func = formul(cache2, t, s);
- else
- *in_func = cache1[t][s];
- }
- long double formul(long double **cache2, size_t t, size_t s)
- {
- long double argument;
- if (!cache2[t][s])
- cache2[t][s] = argument = log(1 + powl((t + s), 5)) * cosl(powl((t + s), 2));
- else
- argument = cache2[t][s];
- return argument * t / s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement