Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- const int SLEN = 30;
- struct student {
- char fullname[SLEN];
- char hobby[SLEN];
- int ooplevel;
- };
- /*funkcja getinfo() ma dwa parametry: wskaźnik pierwszego elementu tablicy struktur student oraz liczbę int
- określającą liczbę elementów w tablicy. Funkcja pobiera i zapisuje dane o studentach. Wprowadzanie danych
- kończy się, kiedy tablica jest pełna lub podane zostanie puste nazwisko studenta. Funkcja zwraca liczbę
- studentów wpisanych do tablicy. */
- int getinfo(student pa[], int n){
- int c=0;
- for(int i =0;i<n;i++){
- string a;
- cin>>a;
- if(a!=" "){
- for(int z=0;z<a.length();z++){
- pa[i].fullname[z] = a[z];}
- }
- else i =n+1;
- cin>>a;
- for(int z=0;z<a.length();z++){
- pa[i].hobby[z] = a[z];}
- int b;
- cin>>b;
- pa[i].ooplevel = b;
- c++;
- }
- return c;
- }
- /* Funkcja display1() pobiera jako parametr strukturę student i pokazuje jej zawartość */
- void display1(student st){
- cout<<st.fullname<<endl<<st.hobby<<endl<<st.ooplevel<<endl;
- }
- /*funkcja display2() pobiera jako parametr adres struktury student i pokazuje zawartość tej struktury. */
- void display2(const student *ps){
- cout<<ps->fullname<<endl<<ps->hobby<<endl<<ps->ooplevel<<endl; //(*ps).fullname
- }
- /*funkcja display3() pobiera jako parametr adres pierwszego elementu tablicy ze strukturami student oraz liczbę
- elementów w tablicy, po czym wyświetla zawartość wskazanych struktur.*/
- void display3(const student pa[], int n){
- for(int i=0;i<n;i++){
- cout<<pa[i].fullname<<" "<<pa[i].hobby<<" "<<pa[i].ooplevel<<endl;
- }
- }
- int main()
- {
- cout << "Podaj wielkość grupy: ";
- int class_size;
- cin >> class_size;
- while (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;
- cout << "Gotowe\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement