Sachees

jacys tam uczniaki

May 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. const int SLEN = 30;
  4.  
  5. struct student {
  6. char fullname[SLEN];
  7. char hobby[SLEN];
  8. int ooplevel;
  9. };
  10. int getinfo(student pa[], int n);
  11. void display1(student st);
  12. void display2(const student * ps);
  13. void display3(const student pa[], int n);
  14.  
  15. int main()
  16. {
  17. std::cout << "Podaj wielkosc grupy: ";
  18. int class_size;
  19. std::cin >> class_size;
  20. while (std::cin.get()!= '\n')
  21. continue;
  22. student * ptr_stu = new student[class_size];
  23. int entered = getinfo(ptr_stu, class_size);
  24. for(int i = 0; i < entered; i++)
  25. {
  26. display1(ptr_stu[i]);
  27. display2(&ptr_stu[i]);
  28. }
  29. display3(ptr_stu, entered);
  30. delete []ptr_stu;
  31. std::cout << "gotowe!\n";
  32. return 0;
  33. }
  34.  
  35. int getinfo(student pa[], int n)
  36. {
  37. int i = 0;
  38. while(i<n)
  39. {
  40. std::cout << "Podaj imie i nazwisko ucznia: ";
  41. std::cin.getline(pa[i].fullname, SLEN);
  42. std::cout << "Podaj hobby ucznia: ";
  43. std::cin.getline(pa[i].hobby, SLEN);
  44. std::cout << "Podaj, w ktorej klasie jest uczen(cyfra): ";
  45. std::cin >> pa[i].ooplevel;
  46. std::cin.ignore();
  47. i++;
  48. }
  49. return i;
  50. }
  51. void display1(student st)
  52. {
  53. std::cout << st.fullname << ", "
  54. << st.hobby << ", klasa "
  55. << st.ooplevel << " | ";
  56. }
  57. void display2(const student * ps)
  58. {
  59. std::cout << ps->fullname << ", "
  60. << ps->hobby << ", klasa "
  61. << ps->ooplevel << "\n";
  62. }
  63. void display3(const student pa[], int n)
  64. {
  65. for(int i = 0; i<n; i++)
  66. {
  67. std::cout << pa[i].fullname << ", "
  68. << pa[i].hobby << ", klasa "
  69. << pa[i].ooplevel << "\n";
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment