Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct samochod
- {
- string marka;
- string model;
- float cena;
- };
- void pobierz_samochody(int ile, samochod* tablica_samochodow);
- void wypisz_samochody(int ile, samochod* tablica_samochodow);
- void zapisz_samochody(int ile, samochod* tablica_samochodow);
- //samochod* tablica_samochodow;
- int main(void)
- {
- int ile;
- string marka="";
- string model="";
- float cena = 00.00;
- samochod* tablica_samochodow;
- cout << endl << "Ile samochodow bedziesz wprowadzac: ";
- cin >> ile;
- tablica_samochodow = new samochod[ile];
- cout << endl;
- pobierz_samochody(ile, tablica_samochodow);
- wypisz_samochody(ile, tablica_samochodow);
- zapisz_samochody(ile, tablica_samochodow);
- delete [] tablica_samochodow;
- return 0;
- }
- void pobierz_samochody(int ile, samochod* tablica_samochodow)
- {
- for(int i=0; i<ile; i++)
- {
- cout << "Podaj marke samochodu: " << i+1 << endl << endl;
- cout << " ";
- cin >> tablica_samochodow[i].marka;
- cout << endl;
- cout << "Podaj model samochodu: " << i+1 << endl << endl;
- cout << " ";
- cin >> tablica_samochodow[i].model;
- cout << endl;
- cout << "Podaj cene samochodu: " << i+1 << endl << endl;
- cout << " ";
- cin >> tablica_samochodow[i].cena;
- cout << endl;
- }
- }
- void wypisz_samochody(int ile, samochod* tablica_samochodow)
- {
- for(int i=0; i<ile; i++)
- {
- cout << "Samochod: " << i+1 << endl << endl;
- cout << " " << "Marka: " << tablica_samochodow[i].marka << endl;
- cout << " " << "Model: " << tablica_samochodow[i].model << endl;
- cout << " " << "Cena: " << tablica_samochodow[i].cena << endl << endl;
- }
- }
- void zapisz_samochody(int ile, samochod* tablica_samochodow)
- {
- ofstream zapis("dane.txt");
- for(int i=0; i<ile; i++)
- {
- zapis << "Samochod: " << i+1 << endl << endl;
- zapis << " " << "Marka: " << tablica_samochodow[i].marka << endl;
- zapis << " " << "Model: " << tablica_samochodow[i].model << endl;
- zapis << " " << "Cena: " << tablica_samochodow[i].cena << endl << endl;
- }
- zapis.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement