| 2 | // Here namespace is having obj like cin and cout ; |
| 3 | using namespace std; |
| 4 | class Array // Creating class |
| 5 | // Class in c++ will have Datamember and member function |
| 6 | { |
| 7 | private: |
| 8 | int *A; // Creating in heap so that i can dynamically create an array |
| 9 | int size; |
| 10 | int length; |
| 11 | |
| 12 | public: // Member function must be inside public |
| 13 | // Write an constructor |
| 14 | Array () // This is non parameter constructor |
| 15 | { |
| 16 | size=10; |
| 17 | A = new int[10]; // dynamically created array in heap |
| 18 | length=0; |
| 19 | |
| 20 | } |
| 21 | |
| 22 | // parametetrzied Constructor |
| 23 | |
| 24 | Array (int sz) |
| 25 | { |
| 26 | size=sz; |
| 27 | length=0; |
| 28 | A=new int [size]; |
| 29 | } |
| 30 | |
| 31 | |
| 32 | // We must have destructors to release resourses |
| 33 | ~Array() // Creating Destructor |
| 34 | { |
| 35 | delete []A; |
| 36 | } |
| 37 | |
| 38 | // Writting Function |
| 39 | void Display (); // There sud not be parameter cz this is part of Array function |
| 40 | void Insert (int index, int x); |
| 41 | int Delete (int index); |
| 42 | |
| 43 | }; |
| 44 | |
| 45 | void Array :: Display () |
| 46 | { |
nothing calls this directly
no outgoing calls
no test coverage detected