Advertisement
MARSHAL327

Untitled

Dec 24th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <limits>
  5. #include <cmath>
  6. #include <stdlib.h>
  7. using namespace std;
  8.  
  9. class SqrtException {};
  10.  
  11. static void first() {
  12. double a = -99, b = -99, per, area;
  13. cout << "\na, b, c, d: ";
  14. while (true) {
  15. cin >> a;
  16. if (!cin) {
  17. cin.clear();
  18. cout << "error" << endl;
  19. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  20. }
  21. else {
  22. break;
  23. }
  24. }
  25. while (true) {
  26. cin >> b;
  27. if (!cin) {
  28. cout << "error";
  29. cin.clear(); // يà ٌëَ÷àé, هٌëè ïًهنûنَùèé ââîن çàâهًّèëٌے ٌ îّèلêîé
  30. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  31. }
  32. else {
  33. break;
  34. }
  35. }
  36. per = 2 * (a + b);
  37. area = a * b;
  38.  
  39. ofstream fout("lab8.txt");
  40. cout << setfill('#') << setprecision(5) << setw(15) << per << "\n";
  41. cout << setfill('#') << setprecision(5) << setw(15) << area;
  42. fout << setfill('#') << setprecision(5) << setw(15) << per << "\n";
  43. fout << setfill('#') << setprecision(5) << setw(15) << area;
  44. fout.close();
  45.  
  46. }
  47.  
  48. static void second() {
  49. double x;
  50. cout << "\n x: ";
  51. while (true) {
  52. cin >> x;
  53. if (!cin) {
  54. cout << "error";
  55. cin.clear();
  56. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  57. }
  58. else {
  59. try {
  60. if (x <= 8) {
  61. throw SqrtException();
  62. }
  63. else
  64. break;
  65. }
  66. catch (SqrtException & s) {
  67. cout << "x > 8.\n";
  68. }
  69. }
  70. }
  71.  
  72. cout << 12 * x + sqrt(x - 8);
  73.  
  74. }
  75.  
  76. int main() {
  77. cout << "//زا:\n//1.\tLp and Spr.\n"
  78. "//2.\tS= ." << endl;
  79.  
  80. first();
  81. second();
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement