2025-02-20 23:51:20 +01:00
..
2025-02-20 23:51:20 +01:00
2025-02-20 23:51:20 +01:00
2025-02-20 23:51:20 +01:00

Task

Write a program resistance.cpp that computes the equivalent resistance of the following wiring:

circuit

We assume that R_1, R_2, R_3, and R_4 have an integer valued resistance. After input of the four values, the program should output the result arithmetically rounded to the nearest integer.

Remark: In order to facilitate the task, you may want to:

  • Conceptually divide the task into sub tasks. For example, start with computation of serial resistors R_{12} and R_{34}.
  • Solve the task first naively using default rounding and then think about how to accomplish arithmetic rounding. Recall that \text{round}(x) = [x + 0.5] \text{ }\forall \text{ } x \in \mathbb{R}, i.e., a real number can be rounded arithmetically by adding 0.5 to it and then rounding down. For example, \text{round}(8,6) = [8.6 + 0.5] = [9.1] = 9.

You can find formulas for computing the total resistance in this Wikipedia article.

Important: using anything other than int (e.g., floating point numbers, long, or double long) is forbidden.

Important: using if-else and any other branches is forbidden.