?
Solved

Please, help to write a code for my problem.

Posted on 2005-05-10
3
Medium Priority
?
253 Views
Last Modified: 2010-04-01
I need to create a class with all the functions listed bellow, and functions definitions. Pleeease, help me!
Thank You!

Create an Array class to hold an array of integers.  An object of the Array class should be very much like a built-in C++ array, except that an Array object has some additional functionality that the built-in C++ array does not.

Listed below is a description of the functionality your Array object should possess.

Given the following declaration statements for 3 objects of the Array class,

int a[3] = {10, 20, 30}, b = {40, 50, 60, 70, 80};

Array myArray1, myArray2, myArray3;

the following member functions should be included:

A default constructor to initialize an Array object to an integer array of size 20, with all elements being initialized to zero.
A constructor of the type
myArray1 = Array(a, 3);

which initializes  myArray1  to hold the values of the array, "a", which is 3 elements long.

A constructor of the type
myArray1 = Array(100);

which initializes  myArray1  to hold an array which is 100 elements long, but sets all the elements to have a value of zero.

A member function to give the length of the Array object:
myArray1.length( );

(Note that this is really an accessor function to get the size of the array.)

An accessor function which returns a pointer that gives access to the array, itself.
If  myArray1  was an Array object that held the values of the integer "a" array, then the following code would print out the values of the integer "a" array:

int i;

int *p;

p = myArray1.get_array( );

for(i=0; i<=myArray1.length( )-1; i++)

    cout << *(p+i);

If  myArray2  was an Array object that held the values of the integer "b" array, then the member function
myArray2.add_begin(a, 3);

would have the values of the "a" array added to the beginning of it, so that it would now hold the following values

10, 20, 30, 40, 50, 60, 70, 80

in that order.

If  myArray1  was an Array object that held the values of the integer "a" array, then the member function
myArray1.add_end(b, 5);

would have the values of the "b" array added to the end of it, so that it would now hold the following values

10, 20, 30, 40, 50, 60, 70, 80

in that order.

If  myArray2  was an Array object that held the values of the integer "b" array, then the member function
myArray2.remove_begin(3);

would remove the first 3 values of the array so that it would now hold the following values

70, 80

in that order.

If  myArray2  was an Array object that held the values of the integer "b" array, then the member function
myArray2.remove_end(3)

would remove the last 3 values of the array so that it would now hold the following values

40, 50

in that order.

The member function
myArray1.resize(200)

would resize the Array object to be 200 elements long.  If the original size of the Array object was bigger, elements would be removed from the end of the array.  If the original size of the Array object was smaller, then the appropriate number of zeros would be added to the end of the Array object.

If  myArray1  was an Array object that held the values of the integer "a" array, and  myArray2  was an Array object that held the values of the integer "b" array, then the addition operator and assignment operator should be overloaded as members of the class so that one could write:
myArray3 = myArray1 + myArray2;

The addition operator would concatenate the elements of  myArray2  to the end of the elements in  myArray1  so that  myArray3  would hold the elements

10, 20, 30, 40, 50, 60, 70, 80

in that order.

Provide a copy constructor for the class.
Provide a destructor for the class.
Be sure to implement all arrays within the class as pointers which point to dynamically allocated arrays.
Whenever it is required to change the size of an Array object, be sure to do it by dynamically allocating a new array of the proper size, copying the appropriate values to the new array, and then unallocating the old array.
At a minimum, your class should include the following:
class Array

{

 public:

       /* Add all of the required member functions here. */

 

 private:

         int size;

         int *array;

};

0
Comment
Question by:Yukia
3 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13970981
Actually you need to show some efforts yourselves befroe we could help with homework.

You should create the class header with all functions/constructors/destructor described above and add as much code as possible. If you don't know how to implement make an appropriate comment. Try to compile a litte test prog and try to solve simple compile errors like "variable xyz undefined" yourself.

Regards, Alex
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 13970983
This looks very much like a homework problem?
0
 
LVL 4

Accepted Solution

by:
furqanchandio earned 2000 total points
ID: 13972558
hi

impressive. if u can write all that in english i see no reason why you cant set up atleast the skeleton of this program with just a little effort.

go ahead if you have any peoblems we will help you

cheers
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question