Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2017
    Posts
    1
    Rep Power
    0
    cảm ơn xư huynh nhiều hé
  2. #17
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,893
    Rep Power
    509
    Please, vask0, post your solution to this challenging problem.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2017
    Posts
    11
    Rep Power
    0
    I came to this conclusion...

    Code:
    #include<iostream>
    
    #define DIM(A) (sizeof(A)/sizeof(*(A)))
    #define ABS(A) ((A) < 0 ? -(A) : (A))
    #define MIN(A, B) ((A) < (B) ? (A) : (B))
    
    struct {
      double V2, V1, dB_expected;
    } test[] = {
      {0.100,   9.600,    -39.6454246607913632},
      {0.600,   9.100,    -23.6178028387490002},
      {1.100,   8.600,    -17.8621153217068525},
      {1.600,   8.100,    -14.0873007244544990},
      {2.100,   7.600,    -11.1718859509374404},
      {2.600,   7.100,     -8.7257000149651454},
      {3.100,   6.600,     -6.5636448341519182},
      {3.600,   6.100,     -4.5805466848695939},
      {4.100,   5.600,     -2.7080834057292984},
      {4.600,   5.100,     -0.8962468883272455},
      {5.100,   4.600,      0.8962468883272461},
      {5.600,   4.100,      2.7080834057292993},
      {6.100,   3.600,      4.5805466848695939},
      {6.600,   3.100,      6.5636448341519182},
      {7.100,   2.600,      8.7257000149651454},
      {7.600,   2.100,     11.1718859509374404},
      {8.100,   1.600,     14.0873007244544972},
      {8.600,   1.100,     17.8621153217068525},
      {9.100,   0.600,     23.6178028387489967},
      {9.600,   0.100,     39.6454246607913632},
    };
    
    int tolerant_equal(double a, double b, double relerr, double abserr) {
      double abserris = ABS(a - b);
      return (abserris < MIN(ABS(a), ABS(b)) * relerr) || (abserris < abserr);
    }
    
    // функционалния децибел. което редават се аргументите V2 и V1 в този ред.
    double decibel(double, double);
    
    int main() {
      double V1, V2, expect, got;
      unsigned i, errors = 0;
      for (i = 0; i < DIM(test); ++i) {
        V1 = test[i].V1;
        V2 = test[i].V2;
        expect = test[i].dB_expected;
    
        if (! tolerant_equal(got, expect, 1e-5, 1e-4)) {
          ++errors;
          std::cout << "decibel(" << V2 << ", " << V1 << ") gave " << got << " expected " << expect << '\n';
        }
      }
      return errors;
    }
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2017
    Posts
    11
    Rep Power
    0
    Here is another task that needs to be done on the C++

    Create a program to enter the natural number n and the real number a from the keyboard. The program calculates and outputs an.

    Hair ideas code ?
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2017
    Posts
    11
    Rep Power
    0
    task 2

    Write a program that inserts a natural number from the keyboard. If the number has a corresponding number in the Roman numeral system, the program outputs the symbol that specifies that number. Otherwise, get an appropriate message.

    Arabic Number 1 5 10 50 100 500 1000

    Roman numeral I V X L C D M

    10x!!!!
  10. #21
  11. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,893
    Rep Power
    509
    Thank you for posting your final effort. You changed the language of the comment and removed the actual call to the decibel function. If you ran the program you didn't bother to notice that all the tests fail.
    Nor does your program meet the original specification:
    Write a program that inputs values V1, V2 from the keyboard and calculates the ratio of V1 / V2 in dB by the formula
    dB = 20 lg (V2 / V1) for V2> 0; V1> 0
    I was rather horrified thinking you might have fooled me into doing your homework. I hope your teaching assistant pays closer attention than you have. Fool me twice, shame on me.
    [code]Code tags[/code] are essential for python code and Makefiles!
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo