Advertisement
Guest User

Untitled

a guest
May 27th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. bool cmp(int xstart, int xend, bool f)
  9. {
  10. if (f)
  11. return xstart <= xend;
  12. else
  13. return xstart >= xend;
  14. }
  15.  
  16. int main()
  17. {
  18. typedef double(*myf_1)(double, double, double);
  19. typedef double(*myf_math)(double, double);
  20. typedef const char*(*FName)();
  21. if (!(LoadLibraryEx(L"lab9dll.dll", 0, LOAD_LIBRARY_AS_DATAFILE)))
  22. {
  23. cout << "Library loading error" << endl;
  24. system("pause");
  25. exit(0);
  26. }
  27. HINSTANCE pdll = LoadLibrary(L"lab9dll.dll");
  28. myf_1 MyFunction = (myf_1)GetProcAddress(pdll, "myf_1");
  29. myf_math Function = (myf_math)GetProcAddress(pdll, "myf_math");
  30. FName Name = (FName)GetProcAddress(pdll, "FName");
  31. if (!(pdll && MyFunction && Function && Name))
  32. {
  33. cout << "Unknown functions" << endl;
  34. system("pause");
  35. exit(0);
  36. }
  37. m1: double eps = 0, xstart = 0, xend = 0, dx = 1, a = -1;
  38. cout << "eps = ";
  39. cin >> eps;
  40. cin.clear();
  41. cin.ignore(cin.rdbuf()->in_avail());
  42. cout << "x start = ";
  43. cin >> xstart;
  44. cin.clear();
  45. cin.ignore(cin.rdbuf()->in_avail());
  46. cout << "x end = ";
  47. cin >> xend;
  48. cin.clear();
  49. cin.ignore(cin.rdbuf()->in_avail());
  50. cout << "dx = ";
  51. cin >> dx;
  52. cin.clear();
  53. cin.ignore(cin.rdbuf()->in_avail());
  54. cout << "a = ";
  55. cin >> a;
  56. if ((eps <= 0) || ((xstart != xend) && (dx == 0)) || ((xstart < xend) && (dx < 0)) || ((xstart > xend) && (dx > 0) || cin.fail()))
  57. {
  58. cout << "\nError!\nTry again\n\n";
  59. cin.clear();
  60. cin.ignore(cin.rdbuf()->in_avail());
  61. goto m1;
  62. }
  63. printf("_____________________________________________________________________________________\n");
  64. printf("|%16s|%4s%-20s|%24s|%16s|\n", "x", "My ", Name(), Name(), "Delta");
  65. printf("-------------------------------------------------------------------------------------\n");
  66. bool flag = dx > 0 ? true : false;
  67. for (double myf, f; cmp(xstart, xend, flag); xstart = round((xstart + dx) * 10000000) / 10000000)
  68. {
  69. myf = MyFunction(eps, a, xstart);
  70. f = Function(a, xstart);
  71. printf("|%16.7lf|%24.7lf|%24.7lf|%16.7lf|\n", xstart, myf, f, sqrt(fabs(myf * myf - f * f)));
  72. }
  73. printf("-------------------------------------------------------------------------------------\n");
  74. double xid;
  75. m2: cout << "x ideal = ";
  76. if (!(cin >> xid))
  77. {
  78. cout << "\nError!\nTry again\n\n";
  79. cin.clear();
  80. cin.ignore(cin.rdbuf()->in_avail());
  81. goto m2;
  82. }
  83. printf("_____________________________________________________________________________________\n");
  84. printf("|%16s|%4s%-20s|%24s|%16s|\n", "eps", "My ", Name(), Name(), "Delta");
  85. printf("-------------------------------------------------------------------------------------\n");
  86. for (double myf, f, eps = 0.1; eps >= 0.0000001; eps *= 0.1)
  87. {
  88. myf = MyFunction(eps, a, xid);
  89. f = Function(a, xid);
  90. printf("|%16.7lf|%24.7lf|%24.7lf|%16.7lf|\n", eps, myf, f, sqrt(fabs(myf*myf - f * f)));
  91. }
  92. printf("-------------------------------------------------------------------------------------\n");
  93. FreeLibrary(pdll);
  94. system("pause");
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement