Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <random>
- #include <fstream>
- #include "Complex.h"
- using namespace std;
- float random(){
- static default_random_engine e{};
- uniform_real_distribution<float> d;
- return d(e);
- }
- int main()
- {
- //zad.1.
- int n;
- cin >> n;
- vector<float> v;
- for(int i=0;i<n;i++){
- float a = random();
- v.push_back(a);
- }
- cout << "ODCZYT z wektora: " <<endl;
- for(int i=0;i<n;i++){
- cout << v[i] << " ";
- }
- cout << "ODCZYT z wektora ( nowy for): " <<endl;
- for(auto x : v){
- cout << x << " ";
- }
- string filename = "plik_bin.txt";
- ofstream output(filename, ios::binary);
- string filename2 = "plik_txt.txt";
- ofstream output2(filename2, ios::out);
- //zapis w trybie bin
- if(output != 0){
- for(int i=0;i<n;i++){
- output.write(reinterpret_cast<char*> (&v[i]), sizeof(float));
- }
- }
- output.close();
- if(output2 != 0){
- for(int i=0;i<n;i++){
- output2 << v[i] << " ";
- }
- }
- output2.close();
- //odczyt binarny
- cout << "ODCZYT tryb binarny:" <<endl;
- ifstream input(filename, ios::binary);
- cout << "---------------------------------------------" <<endl;
- //wczytywanie:
- if(input != 0){
- float f;
- //int n = output.read(reinterpret_cast<char*> (&f), sizeof(float));
- while(input.read(reinterpret_cast<char*> (&f), sizeof(float))){
- cout << f << " ";
- //n = output.read(reinterpret_cast<char*> (&f), sizeof(float))
- }
- }
- input.close();
- cout << "ODCZYT tryb tekstowy: " <<endl;
- //odczyt w trybie tekstowym
- ifstream input2(filename2, ios::in);
- cout << "---------------------------------------------" <<endl;
- if(input2 != 0){
- float f;
- //int n = output.read(reinterpret_cast<char*> (&f), sizeof(float));
- while(input2 >> f){
- cout << f << " ";
- //n = output.read(reinterpret_cast<char*> (&f), sizeof(float))
- }
- }
- input2.close();
- //zad.2.
- complex z1;
- complex z2;
- z1.re = 21;
- z1.im = 41;
- z2.re = 21;
- z2.im = 41;
- // if( equals(z1, z2) ){
- // cout << "z1=z2";
- // }
- // else{
- // cout << "z1!=z2";
- // }
- equals(z1, z2) ? cout << "z1=z2" : cout << "z1!=z2";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement