Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<string>
- using namespace std;
- class Student{
- public:
- int *godine;
- Student(){
- godine = new int;
- }
- ~Student(){
- delete godine;
- }
- };
- void main(){
- int brs;
- cout<<"Koliko zelis studenata upisat: ";
- cin>>brs;
- /*
- Student* *ns; //niz pokazivača
- ns = new Student*[brs];
- for (int i = 0; i<brs; i++){ //alociranje memorije za mjesta di pokazuju pokazivači
- *(ns+i) = new Student;
- }
- */
- vector<Student*> *vs; //samo dodamo vector ispred varijable
- vs = new vector<Student*>(brs); //umjesto uglatih idu obične zagrade
- for (int i=0; i<brs; i++){
- vs->at(i) = new Student;
- //cin>>*((ns+i)->*godine);
- 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
- }
- Student *s;
- cout<<"Koliko novih studenata želiš dodati u vektor: ";
- int novih;
- cin>>novih;
- for (int i=0; i<novih; i++){
- brs=brs+1;
- vs->push_back(s); //ne stavljamo fizičkog studenta, nego adresu od studenta s
- vs->at(brs-1)=new Student;
- cin>>*(vs->at(brs-1)->godine);
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement