$29
In the first phase of the assignment, implement in C++ a class My_vec that can hold data of character type (char). The description of the functions for data manipulation is provided in the first set of the lecture notes, see the slide 8. In the second phase, write a generic version of the class My_vec that can handle any type of data.
Instructions:
Download the supplementary file with a sample code from the class webpage.
Your files should be arranged as follows
Declaration of My_vec class in My_vec.h
Definition (implementation) of My_vec class in My_vec.cpp
Testing code in Main.cpp
Use Makefile by calling make
Compile your program using the Linux machine command line: g++ -std=c++11 *.cpp
or
make all
Run your program by executing
./Main
Be sure to increase or decrease allocated memory when you insert to or remove from a vector.
Be sure to check the vector size against its capacity. If its size is greater than its capacity then allocate more memory by doubling the current capacity and copying the content of the vector.
Points Distribution for Assignment (for part 1 and 2)
My_vec class member functions:
(4 pt) elem_at_rank
(8 pt) insert_at_rank
(4 pt) replace_at_rank
(8 pt) remove_at_rank
(8 pt) constructors and copy constructor
(12 pt) destructor, the assignment operator
(6 pt) overloading the bracket [] operator
non-member functions:
(6 pt) overloading <<operator (output operator)
(10 pt) find_max_index – find an index of the largest object in a vector
(10 pt) sort My_vec using the function find_max_index
(14 pt) Testing program (main function)
(5 pt) Programming style: naming, indentation, whitespace, comments, declaration, variables and constants, expressions and operators, line length, error handling and reporting. Please refer to the document PPT-style.
(10 pt) Generic version of My_vec
The templated “My_vec” uses the data type as a parameter. Recall the templated vector material, slides 16-22 and follow the instructions below
Templates should be declared and defined in the TemplatedMy_vec.h file. Move the content of My_vec.cpp and My_vec.h to TemplatedMy_vec.h
Replace char type by generic type T. Later, in the main function, T can be specified as any type: char, string or a user-defined type.
To create a templated class with generic type T, you must replace a declaration/return type char by T.
Use the generic type T anywhere throughout the class TemplatedMy_vec.
Add the keyword template <typename T before a class declaration.
If a member function is defined outside the class declaration, change the function signature, that is, replace My_vec:: by TemplatedMy_vec<T::
Compile and run the generic version similarly as in the part 1 of the assignment.
(5 pt) Test all the operations for the generic version using at least three different types of objects.
Typed report (preferably using "LyX/LATEX") – Report Instructions
(1 point) Cover Page
(1 pt) Program Description; Purpose of the Assignment
(4 pt) Data Structures Description
Theoretical definition
Real implementation
Analysis of best and worst scenarios for vector.
(2 pt) Instructions to Compile and Run your Program; Input and Output Specifications
(2 pt) Logical Exceptions (and bug description)
(5 pt) C++ object oriented or generic programming features, C++11 features.
(5 pt) Testing results
— © Teresa Leyk
3