lab5a/ConsoleApplication1/ConsoleApplication3.cpp

74 lines
1.1 KiB
C++
Raw Normal View History

2022-05-10 13:06:32 +00:00
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Matrix {
static const int n = 10;
int tab[n][n];
public:
void czytaj_dane() {
int k = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
tab[i][j] = k++;
}
}
}
void wyswietl() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << tab[i][j] << '\t';
}
cout << endl;
}
cout << endl << endl;
}
void przetworz_dane() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(i > j) swap(tab[i][j], tab[j][i]);
}
}
}
void zapisz_dane_do_pliku() {
fstream f;
f.open("dane.txt");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
f << tab[i][j] << '\t';
}
f << endl;
}
f.close();
}
void czytaj_dane_z_pliku() {
fstream f;
f.open("dane.txt");
while (!f.eof()) {
string s;
getline(f, s);
cout << s << endl;
}
f.close();
}
};
int main()
{
Matrix m;
m.czytaj_dane();
m.wyswietl();
m.przetworz_dane();
m.wyswietl();
m.zapisz_dane_do_pliku();
m.czytaj_dane_z_pliku();
}