Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- const int n = 20;
- struct struct1
- {
- int id;
- char name[10];
- double number;
- bool flag;
- };
- void main()
- {
- int f1[n];
- double f2[n];
- for (int i = 0; i < n; i++)
- f1[i] = (rand() % 200) - 100;
- ofstream fout1("file1.bin", ios::binary);
- fout1.write((char*)&f1, sizeof(f1));
- fout1.close();
- ifstream fin1("file1.bin", ios::binary);
- fin1.read((char*)&f1, sizeof(f1));
- for (int i = 0; i < n; i++)
- f2[i] = f1[i] * 1.0 / ((rand() % 200) - 100);
- ofstream fout2("file2.bin", ios::binary);
- fout2.write((char*)&f2, sizeof(f2));
- fin1.close();
- fout2.close();
- ifstream fin2("file2.bin", ios::binary);
- struct1 str[n];
- cout << "Enter " << n << " name:";
- for (int i = 0; i < n; i++)
- {
- cin >> str[i].name;
- str[i].id = i + 1;
- str[i].number = f2[i];
- if (int(f2[i]) == f2[i])
- str[i].flag = true;
- else
- str[i].flag = false;
- }
- ofstream fout3("file3.bin", ios::binary);
- fout3.write((char*)&str, sizeof(str));
- fin2.close();
- fout3.close();
- ifstream fin3("file3.bin", ios::binary);
- fin3.read((char*)&str, sizeof(str));
- for (int i = 0; i < n; i++)
- {
- cout.width(5);
- cout << str[i].id;
- cout.width(10);
- cout << str[i].name;
- cout.width(15);
- cout << str[i].number;
- cout.width(10);
- cout << str[i].flag;
- cout << endl;
- }
- fin3.close();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement