Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. class Student{
  8. public:
  9.     int *godine;
  10.     Student(){
  11.         godine = new int;
  12.     }
  13.     ~Student(){
  14.         delete godine;
  15.     }
  16. };
  17.  
  18. void main(){
  19.     int brs;
  20.     cout<<"Koliko zelis studenata upisat: ";
  21.     cin>>brs;
  22.  
  23.     /*
  24.     Student* *ns;   //niz pokazivača
  25.     ns = new Student*[brs];
  26.     for (int i = 0; i<brs; i++){   //alociranje memorije za mjesta di pokazuju pokazivači
  27.         *(ns+i) = new Student;
  28.     }
  29.     */
  30.  
  31.     vector<Student*> *vs;  //samo dodamo vector ispred varijable
  32.     vs = new vector<Student*>(brs);  //umjesto uglatih idu obične zagrade
  33.     for (int i=0; i<brs; i++){
  34.         vs->at(i) = new Student;
  35.         //cin>>*((ns+i)->*godine);
  36.         cin>>*(vs->at(i)->godine);  //zvjezdica na početku označuje da je varijable godine pokazivač, da nije ili da je funkcija nebi bilo zvjezdice. da vektor nije pokazivač, nebi bila strelica prema godine nego točka
  37.     }
  38.  
  39.     Student *s;
  40.     cout<<"Koliko novih studenata želiš dodati u vektor: ";
  41.     int novih;
  42.     cin>>novih;
  43.  
  44.     for (int i=0; i<novih; i++){
  45.     brs=brs+1;
  46.     vs->push_back(s);  //ne stavljamo fizičkog studenta, nego adresu od studenta s
  47.     vs->at(brs-1)=new Student;
  48.     cin>>*(vs->at(brs-1)->godine);
  49.     }
  50.  
  51. system("PAUSE");
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement