Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- // struktura - składnia:
- struct Student // Student od tego momentu jest nazwą naszego własnego typu zmiennej
- {
- string imie;
- string nazwisko;
- int wiek;
- string e_mail;
- double srednia_ocen;
- };
- void pobierz_dane(Student& student1)
- {
- cout<<"podaj imie studenta"<<endl;
- cin>>student1.imie;
- cout<<"podaj nazwisko studenta"<<endl;
- cin>>student1.nazwisko;
- cout<<"podaj wiek studenta"<<endl;
- cin>>student1.wiek;
- cout<<"podaj e-mail studenta"<<endl;
- cin>>student1.e_mail;
- cout<<"podaj srednia ocen studenta"<<endl;
- cin>>student1.srednia_ocen;
- }
- bool plik_danych(Student t[5] )
- {
- ifstream plik_in;
- plik_in.open("dane_studentow.txt");
- if(plik_in.fail())
- return 1; // zwrócenie błędu
- for(int i=0; i<5; i++)
- {
- plik_in>>t[i].imie;
- plik_in>>t[i].nazwisko;
- plik_in>>t[i].wiek;
- plik_in>>t[i].e_mail;
- plik_in>>t[i].srednia_ocen;
- }
- plik_in.close();
- return 0; // zwrócenie braku błędu
- }
- void dane(Student student1)
- {
- cout<<endl<<"imie= "<<student1.imie<<endl<<"nazwisko= "<<student1.nazwisko<<endl<<"wiek= "<<student1.wiek<<endl<<"e-mail= "<<student1.e_mail<<endl<<"srednia ocen= "<<student1.srednia_ocen;
- }
- int main()
- {
- Student t[5];
- if(plik_danych(t))
- {
- cout << "Nie udalo sie odczytac danych z pliku. Nastapi zamkniecie programu.\n";
- return 0;
- }
- for(int i=0; i<5; i++)
- {
- dane(t[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement