Advertisement
Guest User

Untitled

a guest
Jan 9th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. #include <Windows.h>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. void typing();
  9. void reading();
  10. double chkdsk();
  11. int choice;
  12. int n;
  13. double x;
  14. double y;
  15. double a, b, h;
  16. double greater();
  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. typing();
  40. chkdsk();
  41. goto next;
  42. }
  43. case 2: /* Input data from file and calculate result */
  44. {
  45. reading();
  46. chkdsk();
  47. goto next;
  48. }
  49. case 3: /* That what lets you to output your data to a certain directory */
  50. {
  51. ofstream file("output.txt", ios::app);
  52. file << "x = " << x << "\n" << "y = " << y << endl;
  53. cout << "Writing this to a file..." << endl;
  54. Sleep(1000);
  55. file.close();
  56. }
  57. goto next;
  58. case 4: /* Just some additional information – FAQ and Credits */
  59. int choice_2;
  60. bool
  61. {
  62. cout << "\n" << "1. FAQ\n" << "2. Author credits\n"
  63. };
  64.  
  65. cout << "\n";
  66. cin >> choice_2;
  67. cout << "\n";
  68.  
  69. switch (choice_2)
  70. {
  71. case 1: /* FAQ */
  72. cout << "\t\t\tFAQ for the main menu\n"
  73. << "1. To make input from keyboard and calculate your result, please, press '1'. \n"
  74. << "2. To make input from file and calculate the result, press '2'. \n"
  75. << "3. To save the result into file, press '3'. \n"
  76. << "4. To see some additional information and author credits, press '4'. In the following menu, choose between '1' and '2'. \n"
  77. << "5. Press '5' if you want to exit the program. \n";
  78. cout << endl;
  79. system("pause");
  80. goto next;
  81. case 2: /* Author Credits */
  82. cout << "The program was written and compiled by Maidebura D., group CS-36zh, 2016.\n";
  83. cout << endl;
  84. system("pause");
  85. goto next;
  86. }
  87. case 5: /* Exit from program */
  88. {
  89. cout << "\nE"; Sleep(100); cout << "n"; Sleep(100); cout << "d"; Sleep(100);
  90. cout << " o"; Sleep(100); cout << "f"; Sleep(100);
  91. 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";
  92. Sleep(500);
  93. cout << ".";
  94. Sleep(500);
  95. cout << ".";
  96. Sleep(500);
  97. cout << ".";
  98. break;
  99. }
  100. default:
  101. cout << "\nNot a valid choice \n" << "Choose again \n";
  102. goto next;
  103. system("pause");
  104. }
  105. }
  106.  
  107. double chkdsk()
  108. {
  109. try
  110. {
  111. if (n < 4)
  112. {
  113. throw "error";
  114. }
  115. else
  116. {
  117. for (x = a; x <= b; x = x + h)
  118. {
  119. if (x >= 0)
  120. {
  121. y = 0;
  122. greater();
  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. if (x < 0)
  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. cout << endl;
  146. system("pause");
  147. return (0);
  148. }
  149. catch (double)
  150. {
  151. string c = "the value of n must be greater than or equal to 4\n";
  152. throw c;
  153. }
  154. return 0;
  155. }
  156.  
  157. double greater()
  158. {
  159. try
  160. {
  161. if (a > b)
  162. throw a;
  163. }
  164. catch (double)
  165. {
  166. cout << "\nA must be greater than B\n";
  167. return 0;
  168. }
  169. }
  170.  
  171. void reading()
  172. {
  173. ifstream file("input.txt", ios::app);
  174. file >> a >> b >> h >> n;
  175. }
  176.  
  177. void typing()
  178. {
  179. cout << "Type a, b, h, n: " << endl;
  180. cin >> a >> b >> h >> n;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement