Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cstdlib>
- #include <cmath>
- #include <fstream>
- #define SIZE 1024
- using namespace std;
- long double **new_mas();
- void del_mas(long double **mas);
- bool cacheExist();
- void goInitializer(long double** cache1, long double** cache2, bool cacheExistAnswer);
- void initializerMasZero(long double** mas);
- void initializerMasCache(ifstream& cache, long double** mas);
- void goCopy(long double** cache1, long double** cache2);
- void copyInCache(ofstream& cache, long double** mas);
- void start_while(long double **cache1, long double **cache2);
- void io_user_send(size_t *t, size_t *s);
- 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, cache2, cacheExistAnswer);
- start_while(cache1, cache2);
- goCopy(cache1, cache2);
- del_mas(cache1);
- del_mas(cache2);
- return 0;
- }
- bool cacheExist()
- {
- ifstream fileCache1("cache1.bin", ios_base::binary);
- ifstream fileCache2("cache2.bin", ios_base::binary);
- bool answer = !(fileCache1 && fileCache1);
- if (answer)
- cout << " [Отсутствуют файлы кеша, будут созданы новые...]" << endl;
- else
- cout << " [Файлы кеша найдены...]" << endl;
- fileCache1.close();
- fileCache2.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** cache1, long double** cache2, bool cacheExistAnswer)
- {
- if (cacheExistAnswer)
- {
- ifstream fileCache1("cache1.bin", ios_base::binary);
- ifstream fileCache2("cache2.bin", ios_base::binary);
- initializerMasCache(fileCache1, cache1);
- initializerMasCache(fileCache2, cache2);
- fileCache1.close();
- fileCache1.close();
- }
- else
- {
- initializerMasZero(cache1);
- initializerMasZero(cache2);
- }
- }
- 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(ifstream& cache, long double** mas)
- {
- for (size_t i = 0; i < SIZE; i++)
- for (size_t j = 0; j < SIZE; j++)
- cache >> mas[i][j];
- }
- void goCopy(long double** cache1, long double** cache2)
- {
- ofstream copyCache1("cache1.bin", ios_base::binary);
- ofstream copyCache2("cache2.bin", ios_base::binary);
- copyInCache(copyCache1, cache1);
- copyInCache(copyCache2, cache2);
- copyCache1.close();
- copyCache2.close();
- }
- void copyInCache(ofstream& cache, long double** mas)
- {
- for (size_t i = 0; i < SIZE; i++)
- for (size_t j = 0; j < SIZE; j++)
- cache << mas[i][j];
- }
- 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)
- {
- io_user_send(&t, &s);
- work_func(t, s, &func, cache1, cache2);
- cout << "Результат = " << func << endl;
- cout << endl << "Ввести новые значения? (1/0)" << endl;
- cin >> answer;
- }
- }
- void io_user_send(size_t *t, size_t *s)
- {
- cout << "Введите число t и число s" << endl;
- cin_parametr(t, s);
- }
- void cin_parametr(size_t *in_t, size_t *in_s)
- {
- 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