Advertisement
Week045

ЭП

Oct 18th, 2022
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. double theSteinhartHartformula(double);
  7. const int N = 2; //number of columns
  8.  
  9. int main() {
  10.     setlocale(LC_ALL, "Russian");
  11.     double* resistance = new double[N];
  12.     double* temperature = new double[N];
  13.     //-------------enterAndCalculation-----------------
  14.     for (int i = 0; i < N; i++) {
  15.         cout << "Write a " << i + 1 << "th resistance: ";
  16.         cin >> resistance[i];
  17.         temperature[i] = theSteinhartHartformula(resistance[i]);
  18.     }
  19.     //-------------display-------------------
  20.     system("CLS");
  21.     cout << setw(6) << "R,Ом |"
  22.         << setiosflags(ios::fixed)
  23.         << setiosflags(ios::showpoint);
  24.     for (int i = 0; i < N; i++) {
  25.             cout << setprecision(3)
  26.             << setw(9) << resistance[i] << "|";
  27.     }
  28.     cout << endl;
  29.     cout << setw(6) << "t,°C |";
  30.     for (int i = 0; i < N; i++) {
  31.             cout << setprecision(3)
  32.             << setw(9) << temperature[i] << "|";
  33.     }
  34.     delete[] resistance;
  35.     delete[] temperature;
  36.     return 0;
  37. }
  38.  
  39. double theSteinhartHartformula(double resistance) {
  40.     double A = 1.5524e-3;
  41.     double B = 2.4142e-4;
  42.     double C = 9.62e-8;
  43.     double T, t;
  44.     T = 1 / (A + B * log(resistance) + C * pow(log(resistance), 3));
  45.     t = T - 273;
  46.     return t;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement