Guest User

Untitled

a guest
Dec 28th, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <Windows.h>
  4. #include <fstream>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8. using std::cout;
  9.  
  10. int chkdsk();
  11. int fldsk();
  12. int choice;
  13. int n;
  14. double x;
  15. double y;
  16. double a, b, h;
  17.  
  18. void main()
  19. {
  20. next:
  21. bool
  22. {
  23. cout << endl
  24. << "1. Input data from keyboard and calculate result\n"
  25. << "2. Input data from file and calculate result\n"
  26. << "3. Save result to file\n"
  27. << "4. Help!\n"
  28. << "5. Exit program\n"
  29. << "\n" << "Make your choice and press 'Enter': "
  30. };
  31.  
  32.  
  33. cin >> choice;
  34.  
  35. switch (choice)
  36. {
  37. case 1: /* A line to input data from keyboard and calculate result */
  38. {
  39. do chkdsk();
  40. while (n < 4);
  41. goto next;
  42. }
  43. case 2: /* Input data from file and calculate result */
  44. {
  45. fldsk();
  46. goto next;
  47. }
  48. case 3: /* That what lets you to output your data to a certain directory */
  49. {
  50. ofstream file("output.txt", ios::out | ios::app);
  51. file << x << "\n" << y << endl;
  52. cout << "Writing this to a file..." << endl;
  53. Sleep(1000);
  54. }
  55. goto next;
  56. case 4: /* Just some additional information – FAQ and Credits */
  57. int choice_2;
  58. bool
  59. {
  60. cout << "\n" << "1. FAQ\n" << "2. Author credits\n"
  61. };
  62.  
  63. cout << "\n";
  64. cin >> choice_2;
  65. cout << "\n";
  66.  
  67. switch (choice_2)
  68. {
  69. case 1: /* FAQ */
  70. cout << "\t\t\tFAQ for the main menu\n"
  71. << "1. To make input from keyboard and calculate your result, please, press '1'. \n"
  72. << "2. To make input from file and calculate the result, press '2'. \n"
  73. << "3. To save the result into file, press '3'. \n"
  74. << "4. To see some additional information and author credits, press '4'. In the following menu, choose between '1' and '2'. \n"
  75. << "5. Press '5' if you want to exit the program. \n";
  76. cout << endl;
  77. system("pause");
  78. goto next;
  79. case 2: /* Author Credits */
  80. cout << "The program was written and compiled by Maidebura D., group CS-36zh, 2016.\n";
  81. cout << endl;
  82. system("pause");
  83. goto next;
  84. }
  85. case 5: /* Exit from program */
  86. cout << "\nE"; Sleep(100); cout << "n"; Sleep(100); cout << "d"; Sleep(100);
  87. cout << " o"; Sleep(100); cout << "f"; Sleep(100);
  88. cout << " p"; Sleep(100); cout << "r"; Sleep(200); cout << "o"; Sleep(200); cout << "g"; Sleep(200); cout << "r"; Sleep(200); cout << "a"; Sleep(200); cout << "m";
  89. Sleep(500);
  90. cout << ".";
  91. Sleep(500);
  92. cout << ".";
  93. Sleep(500);
  94. cout << ".";
  95. break;
  96. default:
  97. for (choice > 5; choice < 0; )
  98. {
  99. cout << "\nNot a valid choice \n"
  100. << "Choose again \n";
  101. main();
  102. system("pause");
  103. }
  104. break;
  105. }
  106. }
  107. int chkdsk()
  108. {
  109. double a, b, h;
  110. cout << "Type a, b, h, n: " << endl;
  111. cin >> a >> b >> h >> n;
  112. if (n < 4)
  113. {
  114. cout << "error" << endl;
  115. }
  116. else
  117. {
  118. for (x = a; x <= b; x = x + h)
  119. {
  120. if (x >= 0)
  121. {
  122. y = 0;
  123. for (int i = 0; i <= n - 1; i++)
  124. {
  125. double z = 1;
  126. for (int j = 0; j <= n - 1; j++)
  127. {
  128. z = z*(x + i + j*j);
  129. }
  130. y = y + z;
  131. }
  132. }
  133. else
  134. {
  135. y = 1;
  136. for (int j = 2; j <= n - 2; j++)
  137. {
  138. y = y*(j + 1);
  139. }
  140. }
  141. cout << "x = " << x << endl;
  142. cout << "y = " << y << endl;
  143. }
  144. }
  145. system("pause");
  146. return (0);
  147. }
  148.  
  149. int fldsk()
  150. {
  151. ifstream file("input.txt", ios::app);
  152. {
  153. double a, b, h;
  154. int n;
  155. file >> a >> b >> h >> n;
  156. try
  157. {
  158. if (n < 4)
  159. {
  160. throw n;
  161. }
  162. else
  163. {
  164. for (x = a; x <= b; x = x + h)
  165. {
  166. if (x >= 0)
  167. {
  168. y = 0;
  169. for (int i = 0; i <= n - 1; i++)
  170. {
  171. double z = 1;
  172. for (int j = 0; j <= n - 1; j++)
  173. {
  174. z = z*(x + i + j*j);
  175. }
  176. y = y + z;
  177. }
  178. }
  179. else
  180. {
  181. y = 1;
  182. for (int j = 2; j <= n - 2; j++)
  183. {
  184. y = y*(j + 1);
  185. }
  186. }
  187. cout << "x = " << x << endl;
  188. cout << "y = " << y << endl;
  189. }
  190. }
  191. cout << endl;
  192. system("pause");
  193. return (0);
  194. }
  195. catch (double)
  196. {
  197. string c = "the value of n must be greater than or equal to 4\n";
  198. throw c;
  199. return 0;
  200. }
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment