c++ , questions about some problem

 Dusan Radic · May 16, 2015 Implement a class order which will represent a sequence of integers of arbitrary length, and contains a classinformation on the length of the line. Ensure that the index of the first member may be different from zero if the userjade. To provide access to members of the Order of registration and data exchange. Write the main program in whichto enter the corresponding row and the output to give a sum of members of this order as the order that is compiled in the squareelements of the order that the user entered.#include#includeusing namespace std;class Array{private:int *p; //pointerint num; //array lengthconst int i1; //  Initial index (can be different from 0)public:Array(int first_index=1,int number=0);Array(Array & ); ~Array();  int first(){return i1;}    int length(){return num;}  int last(){return i1+num-1;}  int read(int index){return p[index-i1];}  void change(int, int);};Array::Array(int first_index, int number):i1(first_index), num(number){p=new int[num];}Array::Array(Array &a): i1(a.i1), num(a.num){p=new int[num];for(int i=0;i>n;cout<<"from witch index you would like to start"<<'\n';cin>>i;cout<<"Add members of array"<>x;a1.change(j,x);}Array a2(a1);square(a2);cout<<"Sum of array members is: "<

Replies

 Sengngy Kouch · May 17, 2015 @Dusan: Hi there!I am not sure if I answer your question right. However, let me try my best.1. First of all, I think you mean "is p".  and I am not sure what your question is, but let me try my best. if you creating a new pointer to an array, it will need a size. NUM is the size of the array.``int num = 20;int *p = new int[num]; // now "P" has a size of 20. ``Remember that you are creating an integer type of pointer. ``//Pointer of type double array.double *prt = new double [num]; //ordouble *prter = new double[20]; ``2. You should always use int main() for c++.  The reason why people use void main() is because they get used to java. and void main might only work with Microsoft's C++ compiler. (Microsoft visual studio , etc).3. This is the first time that I see this kind of thing.`` P[index - i1] = value ;``Does this even compile? I think Krootushas might be right.After all, I hope this help. sumeet prasad · May 18, 2015 just to help u ..every time u ask the operating system the memory you should give it back by using the function delete[ ] Dusan Radic · May 18, 2015 Thanks, you all helped me a lot
• 1

C++

124,588 followers