Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <windows.h>
- using namespace std;
- bool cmp(int xstart, int xend, bool f)
- {
- if (f)
- return xstart <= xend;
- else
- return xstart >= xend;
- }
- int main()
- {
- typedef double(*myf_1)(double, double, double);
- typedef double(*myf_math)(double, double);
- typedef const char*(*FName)();
- if (!(LoadLibraryEx(L"lab9dll.dll", 0, LOAD_LIBRARY_AS_DATAFILE)))
- {
- cout << "Library loading error" << endl;
- system("pause");
- exit(0);
- }
- HINSTANCE pdll = LoadLibrary(L"lab9dll.dll");
- myf_1 MyFunction = (myf_1)GetProcAddress(pdll, "myf_1");
- myf_math Function = (myf_math)GetProcAddress(pdll, "myf_math");
- FName Name = (FName)GetProcAddress(pdll, "FName");
- if (!(pdll && MyFunction && Function && Name))
- {
- cout << "Unknown functions" << endl;
- system("pause");
- exit(0);
- }
- m1: double eps = 0, xstart = 0, xend = 0, dx = 1, a = -1;
- cout << "eps = ";
- cin >> eps;
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- cout << "x start = ";
- cin >> xstart;
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- cout << "x end = ";
- cin >> xend;
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- cout << "dx = ";
- cin >> dx;
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- cout << "a = ";
- cin >> a;
- if ((eps <= 0) || ((xstart != xend) && (dx == 0)) || ((xstart < xend) && (dx < 0)) || ((xstart > xend) && (dx > 0) || cin.fail()))
- {
- cout << "\nError!\nTry again\n\n";
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- goto m1;
- }
- printf("_____________________________________________________________________________________\n");
- printf("|%16s|%4s%-20s|%24s|%16s|\n", "x", "My ", Name(), Name(), "Delta");
- printf("-------------------------------------------------------------------------------------\n");
- bool flag = dx > 0 ? true : false;
- for (double myf, f; cmp(xstart, xend, flag); xstart = round((xstart + dx) * 10000000) / 10000000)
- {
- myf = MyFunction(eps, a, xstart);
- f = Function(a, xstart);
- printf("|%16.7lf|%24.7lf|%24.7lf|%16.7lf|\n", xstart, myf, f, sqrt(fabs(myf * myf - f * f)));
- }
- printf("-------------------------------------------------------------------------------------\n");
- double xid;
- m2: cout << "x ideal = ";
- if (!(cin >> xid))
- {
- cout << "\nError!\nTry again\n\n";
- cin.clear();
- cin.ignore(cin.rdbuf()->in_avail());
- goto m2;
- }
- printf("_____________________________________________________________________________________\n");
- printf("|%16s|%4s%-20s|%24s|%16s|\n", "eps", "My ", Name(), Name(), "Delta");
- printf("-------------------------------------------------------------------------------------\n");
- for (double myf, f, eps = 0.1; eps >= 0.0000001; eps *= 0.1)
- {
- myf = MyFunction(eps, a, xid);
- f = Function(a, xid);
- printf("|%16.7lf|%24.7lf|%24.7lf|%16.7lf|\n", eps, myf, f, sqrt(fabs(myf*myf - f * f)));
- }
- printf("-------------------------------------------------------------------------------------\n");
- FreeLibrary(pdll);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement