High_Light

Classes

Feb 20th, 2018
90
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.  
  3. using namespace std;
  4. /*
  5. class Myclass{
  6. public:
  7.  
  8.     int value;
  9.     Myclass(int x){
  10.         value=x;
  11.     }
  12.     Myclass(){
  13.         value = 0;
  14.     }
  15.     void print(){
  16.         cout<< value << endl;
  17.     }
  18.  
  19. };
  20. */
  21. class List{
  22. public:
  23.     int *array,index,size;
  24.     List (){
  25.         array=new int[10];
  26.         size=10;
  27.         index=0;
  28.     }
  29.     ~List(){
  30.         delete [] array;
  31.     }
  32.     void Append(int i){
  33.         array[index]=i;
  34.         index++;
  35.     }
  36.     void get(int N){
  37.         cout<<array[N]<<endl;
  38.     }
  39.  
  40.     void print(){
  41.         for (int i=0 ; i<index ; i++){
  42.             cout << array[i]<< " ";
  43.         }
  44.  
  45.     }
  46. };
  47.  
  48.  
  49.  
  50.  
  51. int main()
  52. {
  53.     int n=6;
  54.     List a = List();
  55.     a.Append(1);
  56.     a.Append(1);
  57.     a.Append(1);
  58.     a.Append(1);
  59.                 a.Append(1);
  60.     a.Append(1);
  61.     a.Append(1);
  62.                 a.Append(1);           a.Append(1);
  63.                 a.Append(1);
  64.     a.get(2);
  65.     /*Myclass a = Myclass(2), b = Myclass(), c = Myclass();
  66.     a.value=5;
  67.     b.value=6;
  68.     c.value;
  69.  
  70.     cout<< a.value << endl;
  71.     cout<< b.value << endl;
  72.     cout<< c.value << endl;
  73.     a.print();
  74.     b.print();
  75.     c.print();*/
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment