PSY Theories of Personality Case Study
Order Number |
636738393092 |
Type of Project |
ESSAY |
Writer Level |
PHD VERIFIED |
Format |
APA |
Academic Sources |
10 |
Page Count |
3-12 PAGES |
PSY Theories of Personality Case Study
Module Four Journal Template
For your journal, complete this template by replacing the bracketed text with the relevant information. Your responses should each be about 2 to 5 sentences in length.
[Insert text]
[Insert text]
[Insert text]
[Insert text]
[Insert text]
[Insert text]
[Insert text]
9
Q4 (70 pts). In this question, you will write your own container class named MyCon similar to
vector class in C++. Your class must be a template class which will contain its elements in an
array named myArray. Since this class will be a template class, you should include the function
definitions at the end of the header file. You can also check the Stack example in Chapter 9. You
should keep the size and capacity of your container in two separate attributes named mySize
and myCapacity. Therefore, your class will have three data members: one generic dynamic
array (you should use pointer representation as given in the Stack example) and two integers.
In this container, the elements will always be sorted in increasing order. As the function
members of your class write the following functions:
container, creates a new array with the given capacity, and stores new array in myArray.
The constructor should also set myCapacity to the parameter value and mySize to 0. If
the parameter is not a positive number, you should set the capacity as 10 and create the
array with 10 elements.
element to the appropriate place in myArray. Note that the elements must always be
sorted. For instance, if the container elements are [3, 7, 9, 12] and the parameter of add
function is 5, it will be added as the second element. The elements will be [3, 5, 7, 9, 12]
after addition. You should also update the size (mySize) accordingly. The function should
return nothing. If the capacity is full, you should
in the array and removes all occurrences of that element in the array. You should shift
the elements after removal. For instance, if the elements are [3, 5, 5, 7, 9, 12], and the
parameter of remove function is 5, the container elements will be [3, 7, 9, 12] after the
removal. You should also update the size (mySize) accordingly. The function should
return nothing.
by a space. Note that you should not print all array content, you should print the
elements in the container. For instance, when you create an integer container with
capacity 100, myArray will contain 100 zeros, but you should not display them.
Therefore, you should iterate your loop from 0 to mySize-1. The function should return
nothing.
the element at the given index.
parameter and searches it in the container. The function should return true or false.
container by setting size as 0. The function should return nothing.
An example driver class (MyConDriver.cpp) and its output are given below.
Size of b: 0
Capacity of b: 10
4
2 4
2 4 9
2 4 4 9
2 4 4 8 9
1 2 4 4 8 9
1 2 4 4 8 9 9
a.sum(): 37
a.at(3): 4
1 2 8 9 9
1 2 8 9 9
1: FOUND.
2: FOUND.
3: NOT FOUND.
4: NOT FOUND.
5: NOT FOUND.
6: NOT FOUND.
7: NOT FOUND.
8: FOUND.
9: FOUND.
10: NOT FOUND.
Size of a: 0
Capacity of a: 12
#include <iostream> #include “MyCon.h” using namespace std; int main() { MyCon<int> a(3); MyCon<double> b(-10); cout << “Size of a: ” << a.getSize() << endl; cout << “Capacity of a: ” << a.getCapacity() << endl; cout << “Size of b: ” << b.getSize() << endl; cout << “Capacity of b: ” << b.getCapacity() << endl; a.add(4); a.display(); a.add(2); a.display(); a.add(9); a.display(); a.add(4); a.display(); a.add(8); a.display(); a.add(1); a.display(); a.add(9); a.display(); cout << “a.sum(): ” << a.sum() << endl; cout << “a.at(3): ” << a.at(3) << endl; a.remove(4); a.display(); a.remove(7); a.display(); for (int i = 1; i <= 10; i++) { if (a.search(i)) { cout << i << “: FOUND.” << endl; } else { cout << i << “: NOT FOUND.” << endl; } } a.clear(); a.display(); cout << “Size of a: ” << a.getSize() << endl; cout << “Capacity of a: ” << a.getCapacity() << endl; }
PSY Theories of Personality Case Study