Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- using namespace std;
- class Class{
- private:
- string a;
- public:
- void setA(string b){a = b;}
- string getA(){return a;}
- };
- class Container{
- private:
- int n, current;
- Class *C;
- public:
- Container(): C(NULL), n(0), current(0){}
- void toFirst() {current = 0;}
- void toNext() {if(current < n)current++;}
- bool notLast() {return current < n;}
- void expandC(int ammount){
- Class *NewClass= new Class[ammount];
- for (int i = 0; i < n; i++)
- NewClass[i] = C[i];
- delete []C;
- C = NewClass;
- n = ammount;
- }
- void addC(string name){
- expandC(n+1);
- C[n-1].setA(name);
- current = n;
- }
- void setC(string name){
- if(current+1<=n){
- C[current].setA(name);
- }else{
- addC(name);
- }
- }
- string getName () { return C[current].getA(); }
- };
- void main(){
- Container *CONT;
- CONT = new Container;
- CONT->expandC(10);
- CONT->toFirst();
- while(CONT->notLast()){
- CONT->setC("value");
- CONT->toNext();
- }
- CONT->toFirst();
- while(CONT->notLast()){
- cout << CONT->getName()<<endl;
- CONT->toNext();
- }
- system("Pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement