CSCE240 Project 3-Pointer “ArrayList” Solved

35.00 $

Category:

Description

Rate this product

Topics Covered​:

  • Master the use of functions in C++.
  • Utilize call-by-value and call-by-reference implementation of functions.
  • Demonstrate mastery of pointer arrays.
  • Become familiar with dynamic memory allocation using pointers.
  • Basic use of header file.

Description: 

Develop a program that mimics some of the functionalities of an ArrayList in Java. Your program should maintain a pointer array of doubles and be able to perform the following functions:

  1. void insert(int index, double num, double *&arr, int &size)
    1. Adds an element (​num​) to the array (​arr​) at a given position (​index​) and updates the size.
    2. You may allow the user to add to the immediate end of the array (at position n for an array of n elements) but not past. You should print an error message if they try to print beyond these bounds.
  2. void remove(int index, double *&arr, int &size)
    1. Removes an element from the array (​arr​) at a given position (​index​) and updates the size.
    2. If index is out of the bounds of the arr then an error message should be printed.
  3. int get(int index, double *arr, int size)
    1. Returns the element at the given position (​index​).
    2. Should check if the index given is outside the bounds of the array. If it is out of bounds an error message should be printed.
  4. void clear(double *&arr, int &size)
    1. Clears all elements of the array (​arr​) and updates the size (​size​) to be 0.
  5. int find(double num, double *arr, int size)
    1. Returns the first index in which a given element (​num​) is found in the array (​arr​).

If not found -1 is returned.

  1. bool equals(double *arr1, int size1, double *arr2, int size2)
    1. Returns true if the contents of the two arrays are equal and false if they are not equal.
  2. void init(double *arr, int size)
    1. Populates the elements of the array (​arr​) with input from the user (or via file redirection).
  3. void print(double *arr, int size)
    1. Prints the elements of the array.

 

Additional Specifications:

  • I have provided two files: sampleMain.cpp and myArray.h
    • I will be using sampleMain.cpp to test your program so you should test using that.

○    In myArray.h you should write ALL YOUR CODE. This is the file that you will be required to submit. DO NOT RENAME THIS FILE!

  • DO NOT USE GLOBAL VARIABLES.
  • You should check your code with Valgrind for memory leaks. You will get points off for both memory leaks as well as errors reported in Valgrind.
  • Your program should consist of a header that contains the following information:
    • First name and last name of the programmer.

○    Date and time of the program completion.

○    A brief description of the program function.

○    Input requirements and format.

○    The output of the program.

○    Any additional needed comments (e.g. related to compilation, execution or other requirements).

  • Each function needs to be properly commented.
    • Your comments need to include a description of the function.

○    Description of the inputs.

○    Description of the output.

○    Any additional notes assisting future programmers to comprehend the complex portions of your functions.

  • Make sure your program compiles and runs on one of the Linux machines in the Linux lab before you submit.
  • Submit the source code (.h) not the executable (a.out).

  • Project3-6ojqv1.zip