Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <iostream>
- #include <fstream>
- #include <time.h>
- #include <cstdlib>
- #include <cstring>
- using namespace std;
- struct osoba{
- char nazwisko[20];
- char adres[15];
- char stanowisko[15];
- float brutto;
- };
- void wpisz(osoba &o)
- {
- cout<<"DODAWANIE NOWEJ OSOBY!"<<endl;
- bool wybor = true;
- fstream plik;
- plik.open("zadanie7.dat", ios::binary | ios::out | ios::app);
- if(!plik.good())
- {
- cout<<"Nie otworze!"<<endl;
- return;
- }
- while(wybor)
- {
- cout<<"Nazwisko: "; cin.get(o.nazwisko, 19); cin.clear(); cin.sync();
- cout<<"Adres: "; cin.get(o.adres, 14); cin.clear(); cin.sync();
- cout<<"Stanowisko: "; cin.get(o.stanowisko, 14); cin.clear(); cin.sync();
- cout<<"Brutto: "; cin>>o.brutto; cin.clear(); cin.sync();
- cout<<endl;
- cout<<"Chcesz wprowadzic kolejne dane? "; cin>>wybor; cin.clear(); cin.sync();
- plik.write(reinterpret_cast<char*>(&o), sizeof(o));
- }
- plik.close(); plik.clear();
- }
- //--------------------------------
- void raport(osoba &o)
- {
- fstream zrodlo;
- zrodlo.open("zadanie7.dat", ios::binary | ios::in);
- fstream raport;
- raport.open("raport_z7.txt", ios::out | ios::app);
- if(!zrodlo.good() || !raport.good())
- {
- cout<<"Nie otworze!"<<endl;
- return;
- }
- string tytul, kto;
- cout<<"Tytul raportu: "; getline(cin, tytul); cin.clear(); cin.sync();
- cout<<"Imie i nazwisko: "; getline(cin, kto); cin.clear(); cin.sync();
- time_t czas;
- struct tm * ptr;
- time( & czas );
- ptr = localtime( & czas );
- char * data = asctime( ptr );
- char stanowisko[15];
- cout<<"Podaj dla jakiego stanowiska wyliczyc srednia: "; cin.get(stanowisko, 14); cin.clear(); cin.sync();
- raport<<"Tytul raportu: "<<tytul<<endl;
- raport<<"Data raportu: "<<data<<endl;
- raport<<"Sporzadzil: "<<kto<<endl;
- raport<<endl;
- int ilu_pracownikow = 0;
- float suma_brutto = 0;
- int ilu_w_zawodzie = 0;
- for(int i = 0;;i++)
- {
- zrodlo.read(reinterpret_cast<char*>(&o), sizeof(o));
- if(zrodlo.eof()){
- break;
- }
- if(strcmp(o.stanowisko, stanowisko) == 0)
- {
- suma_brutto += o.brutto;
- ilu_w_zawodzie++;
- }
- raport<<o.nazwisko<<" "<<o.adres<<" "<<o.stanowisko<<" "<<o.brutto<<endl;
- ilu_pracownikow++;
- }
- float srednia = suma_brutto/ilu_w_zawodzie;
- raport<<endl;
- raport<<"-------------PODSUMOWANIE-----------"<<endl;
- raport<<"W bazie jest "<<ilu_pracownikow<<" pracownikow"<<endl;
- raport<<"Pracownikow pracujacych jako "<<stanowisko<<" jest "<<ilu_w_zawodzie<<endl;
- raport<<"Srednia placy wynosi dla "<<stanowisko<<" wynosi "<<srednia<<endl;
- zrodlo.close(); raport.close();
- }
- //--------------------------------
- int main()
- {
- osoba o;
- wpisz(o);
- raport(o);
- }
Add Comment
Please, Sign In to add comment