Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int rows = 0;
  10. float x = 0.0;
  11. float increment = 0.0;
  12. float ex = 0.0;
  13. float lo = 0.0;
  14. float sq = 0.0;
  15.  
  16.  
  17. int triesInMax = 0;
  18. int triesInError = 0;
  19. int const TRIESMAX = 5;
  20. int const TRIESERROR = (TRIESMAX - 1);
  21. int const TRIESDONE = 0;
  22. int const ROWMIN = 0;
  23. int const ROWMAX = 35;
  24. float const XMIN = 0.0;
  25. float const XMAX = 100.0;
  26. float const INCMIN = 0.0;
  27.  
  28.  
  29. triesInMax = TRIESMAX;
  30. triesInError = TRIESERROR;
  31.  
  32. while(rows <= ROWMIN || rows > ROWMAX)
  33. {
  34. if(triesInMax <= triesInError && triesInMax > TRIESDONE)
  35. {
  36. cout << "The number you entered was invalid, TRY AGAIN: " << endl;
  37. }
  38.  
  39. cout << "Enter the number of rows in the table to be produced " << endl << "The number of rows must be between " << ROWMIN << " and " << ROWMAX << endl;
  40. cin >> rows;
  41. triesInMax--;
  42.  
  43. if(triesInMax <= TRIESDONE)
  44. {
  45. cerr << "ERROR, ATTEMPTED TOO MANY TIMES!";
  46. return 1;
  47. }
  48. }
  49.  
  50.  
  51. triesInMax = TRIESMAX;
  52. triesInError = TRIESERROR;
  53.  
  54.  
  55. while(x == XMIN || abs(x) > XMAX)
  56. {
  57. if(triesInMax <= triesInError && triesInMax > TRIESDONE)
  58. {
  59. cout << "The number you entered was too large, TRY AGAIN: " << endl;
  60. }
  61.  
  62. cout << "Enter the starting X " << endl << "The starting x must satisfy |X| " << fixed << setprecision(0) << XMAX << endl;
  63. cin >> x;
  64. triesInMax--;
  65.  
  66. if(x == XMIN)
  67. {
  68. break;
  69. }
  70.  
  71. if(triesInMax <= TRIESDONE)
  72. {
  73. cerr << "ERROR, ATTEMPTED TOO MANY TIMES!";
  74. return 2;
  75. }
  76.  
  77. }
  78.  
  79.  
  80. triesInMax = TRIESMAX;
  81. triesInError = TRIESERROR;
  82.  
  83.  
  84. while(increment <= INCMIN)
  85. {
  86. if(triesInMax <= triesInError && triesInMax > TRIESDONE)
  87. {
  88. cout << "The number you entered was invalid, TRY AGAIN: " << endl;
  89. }
  90.  
  91. cout << "Enter the increment in X between successive rows " << endl << "The increment in X must be positive " << endl;
  92. cin >> increment;
  93. triesInMax--;
  94.  
  95. if(triesInMax <= TRIESDONE)
  96. {
  97. cerr << "ERROR, ATTEMPTED TOO MANY TIMES!";
  98. return 3;
  99. }
  100. }
  101.  
  102.  
  103. cout << endl << endl << endl << endl << fixed << setw(9) << right << "X" << setw(17) << "exp(X)" << setw(16) << "log10(X)" << setw(15) << "sqrt(X)" << endl;
  104.  
  105.  
  106. while(rows > ROWMIN)
  107. {
  108.  
  109. cout << fixed << right << setw(12) << setprecision(3) << x;
  110.  
  111. ex = exp(x);
  112. cout << fixed << right << setw(15) << setprecision(2) << scientific << ex;
  113.  
  114. if(x <= XMIN)
  115. {
  116. cout << fixed << right << setw(15) << "undef";
  117. }
  118. else
  119. {
  120. lo = log10(x);
  121. cout << fixed << right << setw(15) << setprecision(5) << lo;
  122. }
  123.  
  124. sq = sqrt(abs(x));
  125. cout << fixed << right << setw(15) << setprecision(5) << sq;
  126.  
  127. if(x <= XMIN)
  128. {
  129. cout << "i";
  130. }
  131.  
  132. cout << endl;
  133.  
  134. x += increment;
  135.  
  136. rows--;
  137.  
  138. }
  139.  
  140.  
  141.  
  142. return 0;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement