#include #include 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(&a), sizeof(a)); } finOut.close(); system("pause"); }