Advertisement
MeehoweCK

Untitled

May 20th, 2023
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. // struktura - składnia:
  6. struct Student     // Student od tego momentu jest nazwą naszego własnego typu zmiennej
  7. {
  8.     string imie;
  9.     string nazwisko;
  10.     int wiek;
  11.     string e_mail;
  12.     double srednia_ocen;
  13. };
  14. void pobierz_dane(Student& student1)
  15. {
  16.     cout<<"podaj imie studenta"<<endl;
  17.     cin>>student1.imie;
  18.     cout<<"podaj nazwisko studenta"<<endl;
  19.     cin>>student1.nazwisko;
  20.     cout<<"podaj wiek studenta"<<endl;
  21.     cin>>student1.wiek;
  22.     cout<<"podaj e-mail studenta"<<endl;
  23.     cin>>student1.e_mail;
  24.     cout<<"podaj srednia ocen studenta"<<endl;
  25.     cin>>student1.srednia_ocen;
  26. }
  27. bool plik_danych(Student t[5] )
  28. {
  29.  
  30.     ifstream plik_in;
  31.     plik_in.open("dane_studentow.txt");
  32.     if(plik_in.fail())
  33.         return 1;       // zwrócenie błędu
  34.     for(int i=0; i<5; i++)
  35.     {
  36.         plik_in>>t[i].imie;
  37.         plik_in>>t[i].nazwisko;
  38.         plik_in>>t[i].wiek;
  39.         plik_in>>t[i].e_mail;
  40.         plik_in>>t[i].srednia_ocen;
  41.     }
  42.  
  43.     plik_in.close();
  44.     return 0;       // zwrócenie braku błędu
  45. }
  46.  
  47.  
  48. void dane(Student student1)
  49. {
  50.     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;
  51.  
  52. }
  53.  
  54. int main()
  55. {
  56.  
  57.     Student t[5];
  58.     if(plik_danych(t))
  59.     {
  60.         cout << "Nie udalo sie odczytac danych z pliku. Nastapi zamkniecie programu.\n";
  61.         return 0;
  62.     }
  63.  
  64.     for(int i=0; i<5; i++)
  65.     {
  66.         dane(t[i]);
  67.     }
  68.  
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement