Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication12.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- struct trasa
- {
- float dystans;
- float czas;
- };
- void wypisz_etapy()
- {
- trasa pom;
- fstream zrodlo("dane.bin", ios::in | ios::binary);
- while (1)
- {
- zrodlo.read((char*)&pom, sizeof(trasa));
- if (zrodlo.good())
- {
- cout << "Dystans: " << pom.dystans <<endl;
- cout << "Czas: " << pom.czas <<endl;
- cout << endl;
- }
- else
- {
- if (!zrodlo.eof())
- {
- cout << "blad odczytu!" << endl;
- }
- break;
- }
- }
- zrodlo.clear();
- zrodlo.close();
- };
- void trasa_calkowita(float & calkowita1)
- {
- trasa pom;
- fstream zrodlo("dane.bin", ios::in | ios::binary);
- calkowita1 = 0;
- while (1)
- {
- zrodlo.read((char*)&pom, sizeof(trasa));
- if (zrodlo.good())
- {
- calkowita1 += pom.dystans;
- }
- else
- {
- if (!zrodlo.eof())
- {
- cout << "blad odczytu!" << endl;
- }
- break;
- }
- }
- zrodlo.clear();
- zrodlo.close();
- }
- void najdluzszy(float & calkowita1)
- {
- trasa pom;
- fstream zrodlo("dane.bin", ios::in | ios::binary);
- calkowita1 = 0;
- while (1)
- {
- zrodlo.read((char*)&pom, sizeof(trasa));
- if (zrodlo.good())
- {
- calkowita1 += pom.dystans;
- }
- else
- {
- if (!zrodlo.eof())
- {
- cout << "blad odczytu!" << endl;
- }
- break;
- }
- }
- zrodlo.clear();
- zrodlo.close();
- }
- void srednia_predkosc()
- {
- trasa pom;
- fstream zrodlo("dane.bin", ios::in | ios::binary);
- fstream cel("wyniki.txt", ios::out);
- float srednia = 0;
- while (1)
- {
- zrodlo.read((char*)&pom, sizeof(trasa));
- if (zrodlo.good())
- {
- srednia = pom.dystans / pom.czas;
- cel << srednia << endl;
- }
- else
- {
- if (!zrodlo.eof())
- {
- cout << "blad odczytu!" << endl;
- }
- break;
- }
- }
- zrodlo.clear();
- zrodlo.close();
- cel.clear();
- cel.close();
- };
- int main()
- {
- float dystanssuma;
- //utworzenie_pliku();
- wypisz_etapy();
- trasa_calkowita(dystanssuma);
- cout << endl << "Cały dystans to: " << dystanssuma << endl;
- srednia_predkosc();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement