Advertisement
Guest User

question

a guest
May 27th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip> //for output formatting
  3. #include <fstream> //for file operations
  4. #include <cmath> //for maths functions
  5.  
  6. using namespace std;
  7.  
  8. //Define Function
  9. double function_18339286(int);
  10.  
  11. int main()
  12.  
  13.  
  14.  
  15.  
  16. {
  17.  
  18. int N;
  19. double y;
  20.  
  21.  
  22. //Question (b) i:
  23. //Ask user to enter value for N
  24. do {
  25. cout << "Enter a value for N (N must be an integer greater than 0): " << endl;
  26. cin >> N;
  27. } while (N < 0);
  28.  
  29.  
  30.  
  31. //Part ii
  32. y=function_18339286(N);
  33. cout << "\nThe value of y is equal to ";
  34. cout << fixed << showpoint << setprecision(4) << y << endl;
  35.  
  36. //Part iii
  37. ofstream output;
  38. output.open("function_output.txt");
  39.  
  40. for (int N = 1; N <= 5; N++)
  41. {
  42. y = function_18339286(N);
  43. cout << "\nThe value of y is equal to ";
  44. cout << fixed << showpoint << setprecision(4) << y << endl;
  45. output << fixed << showpoint << setprecision(4) << y << endl;
  46. }
  47.  
  48. output.close();
  49.  
  50.  
  51.  
  52. system("pause");
  53.  
  54. return (0);
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. double function_18339286(int N)
  62. {
  63. return (N+0.5)/(N^2+1);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement