Some additional information: getIndex function (using linear search): 1) Accepts a value of type T as a parameter. 2) Iterate through the array checking if the value is in the array. If it is return the index. If it is not, return -1. Example Given 5 10 15 20 25 30 and value 15, return the index 2.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 2RQ
icon
Related questions
Question

NEED HELP WITH THIS C++ QUESTION

Some additional information:
getIndex function (using linear search):
1) Accepts a value of type T as a parameter.
2) Iterate through the array checking if the value is in the array.
If it is return the index.
If it is not, return -1.
Example
Given 5 10 15 20 25 30 and value 15, return the index 2.
erase function:
1) Accepts an index as a parameter.
2) Use a loop to shift all elements from the index to the end of the
array to the left by 1.
3) Decrement size by 1.
Example
Given 5 10 15 20 25 30 and index 3 we would shift 25 and 30 to the left
thereby overwriting the number 20 resulting in the array 5 10 15 25 30.
Transcribed Image Text:Some additional information: getIndex function (using linear search): 1) Accepts a value of type T as a parameter. 2) Iterate through the array checking if the value is in the array. If it is return the index. If it is not, return -1. Example Given 5 10 15 20 25 30 and value 15, return the index 2. erase function: 1) Accepts an index as a parameter. 2) Use a loop to shift all elements from the index to the end of the array to the left by 1. 3) Decrement size by 1. Example Given 5 10 15 20 25 30 and index 3 we would shift 25 and 30 to the left thereby overwriting the number 20 resulting in the array 5 10 15 25 30.
Implementation
Implement a class SomeObj:
1) data member:
a) id
an integer named
2) constructors:
a) default
b) single parameter constructor to set the value of id
3) functions:
a) getId
return the value of id
a) output
output the value of id to console
Implement a Template Class MyArray (modify/augment example 12.6):
1) data members:
a) data
dynamic array of type T
b) capacity
c) size
capacity of the dynamic array
number of elements in the array
2) constructors:
- create an empty array of capacity 10
- create an array of a specified capacity
a) default
b) single parameter
3) functions:
a) getSize
b) getCapacity
return the size
return the capacity
b) grow
private grow function (capacity*2) +1
given a value, return its index or -1 if not found
c) getIndex
use a linear or binary search
d) push_back
append element to the end of the array
- remove the element at the specified index
- overloaded [] operator (regular and const versions)
e) erase
f) []
4) the big three
A Non-Member Print function:
1) Prints the contents of a template MyArray object given via as a parameter.
Main:
1) Instantiate a template MyArray object of SomeObj pointers.
2) Instantiate 10 SomeObj objects and append them to the MyArray object.
3) Print the SomeObj contents of the MyArray object.
Transcribed Image Text:Implementation Implement a class SomeObj: 1) data member: a) id an integer named 2) constructors: a) default b) single parameter constructor to set the value of id 3) functions: a) getId return the value of id a) output output the value of id to console Implement a Template Class MyArray (modify/augment example 12.6): 1) data members: a) data dynamic array of type T b) capacity c) size capacity of the dynamic array number of elements in the array 2) constructors: - create an empty array of capacity 10 - create an array of a specified capacity a) default b) single parameter 3) functions: a) getSize b) getCapacity return the size return the capacity b) grow private grow function (capacity*2) +1 given a value, return its index or -1 if not found c) getIndex use a linear or binary search d) push_back append element to the end of the array - remove the element at the specified index - overloaded [] operator (regular and const versions) e) erase f) [] 4) the big three A Non-Member Print function: 1) Prints the contents of a template MyArray object given via as a parameter. Main: 1) Instantiate a template MyArray object of SomeObj pointers. 2) Instantiate 10 SomeObj objects and append them to the MyArray object. 3) Print the SomeObj contents of the MyArray object.
Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage