Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

In this assignment, you will be required to implement a generic SortedArray Container class. Elements in the SortedArray should be always in the non-decreasing order. Unlike basic C++ arrays that burden the programmer with the task of keeping track of its capacity and utilization, the SortedArray must also provide an interface to the programmer to allow for retrieval of information about the number of elements inside it as well as the maximum number of elements it can store. 

Requirements 
• SortedArray MUST store elements internally in a C++ array. Please refer to the vector implementation example in the textbook, page 81-82. 
• SortedArray MUST be able to store elements of any comparable type that provides operator < and operator =.
• All the elements in the SortedArray should always be in non-decreasing order. 
• SortedArray MUST have a no-argument constructor that initializes its internal array to some size. This size MUST NOT is so large as to prevent a calling program to initialize several instances of SortedArray in a single execution. Suggested length values are 16 or 64. 
• Every SortedArray instance holding n elements MUST accept insertions as long as the system has enough free memory to dynamically allocate an array of 2n+1 elements at insertion request time, regardless of the initial capacity of its internal array. If the system does not have such free memory, SortedArray MUST report an error message as the result of the insertion request. 
• SortedArray MUST implement the full interface specified in the file SortedArray.h 
• You MUST NOT change the file SortedArray.h 
• You class implementation must be in the file SortedArray.cpp
• You must submit a memo (a single .doc file) with the time complexity analysis of each member function.
• I will provide a program to test your class. Compile and run the program with the class. You should probably write other test program(s) to make sure everything works. 

Interface 
The interface of SortedArray is provided in the attached SortedArray.h file.
It provides for the following public functionality, all of which can be achieved using an internal array representation for the data.
• SortedArray(): no-argument constructor. Initializes the internal array to some pre-specified size.
• ~SortedArray(): destructor.
• SortedArray(const SortedArray&): copy constructor.
• SortedArray& operator= invoked by the copy constructor.
• const Object& operator [](int)const: returns the ith element stored in this SortedArray, where the 1st element is the element in the front.
• Object& operator[] (int): mutator that returns the ith element stored in this SortedArray.
• bool equals (const SortedArray & rhs): returns true if this array and the rhs array have the same elements, in the same order. (The capacity of the containers may be different, only the actual number of elements in each must be the same for the call to return true.)
• void clear(): removes all the elements of the container. This SortedArray should still be useful after a call to this function.
• bool empty(): returns true if the SortedArray contains no elements, and false otherwise.
• void print(ostream& os, char delimiter = ',') const: print all elements of SortedArray to ostream os. Each element is followed by a delimiter except the last element. 
• int size(): returns the number of elements stored in this SortedArray, which may be less than its capacity.
• int capacity(): returns the current capacity of this SortedArray.
• void reserve(int newCapacity): sets the new capacity. MUST report an error current size is already larger than the requested capacity. MAY do nothing if the existing capacity (but not the size) is larger than the requested capacity.
• void insert(const Object &): insert new elements into the correct position in the array, sliding elements over the position to right, as needed.
• void deleteMin( ): remove the element in position 0, and slide over all the other item.
• void deleteMax( ): remove the last element.
• const Object & findMin( ) const: find the minimum element.
• const Object & findMax( ) const: find the maximum element.
• int binarySearch (const Object & x): Performs the standard binary search using two comparisons per level. Returns index where item is found or -1 if not found. Please refer to Figure 2.9 on the Page 59 of the textbook.

What to turn in:

Upload all your files as a single ZIP file to the VLT under the "P1" folder. You should include two documents, your source code and your memo (a single .doc file). Your source code must be named SortedArray.cpp.


How the program will be graded.

Analysis 
Time Analysis Worst case O() of each member function with explanation. 
Program Style 
Your Name 
Description of the problem in your own words 
Overall program style and comments
Pre/Post conditions for functions
Functionality

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M9646755

Have any Question?


Related Questions in C/C++

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As