This commit is contained in:
w65567 2022-05-10 15:06:32 +02:00
parent 27c3768c07
commit 1c59d193f2
3 changed files with 76 additions and 2 deletions

View File

@ -139,7 +139,7 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="ConsoleApplication2.cpp" /> <ClCompile Include="ConsoleApplication3.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -15,7 +15,7 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="ConsoleApplication2.cpp"> <ClCompile Include="ConsoleApplication3.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,74 @@
#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();
}