# 9. 2D vector

Als je 5 proefwerkcijfers van de hele klas van 25 leerlingen wil opslaan, dan kun je hiervoor een 2-dimensionale array of vector gebruiken.

!\[A picture containing calendar

Description automatically generated]\(<https://lh6.googleusercontent.com/FUzKGfpkefaB73rNeDYHz8ES9NLSb98BLbUHuyy1au6kSagxVyn_QgiaJb173oyw4Gq3_ZjGIUjpoeF4Y8ZTe40iyXWhSNABXtC1sdcH25wtp_7I4IgprnUwlN0uFrpS8M4jS9cm1zLyAKTXKWeb>)

\
`cijfer[1][3]` -> dit is leerling met index 1 en proefwerkcijfer met index 3. Dit is een 9,8.\
`cijfer[2][1]` -> dit is leerling met index 2 en proefwerkcijfer met index 1. Dit is een 5,5.

Een 2-dimensionale vector declareer je als volgt: `vector<vector<int>> vect;`

Hieronder zie je een voorbeeld:

```cpp
#include <vector>
#include <iostream>
using namespace std;

int main() {
 int aantalRij = 5;
 int aantalKol = 3;

 //declareer de vector
 vector<vector<int> > vect(aantalRij, vector<int> (aantalKol));

 //vul de vector
 for (int rij = 0; rij < aantalRij; rij++) {
   for (int kol = 0; kol < aantalKol; kol++) {
      cout << "Geef element " << kol << " van rij " << rij << endl;
      cin >> vect[rij][kol];
   }  
 }

 //print de vector
 for (int rij = 0; rij < aantalRij; rij++) {
   for (int kol = 0; kol < aantalKol; kol++) {
      cout << vect[rij][kol] << " ";
    }
    cout << endl;
  }
}
```

{% hint style="info" %}
Als je een 2-dimensionale vector direct met 0-en wil vullen dan gebruik je de code:\
`vector<vector<int> > vect(aantalRij, vector<int> (aantalKol, 0))`
{% endhint %}

**Opdracht 9.1**\
Schrijf een programma om de volgende vraag op te lossen:

<figure><img src="/files/hfyD5FduElz4IU9TKzn8" alt="" width="563"><figcaption></figcaption></figure>

**Opdracht 9.2**\
Maak de opdracht: [Magische vierkanten](https://informatica.cuttle.org/?action=question_standalone\&que_id=110\&t=777aa95d077531d7)

Opdracht 9.3\
Maak de opdracht: [Lichten](https://informatica.cuttle.org/?action=question_standalone\&que_id=115\&t=c42c8d290652ee4d)

Opdracht 9.4\
Maak de opdracht: [Geheimtaal](https://informatica.cuttle.org/?action=question_standalone\&que_id=72\&t=36f017bb365855b3)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://girls.gitbook.io/c++-cursus/leer-meer-c++/9.-2d-vector.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
