Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
# Programmier Aufgaben

Hier findet ihr verschieden kleine Programmieraufgaben!
Alles hier gerade noch WIP, bald mehr.
Für Musterlösungen oder Aufgabenideen einfach anschreiben (Ron31#2338), ein Issue oder eine PR machen.
# Programming Tasks

## Inhalt:
- [**Leicht**](aufgaben-leicht)
- [Login](aufgaben-leicht/aufgabe01)
- [Zahlen raten](aufgaben-leicht/aufgabe02)
- [Trivia-Quiz](aufgaben-leicht/aufgabe03)
- [Towerdrop](aufgaben-leicht/aufgabe04)
- [Fibonacci](aufgaben-leicht/aufgabe05)
- [**Mittel**](aufgaben-mittel/)
- [Primfaktorzerlegung](aufgaben-mittel/aufgabe01)
- [**Schwer**](aufgaben-schwer/)
- [Chat Room](aufgaben-schwer/aufgabe01)
Deutsch: [/de](de/)
English: [/en](en/)
17 changes: 17 additions & 0 deletions de/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Programmier Aufgaben

Hier findet ihr verschieden kleine Programmieraufgaben!
Alles hier gerade noch WIP, bald mehr.
Für Musterlösungen oder Aufgabenideen einfach anschreiben (Ron31#2338), ein Issue oder eine PR machen.

## Inhalt:
- [**Leicht**](aufgaben-leicht)
- [Login](aufgaben-leicht/aufgabe01)
- [Zahlen raten](aufgaben-leicht/aufgabe02)
- [Trivia-Quiz](aufgaben-leicht/aufgabe03)
- [Towerdrop](aufgaben-leicht/aufgabe04)
- [Fibonacci](aufgaben-leicht/aufgabe05)
- [**Mittel**](aufgaben-mittel/)
- [Primfaktorzerlegung](aufgaben-mittel/aufgabe01)
- [**Schwer**](aufgaben-schwer/)
- [Chat Room](aufgaben-schwer/aufgabe01)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Zahlen Raten

Das Programm soll eine Zufällige Zahl, zunächst von 1 bis 100, generieren. Danach wird der Spieler zur Eingabe aufgefordert: Er soll di Zahl nun erraten. Gibt er eine zu hohe oder zu niedrige Zahl an, wird eine entsprechende Meldung ausgegeben. Ist die Zahl erraten, gibt da Programm dies aus und beendet sich selbst.
Das Programm soll eine Zufällige Zahl, zunächst von 1 bis 100, generieren. Danach wird der Spieler zur Eingabe aufgefordert: Er soll die Zahl nun erraten. Gibt er eine zu hohe oder zu niedrige Zahl an, wird eine entsprechende Meldung ausgegeben. Ist die Zahl erraten, gibt das Programm dies aus und beendet sich selbst.
Errät man die Zahl nicht, soll auch nach 10 Versuchen das Programm beendet werden.

Voraussetzungen:
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions en/easy-tasks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Easy tasks
23 changes: 23 additions & 0 deletions en/easy-tasks/task01/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Task 01

> Contributors: Ron31#2338, zekro#0001, Kaktushose#0436
> Last update: 2019/10/03

---

## Simple "Login System"

In the terminal (when you run the programm) you should first enter a username and then a password. If this matches, a message with: "You are now logged in" is displayed.

Conditions:

- For the example, there is the user `root` with the password `rootpw`.
- It must generally be possible for several users to log in with their passwords.

---

## Sample solutions

- [Python](solutions/python/1.py)
- [C++](solutions/cpp)
- [Java](solutions/java/Main.java)
34 changes: 34 additions & 0 deletions en/easy-tasks/task01/solutions/cpp/map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
This example describes a way using the std::map
library for saving username-password combinations
and checking them.
*/

#include <iostream>
#include <string>
#include <map>

int main() {

using namespace std;

map<string, string> users = {
{"root", "rootpw"}
};

string username, password;

cout << "Enter username: ";
cin >> username;

cout << "Enter password: ";
cin >> password;

if (users[username] == password) {
cout << "You are now logged in!";
return 0;
}

cout << "Wrong password";
return 1;
}
45 changes: 45 additions & 0 deletions en/easy-tasks/task01/solutions/cpp/native.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
This example describes the 'native' way of solving this
problem. So it does not use any external libraries (except
iostream and string).
*/

#include <iostream>
#include <string>

struct User {
std::string username;
std::string password;
};

int main() {

using namespace std;

User users[] = {
User{"root", "rootpw"},
};

string username, password;

cout << "Enter username: ";
cin >> username;

cout << "Enter password: ";
cin >> password;

bool pass = false;
for (int i = 0; i < sizeof(users) / sizeof(User); i++) {
if (users[i].username == username && users[i].password == password) {
pass = true;
}
}

if (pass) {
cout << "You are logged in.";
return 0;
}

cout << "Wrong password";
return 1;
}
21 changes: 21 additions & 0 deletions en/easy-tasks/task01/solutions/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.Map;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Map<String, String> userpws = Map.of("root", "rootpw");
Scanner scanner = new Scanner(System.in);

System.out.print("User: ");
String user = scanner.nextLine();

System.out.print("Password: ");
if (userpws.get(user).equals(scanner.nextLine())) {
System.out.println("Du bist nun eingeloggt");
} else {
System.out.println("Falsches Passwort");
}
}
}

12 changes: 12 additions & 0 deletions en/easy-tasks/task01/solutions/python/1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
userpws = {"root": "rootpw"}

print('User:')
user = input()

print('Password:')
password = input()

if (password == userpws.get(user)):
print('You are now logged in')
else:
print('Wrong password')
28 changes: 28 additions & 0 deletions en/easy-tasks/task02/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Task 02

> Contributors: Voxain#0001, Kaktushose#0436
> Last update: 2019/10/03

---

## Numbers guessing

The programm should generate a random number, initially from 1 to 100. Then the player is prompted to enter: He should now guess the number. If he enters a number that is too high or too low, a corresponding message is shown. If the rigth number is guessed, the programm outputs this and exits.
If the number is not guessed, the programm should also be terminated after 10 attempts.

Conditions:

- The number of attempts is set in advance
- After a successful guess of the number or the remaining attempts have been used, nothing more should happen except for a corresponding message to be send.

### Additional tasks

- You can choose the range in which the generated number lies
- After a certain number of attempts you get a hint. Examples of a hint: _The number is between x and y._

---

## Sample solutions

- [Python](solutions/python/python.py)
- [Java](solutions/java/Main.java)
35 changes: 35 additions & 0 deletions en/easy-tasks/task02/solutions/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Solution without extra tasks

import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;

public class Main {

public static void main(String[] args) {
int number = ThreadLocalRandom.current().nextInt(1, 101);
int attempts = 10;
Scanner scanner = new Scanner(System.in);

System.out.println("The number is between 1 and 100.");
System.out.println("You now have 10 tries to guess the number.");

while (attempts > 0) {
System.out.println("Remaining attemps: " + attempts);
System.out.print("Please enter the number you would like to guess: ");
int input = scanner.nextInt();
attempts--;

if (input == number) {
System.out.println("You guessed the number right!");
System.exit(0);
} else if (input < number) {
System.out.println("The number you entered was too low.");
} else {
System.out.println("The number you entered was too high.");
}
}
System.out.println("You have no more attempts left!");
scanner.close();
}
}

26 changes: 26 additions & 0 deletions en/easy-tasks/task02/solutions/python/python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Solution without extra tasks

import random

number = random.randint(1, 101)
attempts = 10
user_input = -1

print("The number is between 1 and 100.")
print("You now have 10 tries to guess the number.")

while(attempts > 0):
print("Remaining attemps: " + str(attempts))
user_input = int(input("Please enter the number you would like to guess: "))
attempts -= 1
print("")
if(user_input == number):
print("You guessed the number right!")
exit(0)
elif(user_input < number):
print("The number you entered was too low.")
elif(user_input > number):
print("The number you entered was too high.")

if(attempts <= 0):
print("You have no more attempts left!")
23 changes: 23 additions & 0 deletions en/easy-tasks/task03/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Task 03

> Contributors: Ron31#2338
> Last update: 2019/01/28

---

## Trivia Quiz

The user is asked various questions one after the other, to which he must give a correct answer.
One point is awarded for each correct answer.

### Additional tasks

- After x failed attempts, you are given answer options.
- The questions are loaded from a file, anyone can add new ones.
- If you give the right answer immediately, you get 3 points. If you give the wrong answer, you still have x attempts, but you get fewer points.

---

## Musterlösungen

- None available yet!
43 changes: 43 additions & 0 deletions en/easy-tasks/task04/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Task 04

> Contributors: Vale#5252
> Last update: 2019/01/24

---

## Towerdrop

This task is maybe a little more challenging. This is about programming a simulation. First of all, the user sets a height for a tower. From this a tower, a ball is then thrown down. We assume normal gravitational acceleration (9.81 m/s²) and that the ball has no initial velocity. Your program should
then output the height of the ball above the ground after 0, 1, 2, 3, 4 and 5 seconds.

**Keep in mind:** The ball should never fall "into" the ground. The end is at height 0.

Define a constant that stores the value of the gravitational acceleration (9.81).
To calculate how many metres the ball has fallen after x seconds, you can use the formula
`fall_distance = gravitational_acceleration * x_seconds² / 2`.

An example of the output:

```
Please enter the height of the tower in metres: 100
After 0 seconds, the ball is at 100 metres.
After 1 second, the ball is at 95.1 metres.
After 2 seconds, the ball is at 80.4 metres.
After 3 seconds, the ball is at 55.9 metres.
After 4 seconds, the ball is at 21.6 metres.
After 5 seconds, the ball has already hit the ground.
```

**Hints:**

- You must use simple functions in your programm.
- Your ball may not reach the ground in 5 seconds. That's fine.
- Loops are not a mandatory requirement.

---

## Sample solutions

- [C++](solutions/cpp/towerdrop.cpp)
- [Java](solutions/java/TowerDrop.java)
- [Python](solutions/python/towerdrop.py)
Loading