Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. // Deklaracja struktury
  7. struct T_dane_osobowe
  8. {
  9. char nazwisko[30];
  10. char imie[15];
  11. short rok_urodz, wzrost;
  12. char plec;
  13. double stypendium;
  14. };
  15.  
  16. // Funkcja zwracajaca strukture
  17. T_dane_osobowe Wczytaj_Dane_Osobowe( void )
  18. {
  19. T_dane_osobowe nowe_dane;
  20. cout << "Podaj nazwisko: ";
  21. cin >> nowe_dane.nazwisko;
  22. return nowe_dane ;
  23. }
  24.  
  25. // Funkcja pobieraa strukture jako wartosc
  26. void Wyswietl_Dane_Osobowe( T_dane_osobowe osoba )
  27. {
  28. cout << "\nCout w funkcji\n";
  29. cout << osoba.nazwisko << osoba.imie<<"\n";
  30. strcpy(osoba.nazwisko, "nadpisane");
  31. cout << osoba.nazwisko << "\n Koniec funkcji\n";
  32. }
  33.  
  34. int main()
  35. {
  36.  
  37.  
  38. T_dane_osobowe student_1, student_2;
  39. T_dane_osobowe student_x = {"Kowalski", "Jan", 1970, 175 ,'M', 320.00 };
  40.  
  41. // Przypisanie struktury kopiuje wartosci wszystkich pol, tak jak w przypadku zwyklej zmiennej
  42. student_1 = student_x;
  43.  
  44. cout << student_x.imie << student_x.nazwisko << "\n";
  45. cout << student_1.imie << student_1.nazwisko << "\n";
  46.  
  47. // Funkcja zwraca strukture tak jak zwykla zmienna i kopiuje zawartosc wszystkich pol
  48. student_2 = Wczytaj_Dane_Osobowe();
  49. cout << student_2.nazwisko << "\n";
  50.  
  51. // Przekazanie do funkcji nastepuje przez wartosc!
  52. Wyswietl_Dane_Osobowe(student_1);
  53.  
  54. cout << "\n W funkcji main:";
  55. cout << student_1.imie << student_1.nazwisko << "\n";
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement