Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- typedef double(*func) (double, double);
- double func_y(double a, double n) {
- return exp(a * 2);
- }
- double func_s(double a, double n) {
- double k = 1, summ = 1, r = 1;
- do
- {
- r = r * 2 * a / k;
- summ += r;
- k++;
- } while (k <= n);
- return summ;
- }
- double func_fabs( double a, double n) {
- return fabs(func_y(a, n) - func_s(a, n));
- }
- void rez(func f, double a, double b, double h, double n) {
- for (a; a < b; a += h) cout << fixed << "x = " << a << "\tFunction = " << setprecision(7) << f(a, n) << endl;
- }
- int main()
- {
- double a, b, h, n;
- char k;
- cout << "Enter a, b, h, n" << endl;
- cin >> a >> b >> h >> n;
- while (true) {
- cout << "What to do?" << endl << "1. Display the function Y(x)" << endl << "2. Display the function S(x)" << endl << "3. Display |Y(x)-S(X)|" << endl << "4. Press 'e' to exit the program" << endl;
- cin >> k;
- switch (k) {
- case '1': default: {
- cout << "Function Y(x)" << endl;
- rez(func_y, a, b, h, n);
- cout << endl;
- break;
- }
- case '2': {
- cout << "Function S(x)" << endl;
- rez(func_s, a, b, h, n);
- cout << endl;
- break;
- }
- case '3': {
- cout << "Function |Y(x)-S(X)|" << endl;
- rez(func_fabs, a, b, h, n);
- cout << endl;
- break;
- }
- case 'e': case 'E': return 11;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement