Exercise 10
Added Exercise 10 to Repo
This commit is contained in:
46
Informatik_I/Exercise_10/Task_1a/README.org
Normal file
46
Informatik_I/Exercise_10/Task_1a/README.org
Normal file
@@ -0,0 +1,46 @@
|
||||
#+title: Task 1a: Understanding Pointers: - Lookup
|
||||
|
||||
#+author: JirR02
|
||||
* Task Description
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: task-description
|
||||
:END:
|
||||
Complete the definition of function lookup by editing the file
|
||||
=lookup.cpp= according to its specified pre- and post conditions.
|
||||
|
||||
We provide a test program using the implemented function to perform
|
||||
lookup on a vector.
|
||||
|
||||
** Input
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: input
|
||||
:END:
|
||||
The program accepts
|
||||
|
||||
- the length of the vector, =l=,
|
||||
- =l= vector elements, and
|
||||
- a lookup index =i=.
|
||||
|
||||
For example:
|
||||
|
||||
means a 3-element vector =[9, 8, 7]= and the lookup index 1.
|
||||
|
||||
** Output
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: output
|
||||
:END:
|
||||
The test program prints the value of the element at the lookup index.
|
||||
|
||||
For example, for the input given above, this value is 8.
|
||||
|
||||
* Solution
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: solution
|
||||
:END:
|
||||
#+begin_src cpp
|
||||
#include "lookup.h"
|
||||
|
||||
// PRE: 0 <= i < vec.size()
|
||||
// POST: Returns the address of the i-th element of vec.
|
||||
const int *lookup(const std::vector<int> &vec, const int i) { return &vec[i]; }
|
||||
#+end_src
|
Reference in New Issue
Block a user