Загрузить файлы в «/»

This commit is contained in:
2025-11-06 19:24:17 +02:00
parent 9f08d3ecba
commit e3685eac60

68
ConsoleApplica44444.cpp Normal file
View File

@@ -0,0 +1,68 @@
#include <iostream>
#include <fstream>
using namespace std;
int ncd(int a, int b) {
return (b == 0 ? a : ncd(b, a % b));
}
struct Drib {
int ch;
int zn;
void init() {
cout << "\nInput ch: ";
cin >> ch;
cout << "Input zn: ";
cin >> zn;
skor();
}
void skor() {
int d = ncd(ch, zn);
if (d != 0) {
ch /= d;
zn /= d;
}
}
void print() {
cout << ch << "/" << zn << endl;
}
};
int main()
{
Drib a;
fstream finOut;
finOut.open("info.dat", ios::binary | ios::out); //ios::out | ios::trunc);
if (!finOut.is_open()) {
cerr << "\n Error opening file(out)!!\n";
system("pause");
return 1;
}
int vUser;
do {
a.init();
finOut.write((char*)(&a), sizeof(Drib));
cout << "\n Create a fraction?(1/Yes 0/No) ";
cin >> vUser;
} while (vUser);
finOut.close();
finOut.open("info.dat", ios::binary | ios::in);
if (!finOut.is_open()) {
cerr << "\n Beta(in)!!\n";
system("pause");
return 1;
}
cout << "\nRead fractions in file:\n";
finOut.read((char*)(&a), sizeof(a));
while (finOut.good()) {
a.print();
finOut.read(reinterpret_cast<char*>(&a), sizeof(a));
}
finOut.close();
system("pause");
}