Advertisement
Soverein

Untitled

Mar 4th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include <windows.h>
  4. #include<stdlib.h>
  5. #include<math.h>
  6. using namespace std;
  7. int main()
  8. {
  9. SetConsoleOutputCP(1251);
  10. SetConsoleCP(1251);
  11.  
  12. float mas[10];
  13. float temp, temp1;
  14. ofstream myfile;
  15. myfile.open("Stepin.txt");
  16. if (!(myfile.is_open()))
  17. {
  18. cout << "file not found\n";
  19. cout << "exit";
  20. cin.get(); //Это если окошко сразу закрывается, задерживаем
  21. return -1;
  22. }
  23. else
  24. {
  25. float NUM;
  26.  
  27. for (int i = 0; i < 10; ++i)
  28. {
  29. NUM = (rand() % 210 - 100) / 10.0;
  30. mas[i] = NUM;
  31. cout << mas[i]<<"\t ";
  32. myfile << mas[i]<<" ";
  33. }
  34. cout << "\n";
  35. }
  36. ofstream neg;
  37. neg.open("NEG.txt");
  38. if (!(neg.is_open()))
  39. {
  40. cout << "File not found";
  41. cout << "exit";
  42. cin.get(); //Это если окошко сразу закрывается, задерживаем
  43. return -1;
  44. }
  45. else
  46. {
  47. temp = 0;
  48. for (int i = 0; i < 10; ++i)
  49. {
  50. if (mas[i] < 0)
  51. {
  52. cout << mas[i] << "\t ";
  53. ++temp;
  54. neg << mas[i] << "\t";
  55. }
  56. }
  57. cout << "\ntemp= " << temp<<endl;
  58. neg<< "\ntemp= " << temp;
  59. }
  60. ofstream pos;
  61. pos.open("POS.txt");
  62. if (!(pos.is_open()))
  63. {
  64. cout << "File not found";
  65. cout << "exit";
  66. cin.get(); //Это если окошко сразу закрывается, задерживаем
  67. return -1;
  68. }
  69. else
  70. {
  71. temp1 = 0;
  72. for (int i = 0; i < 10; ++i)
  73. {
  74. if (mas[i] > 0)
  75. {
  76. cout << mas[i] << "\t ";
  77. ++temp1;
  78. pos << mas[i] << "\t";
  79. }
  80. }
  81. cout << "\ntemp1= " << temp1;
  82. pos << "\ntemp1= " << temp1;
  83. }
  84. myfile.close();
  85. pos.close();
  86. neg.close();
  87. return 0 ;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement