43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
/// @file
|
|
/// @brief task C
|
|
/// g++ -std=c++20 -Imodules taskC.cpp -o taskC && ./taskC
|
|
|
|
/// @todo include modules library header for using iue::io::savetxt
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
/// @todo write a function initalizing a 'vector of vectors' with an integer sequence, details see main.ipynb
|
|
std::vector<std::vector<double>> initMatrix(int m, int n) {
|
|
std::vector<std::vector<double>> matrix;
|
|
double value = 1.0;
|
|
for (int i = 0; i < m; i++) {
|
|
std::vector<double> row;
|
|
for (int j = 0; j < n; j++) {
|
|
row.push_back(value);
|
|
value++;
|
|
}
|
|
matrix.push_back(row);
|
|
}
|
|
return matrix;
|
|
}
|
|
|
|
/// @todo write a function to write a 'vector of vectors' to a csv-file, details see main.ipynb
|
|
void writeMatrix(std::vector<std::vector<double>> matrix, std::string filename) {
|
|
std::ofstream file(filename);
|
|
for (auto row : matrix) {
|
|
for (auto i : row) {
|
|
file << i << ",";
|
|
}
|
|
file << std::endl;
|
|
}
|
|
file.close();
|
|
}
|
|
|
|
/// @todo write a main-function and use your function to
|
|
/// - init a 'vector of vectors' to initialize a table and
|
|
/// - write the table to a csv-file using iue::io::savetxt
|
|
int main() {
|
|
std::vector<std::vector<double>> matrix = initMatrix(3, 4);
|
|
writeMatrix(matrix, "matrix.csv");
|
|
} |