Previous sheets

Chapter 01 - Basics

Start time:
Mi 31 Jan 2018 09:50:53
End time:
So 06 Mai 2018 09:45:53

Assignments 8

Task 01 - Hello World! (Slides 14-26)
Create and launch the Hello World program.
Task 02 - Basic I/O (Slides 27-46)
Create a C++ program that ... Prints the following line: Insert your age: Reads an int from std::cin and stores it in a variable named age Prints the following line: Insert your...
Task 0301 - Command line arguments (Slides 53-65)
Implement a program which expects an integer as command line argument, representing a temperature value in degree Celsius (° C), and which converts the value into degrees Fahrenheit (° F). The...
Task 0302 - Command line arguments (Slides 53-65)
Create a program with an integer command line argument n , which reads n floating point numbers from std::cin . The program should compute and print the sum of the numbers read. Hint: You...
Task 0401 - Functions (Slides 66-78)
Create a program that prints the value of π. Define π as constexpr using the formula π = 4arctan(1) .
Task 0402 - Functions (Slides 66-78)
Create a function that returns the value of f(x) = sin(x) /x. The value for x = 0 is 1.
Task 0403 - Functions (Slides 66-78)
Implement the bisection method to find one n for which function f(x) is zero. The idea is the following:Given a continuous function on an interval [a,b] . If the sign of f(a) is different...
Task 0404 - Functions (Slides 66-78)
Generalize the previous algorithm to find multiple x values for which a function f(x) is zero. In order to do so, divide the interval into n pieces (e.g., n=10 ) and call your previously...
Chapter 02 - Memory

Start time:
Mi 31 Jan 2018 09:50:53
End time:
So 06 Mai 2018 09:45:53

Assignments 10

Task 0101: Raw pointers (Slides 40-63)
What is the result of the following code? Would the program crash or cause undefined behavior?
Task 0102: Raw pointers (Slides 40-63)
Implement a function swap_values that enables the user to swap two given integer values.
Task 0103: Raw pointers (Slides 40-63)
Modify your code such that you can swap integer pointers instead
Task 0104: Raw pointers (Slides 40-63)
Draw a diagram for the main function in (0103) illustrating the heap/stack memory layout after swap_values has been called.
Task 0201: Arrays (Slides 64-93)
Given the C++ program below. Write down the state of the stack and the heap after each change to either one of them. Explain the consequences and potential problems of the statement a = nullptr;
Task 0202: Arrays (Slides 64-93)
Implement a recursive function with the following signature to perform a binary search on a given integer array: bool binary_search(const int* begin, const int* end, int key)...
Task 0203: Arrays (Slides 64-93)
Create a program that takes an arbitrary number of strings as command line arguments, reads them into a std::vector<std::string> and finally outputs them via cout using a range-based for...
Task 0301: Memory (Slides 40-112)
Re-implement the program from exercise (0101) using references instead of pointers.
Task 0302: Memory (Slides 40-112)
What is the output by the following code?
Task 0303: Memory (Slides 40-112)
For the given C++ code, answer the following questions: What is the type of each variable a-o ? Which assignments in the code are erroneous? Why?
Chapter 03 - Custom Types

Start time:
Mi 31 Jan 2018 09:50:53
End time:
So 06 Mai 2018 09:45:53

Assignments 4

Task 01: Structs (Slides 5-15)
Create a struct named Atom with the following members: A string for its name A string for the element symbol An unsigned int for the atomic number Then create a struct named...
Task 02: Class essentials (Slides 16-30)
Create a class named Rational in order to represent rational numbers. The class should have two int members for the numerator and the denominator, being accessible via getters and setters....
Task 03: Unique Ownership (Slides 31-55)
Create a class named Stack that represents a LIFO data structure for positive integer values. Use a singly-linked list as internal data structure (cf. slide 44). Your class should offer the...
Task 04: File I/O (Slides 68-76)
Create a program that reads the content of the given input file as shown on the sheet (given as command line argument), extracts the first name and the last name of each student and copies the...
Chapter 04 - STL

Start time:
Mi 31 Jan 2018 09:50:53
End time:
So 06 Mai 2018 09:45:53

Assignments 3

Task 01: Separate compilation (Slides 2-24)
Split your stack implementation from the previous exercise sheet into separate header and source files for Stack , Node and the main program. Create a suitable Makefile to compile and link the...
Task 02: Sequence assembly (Slides 33-78)
Given a collection of strings, find an optimal assembly according to the following approach: Take the longest overlap between the suffix and the prefix of two distinct strings. Then merge the...
Task 03: Associative containers (Slides 79-84)
Create a container object that, given the one-letter code of an amino acid, provides efficient access to the corresponding three-letter code: Alanine Ala A Arginine Arg R...