Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- const int SLEN = 30;
- struct student {
- char fullname[SLEN];
- char hobby[SLEN];
- int ooplevel;
- };
- int getinfo(student pa[], int n);
- void display1(student st);
- void display2(const student * ps);
- void display3(const student pa[], int n);
- int main()
- {
- std::cout << "Podaj wielkosc grupy: ";
- int class_size;
- std::cin >> class_size;
- while (std::cin.get()!= '\n')
- continue;
- student * ptr_stu = new student[class_size];
- int entered = getinfo(ptr_stu, class_size);
- for(int i = 0; i < entered; i++)
- {
- display1(ptr_stu[i]);
- display2(&ptr_stu[i]);
- }
- display3(ptr_stu, entered);
- delete []ptr_stu;
- std::cout << "gotowe!\n";
- return 0;
- }
- int getinfo(student pa[], int n)
- {
- int i = 0;
- while(i<n)
- {
- std::cout << "Podaj imie i nazwisko ucznia: ";
- std::cin.getline(pa[i].fullname, SLEN);
- std::cout << "Podaj hobby ucznia: ";
- std::cin.getline(pa[i].hobby, SLEN);
- std::cout << "Podaj, w ktorej klasie jest uczen(cyfra): ";
- std::cin >> pa[i].ooplevel;
- std::cin.ignore();
- i++;
- }
- return i;
- }
- void display1(student st)
- {
- std::cout << st.fullname << ", "
- << st.hobby << ", klasa "
- << st.ooplevel << " | ";
- }
- void display2(const student * ps)
- {
- std::cout << ps->fullname << ", "
- << ps->hobby << ", klasa "
- << ps->ooplevel << "\n";
- }
- void display3(const student pa[], int n)
- {
- for(int i = 0; i<n; i++)
- {
- std::cout << pa[i].fullname << ", "
- << pa[i].hobby << ", klasa "
- << pa[i].ooplevel << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment