Converted everything to orgmode

converted everything to orgmode and added solution to the README files
This commit is contained in:
2025-03-31 08:40:43 +02:00
parent 8719f4c140
commit 88e0b5ed69
88 changed files with 1942 additions and 2989 deletions

View File

@@ -1,17 +0,0 @@
# Task
Let `a`, `b`, `c`, and `d` be variables of type `int`.
- Which of the following character sequences are valid expressions in the sense that they are accepted by a C++ Compiler? Explain your answer.
1. a = b = 5
1. 1 = a
1. ++a + b++
1. a + b = c + d
1. a = 2 b
Assume that all the variables have been defined and correctly initialized and that all expressions are completely independent from each other.
- For each of the expressions that you have identified as valid, decide whether the entire expression is an `lvalue` or an `rvalue`, and explain your decision.
- Determine the values of the expressions that you have identified as valid and explain how these values are obtained.

View File

@@ -0,0 +1,52 @@
#+TITLE: Task 1: Expressions
#+AUTHOR: JirR02
* Task
Let =a=, =b=, =c=, and =d= be variables of type =int=.
- Which of the following character sequences are valid expressions in the sense that they are accepted by a C++ Compiler? Explain your answer.
1. a = b = 5
1. 1 = a
1. ++a + b++
1. a + b = c + d
1. a = 2 b
Assume that all the variables have been defined and correctly initialized and that all expressions are completely independent from each other.
- For each of the expressions that you have identified as valid, decide whether the entire expression is an =lvalue= or an =rvalue=, and explain your decision.
- Determine the values of the expressions that you have identified as valid and explain how these values are obtained.
* Solution
#+begin_src md
# Task 1
---
### Expression 1: `a = b = 5`
The expression is valid and will be accepted by the CPP compiler. It will result with the l-values `a = 5` and `b = 5`. This is due to the fact the the `=` opperation is read from right to left so `b = 5` will run first and `a = b` afterwards.
### Expression 2: `1 = a`
The expression is invalid.
### Expression 3: `++a + b++`
The expression is valid and will be accepted by the CPP compiler. It will result in a r-value since the result is not assigned to a variable.
### Expression 4: `a + b = c + d`
The expression is invalid.
### Expression 5: `a = 2 b`
The expression is valid and will be accepted by the CPP compiler. It will result with the l-value `a = 2 b`. This is valid since a l-value can be a r-value.
#+end_src
-----
Made by JirR02 in Switzerland 🇨🇭

View File

@@ -1,23 +0,0 @@
# Task 1
---
### Expression 1: `a = b = 5`
The expression is valid and will be accepted by the CPP compiler. It will result with the l-values `a = 5` and `b = 5`. This is due to the fact the the `=` opperation is read from right to left so `b = 5` will run first and `a = b` afterwards.
### Expression 2: `1 = a`
The expression is invalid.
### Expression 3: `++a + b++`
The expression is valid and will be accepted by the CPP compiler. It will result in a r-value since the result is not assigned to a variable.
### Expression 4: `a + b = c + d`
The expression is invalid.
### Expression 5: `a = 2 b`
The expression is valid and will be accepted by the CPP compiler. It will result with the l-value `a = 2 b`. This is valid since a l-value can be a r-value.

View File

@@ -1,24 +0,0 @@
# Task
_This task is a text-based task but mostly automatically checked. You are required to write your answers into submission.txt by replacing the question marks with the correct solution. Please, do not change the line formating._
_You can check whether your solution is correct by clicking on the test button._
Numbers can be provided in various formats in C++. Literals prefixed with `0b` indicate binary encoding. Assume unsigned arithmetics with sufficient numbers of bits, i.e. no overflows. Convert the following binary numbers into decimal numbers (1-4) and decimal numbers to binary (5-8):
```txt
# Lines starting with # are comments. Spaces is ignored.
# Lines starting with a whitespace before # will not be a comment.
# Convert to decimal:
0b1 = ?
0b10 = ?
0b000001 = ?
0b101010 = ?
# Convert to binary:
7 = ?
11 = ?
28 = ?
1024 = ?
```

View File

@@ -0,0 +1,50 @@
#+TITLE: Task 2: Representation of Integers
#+AUTHOR: JirR02
* Task
/This task is a text-based task but mostly automatically checked. You are required to write your answers into =submission.txt= by replacing the question marks with the correct solution. Please, do not change the line formating./
/You can check whether your solution is correct by clicking on the test button./
Numbers can be provided in various formats in C++. Literals prefixed with =0b= indicate binary encoding. Assume unsigned arithmetics with sufficient numbers of bits, i.e. no overflows. Convert the following binary numbers into decimal numbers (1-4) and decimal numbers to binary (5-8):
#+begin_src txt
# Lines starting with # are comments. Spaces is ignored.
# Lines starting with a whitespace before # will not be a comment.
# Convert to decimal:
0b1 = ?
0b10 = ?
0b000001 = ?
0b101010 = ?
# Convert to binary:
7 = ?
11 = ?
28 = ?
1024 = ?
#+end_src
* Solutions
#+begin_src txt
# Lines starting with # are comments. Spaces are ignored.
# Lines starting with a whitespace before # will not be a comment.
# Convert to decimal:
0b1 = 1
0b10 = 2
0b000001 = 1
0b101010 = 42
# Convert to binary:
7 = 0b111
11 = 0b1011
28 = 0b11100
1024 = 0b10000000000
#+end_src
—----
Made by JirR02 in Switzerland 🇨🇭

View File

@@ -1,14 +0,0 @@
# Lines starting with # are comments. Spaces are ignored.
# Lines starting with a whitespace before # will not be a comment.
# Convert to decimal:
0b1 = 1
0b10 = 2
0b000001 = 1
0b101010 = 42
# Convert to binary:
7 = 0b111
11 = 0b1011
28 = 0b11100
1024 = 0b10000000000

View File

@@ -1,18 +0,0 @@
# Task
Write a program resistance.cpp that computes the equivalent resistance of the following wiring:
![circuit](./resistance.png)
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](https://en.wikipedia.org/wiki/Resistor#Series_and_parallel_resistors).
**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.

View File

@@ -0,0 +1,55 @@
#+TITLE: Task 3: Equivalent Resistance
#+AUTHOR: JirR02
* Task
Write a program resistance.cpp that computes the equivalent resistance of the following wiring:
[[./resistance.png]]
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 [[https://en.wikipedia.org/wiki/Resistor#Series_and_parallel_resistors][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.
* Solution
#+begin_src cpp
#include <iostream>
int main() {
int r1;
int r2;
int r3;
int r4;
int res;
std::cin >> r1;
std::cin >> r2;
std::cin >> r3;
std::cin >> r4;
int r12 = r1 + r2;
int r34 = r3 + r4;
res = (r12 * r34 + ((r12 + r34) / 2)) /
(r12 + r34); // By adding the average of r12 and r34, the result is
// increased enough to get the correct rounded number
std::cout << res;
return 0;
}
#+end_src
-—---
Made by JirR02 in Switzerland 🇨🇭

View File

@@ -1,25 +0,0 @@
#include <iostream>
int main() {
int r1;
int r2;
int r3;
int r4;
int res;
std::cin >> r1;
std::cin >> r2;
std::cin >> r3;
std::cin >> r4;
int r12 = r1 + r2;
int r34 = r3 + r4;
res = (r12 * r34 + ((r12 + r34) / 2)) /
(r12 + r34); // By adding the average of r12 and r34, the result is
// increased enough to get the correct rounded number
std::cout << res;
return 0;
}