Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. #include <iomanip>
  5. #include <string>
  6. #include <stdlib.h>
  7.  
  8. using namespace std;
  9. float *evaluate ();
  10. void  display ();
  11. void  Min_Max(float *);
  12. int main()
  13. {
  14. float *p;
  15.  
  16.  
  17.     evaluate();
  18.     display();
  19.  
  20. cin.get();
  21.  
  22. p = evaluate();
  23. Min_Max(p);
  24.  
  25.  
  26.     return 0;
  27. }
  28.  
  29. float *evaluate()
  30. {
  31.   ofstream Out_File("result.txt");
  32.   int n=30;
  33.   float x [n];
  34.   float fx[n];
  35.   float interval = ((4-(-2))/0.2);
  36.   x[0]= -2.0;
  37.  
  38.     for(n=0;n <= interval;n++)
  39.     {
  40.         fx[n] = 4*exp((-x[n])/2)*sin((2*x[n]- 0.3)*3.14159/180);
  41.         x[n+1] = x[n] + 0.2;
  42.  
  43.        if (Out_File.is_open())
  44.         {
  45.             Out_File <<setprecision(5)<<setw(8)<<showpoint<<fixed<< x[n];
  46.             Out_File << "\t\t"<<setprecision(5)<<setw(8)<<showpoint<<fixed<<fx[n]<<endl;
  47.         }
  48.        else cout << "Unable to open file";
  49.     }
  50.     Out_File.close();
  51. return fx;
  52. }
  53.  
  54. void display()
  55. {
  56.       ifstream inFile;
  57.     inFile.open("result.txt");
  58.     string line;
  59.     cout << "    x\t\t\t   f(x)"<<endl;
  60.     cout << "_______________________________________"<<endl;
  61.         while( getline (inFile,line))
  62.         {
  63.             cout<<line<<endl;
  64.         }
  65.  
  66.     inFile.close();
  67.  
  68. }
  69.  
  70. void Min_Max(float *value)
  71. {
  72.     int a=0;
  73.     for(a=0;a<=30;a++){
  74.         cout << *(value+a) <<endl;
  75.         *value =0;}
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement