Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <ctime>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. int proizvedenie(int npol, int* xp, int* yp, int* zp)
  10. {
  11.     int c = 0;
  12.     int tmp[3];
  13.     cout << *xp << endl;
  14.     tmp[0] = xp[1] * yp[2] - xp[2] * yp[1];
  15.     tmp[1] = xp[0] * yp[2] - xp[2] * yp[0];
  16.     tmp[2] = xp[0] * yp[1] - xp[1] * yp[0];
  17.  
  18.     c = tmp[0] * zp[0] - tmp[1] * zp[1] + tmp[3] * zp[3];
  19.    
  20.     return c;
  21. }
  22. const int n = 3;
  23. DWORD WINAPI run(LPVOID arg) {
  24.     char  * iFile = (char*)(static_cast<char**>(arg))[0];
  25.     char  * oFile = (char*)(static_cast<char**>(arg))[1];
  26.     ifstream fin(iFile);
  27.     ofstream fout(oFile);
  28.  
  29.     int* x = new int[n];
  30.     int* y = new int[n];
  31.     int* z = new int[n];
  32.     for (int i = 0; i < n; ++i)
  33.     {
  34.         fin >> x[i];
  35.     }
  36.     for (int i = 0; i < n; ++i)
  37.     {
  38.         fin >> y[i];
  39.     }
  40.     for (int i = 0; i < n; ++i)
  41.     {
  42.         fin >> z[i];
  43.     }
  44.  
  45.     try {
  46.         fout << proizvedenie(n, x, y, z);
  47.         cout << proizvedenie(n, x, y, z) << endl;
  48.     }
  49.     catch (...) {
  50.         fout << "Ошибка в данных";
  51.     }
  52.     return 0;
  53. }
  54.  
  55. int main()
  56. {
  57.     int a = 0;
  58.     char* iFile = "input.txt";
  59.     char* oFile = "output.txt";
  60.     char* params[] = { iFile, oFile };
  61.     long timeBegin = clock();
  62.     setlocale(LC_ALL, "Russian");
  63.     HANDLE hHandle = CreateThread(NULL, 0, run, static_cast<void*>(params), 0, 0);
  64.     if (hHandle == NULL)
  65.         return GetLastError();
  66.     WaitForSingleObject(hHandle, INFINITE);
  67.     long time = clock() - timeBegin;
  68.     CloseHandle(hHandle);
  69.     cout << (double)time / CLOCKS_PER_SEC << " секунд" << endl;
  70.     system("pause");
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement