Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. const char CDfd[] = "duom.txt";
  9. const char CDfr[] = "rez.txt";
  10. const int CMax = 24;
  11.  
  12. void Skaityti (const char CDfd[], int A[], double B[], int& n);
  13. void Spausdinti (const char CDfr[], int A[], double B[], int n);
  14.  
  15. int AuksciausiaTemp (double B[], int n);
  16. void SpausdintiAukstaTemp (const char CDfr[], int A[], double B[], int n, double max);
  17.  
  18. int main()
  19. {
  20. int V[CMax];
  21. double T[CMax];
  22. int n;
  23.  
  24. ofstream fr(CDfr, ios::app);
  25.  
  26. Skaityti (CDfd, V, T, n);
  27. Spausdinti (CDfr, V, T, n);
  28. int indmax = AuksciausiaTemp (T, n);
  29.  
  30. fr << "Auksciausia temperatura " << T[indmax] << " buvo " << V[indmax] << " val." << endl;
  31.  
  32. SpausdintiAukstaTemp(CDfr, V, T, n, T[indmax]);
  33.  
  34. fr.close();
  35. return 0;
  36. }
  37.  
  38. void Skaityti (const char CDfd[], int A[], double B[], int& n)
  39. {
  40. ifstream fd(CDfd);
  41. fd >> n;
  42. for (int i = 0; i < n; i++)
  43. fd >> A[i] >> B[i];
  44. fd.close();
  45. }
  46.  
  47. void Spausdinti (const char CDfr[], int A[], double B[], int n)
  48. {
  49. ofstream fr(CDfr);
  50. fr << " Ligonio temperatura " << endl;
  51. fr << "---------------------" << endl;
  52. fr << " Valanda Temperatura " << endl;
  53. fr << "---------------------" << endl;
  54. for (int i = 0; i < n; i++)
  55. fr << setw(5) << A[i] << " " << fixed << setw(2) << setprecision(1) << B[i] << endl;
  56. fr << "---------------------" << endl;
  57. fr.close();
  58. }
  59.  
  60. int AuksciausiaTemp (double B[], int n)
  61. {
  62. double max = B[0];
  63. int maxind = 0;
  64. for (int i = 1; i < n; i++)
  65. if (B[i] > max){
  66. max = B[i];
  67. maxind = i;
  68. }
  69. return maxind;
  70. }
  71.  
  72. void SpausdintiAukstaTemp (const char CDfr[], int A[], double B[], int n, double max)
  73. {
  74. ofstream fr(CDfr, ios::app);
  75. fr << "Auksta temperatura dar buvo:" << endl;
  76. for (int i = 0; i < n; i++)
  77. if (fabs(max - B[i]) <= 0.5)
  78. fr << A[i] << " val. " << B[i] << endl;
  79. fr.close();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement