Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1) Write in C++ a class My_vec that can hold data of character type 2.)

ID: 3664673 • Letter: Q

Question

Question

1) Write in C++ a class My_vec that can hold data of character type

2.) Write a generic version of the class My_vec that can handle any type of data.

The following must be implemented in the program:

(1) My_vector Class Member Functions:
(a) elem_at_rank

(b) (insert_at_rank). (replace_at_rank), (remove_at_rank) (constructor and copy constructor),( destructor and the assignment operator) (overloading the [] operator)

(c) non-member functions: (overloading << operator), (find_max_index - an index of the largest objectin a vector), (sort My_vector using the function find_max_index)

(d) Testing program (main function)

(e) Programming style: naming, indentation, whitespace, comments, declaration, variables and constants, expressions and operators, line length, error handling and reporting.


(2) Write a generic version of My_vector
Test all the operations listed above using at least three different type of objects.

Main.cpp

My_vec.h

// main.cpp //Tests all functionality of the y ves class #include #include #include

Explanation / Answer

#ifndef EMPLOYEEINFO_H #define EMPLOYEEINFO_H #include #include using namespace std; // This class has two data members to hold the employee ID // and the name of the employee. class EmployeeInfo { private: int empID; // To hold employee ID number string empName; // To hold employee name public: // Default Constructor EmployeeInfo(); // Constructor EmployeeInfo(int, string); // Mutators void setEmpID(int); void setEmpName(string); // Accessors int getEmpID(); string getEmpName(); // Overloaded operator. This works directly with // the insert function of BinaryTree.h more specifically // line 71. *For my knowledge* bool operator < (const EmployeeInfo &e) { if (empID value value) insert(nodePtr->left, newNode); // Search the left branch else insert(nodePtr->right, newNode);// Search the right branch } //********************************************************* // insertNode creates a new node to hold item as its value* // and passes it to the insert function. * //********************************************************* template void BinaryTree::insertNode(T item) { TreeNode *newNode; // Pointer to a new node // Create anew node and store num in it newNode = new TreeNode; newNode->value = item; newNode->left = newNode->right = NULL; // Insert the node insert(root, newNode); } //********************************************************** // destroySubTree is called by the destructor. It deletes * // all nodes in the tree. * //********************************************************** template void BinaryTree::destroySubTree(TreeNode *nodePtr) { if (nodePtr) { if (nodePtr->left) destroySubTree(nodePtr->left); if (nodePtr->right) destroySubTree(nodePtr->right); delete nodePtr; } } //********************************************************** // searchNode determines if a value is present in the tree.* // If so, the function returns true. Otherwise it returns * // false. //********************************************************** template bool BinaryTree::searchNode(T item) { TreeNode *nodePtr = root; while (nodePtr) { if (nodePtr->value == item) return true; else if (item value) nodePtr = nodePtr->left; else nodePtr = nodePtr->right; } return false; } #endif #include "EmployeeInfo.h" #include "BinaryTree.h" #include using namespace std; int main() { // Create an instance of BinaryTree BinaryTree tree; // Create an EmployeeInfo object EmployeeInfo emp1(1021, "John Williams"); EmployeeInfo emp2(1057, "Bill Witherspoon"); EmployeeInfo emp3(2487, "Jennifer Twain"); EmployeeInfo emp4(3769, "Sophia Lancaster"); EmployeeInfo emp5(1017, "Debbie Reece"); EmployeeInfo emp6(1275, "George McMullen"); EmployeeInfo emp7(1899, "Ashley Smith"); EmployeeInfo emp8(4218, "Josh Plemmons"); tree.insertNode(emp1); tree.insertNode(emp2); tree.insertNode(emp3); tree.insertNode(emp4); tree.insertNode(emp5); tree.insertNode(emp6); tree.insertNode(emp7); tree.insertNode(emp8); // Search for an employee char again = 'y'; // To hold yes int id; // To hold ID number from user cout again; if (again) { do { cout > id; // Create an EmployeeInfo object to store the user's // search parameters EmployeeInfo info; info.setEmpID(id); // If search finds what the user entered display the // corresponding employee if (tree.searchNode(info)) { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote