Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need to do this lab exercise to unlock my assignment. Please help. 1 . In the previous lab exercises, the Registration class had a
I need to do this lab exercise to unlock my assignment. Please help.
In the previous lab exercises, the Registration class had a raw array of results. This array itself was not encapsulated inside a class to provide controlled access to the array.
For this and later exercises, a data structure needs to be created that encapsulates a raw array. For our purposes, we will call this data structure a Vector. Vector is a templated data structure that encapsulates a raw dynamic array uses new to create memory on the heap
As Vector is templated, it can store anything, including itself.
The closest analogy would be the Java ArrayList which is also templated. You would have used ArrayList in the prerequisite unit, but in this unit, you are building something similar. Vector is an array, so part of the methods of Vector. The raw array is a private member of the template class Vector. You write the Vector class and provide controlled access to the dynamic raw array via the Vectors public methods. Your Vector class is not the same as the STL std::vector, so please do not attempt to duplicate the STL vector. You will get a bloated result and your work will be penalised. The Vector class needs to be minimal but complete.
Do not attempt to the mimic the STL vector std::vector Methods or operators should not have duplicated functionality. See Rule Prefer minimal classes to monolithic classes in the unit's reference book: C Coding Standards: Rules, Guidelines, and Best Practices by Sutter and Alexandrescu. ebook is in the library if the following link does not work. See My Unit Readings in LMS
Do not use the STL std::vector class as a service data structure to your Vector ie you must not have #include in any part of your code for this lab or assignment as no marks will be allocated if you do
The template Vector class that you have to write is an example of a linear data structure. The entire interfacedeclaration and implementation template Vector class is written in a file called Vector.h because it is a template class. The textbook explains schemes for having cpp files for template classes. There is no Vector.cpp for the template Vector class in this lab and assignment There is no need to complicate the issue by having a cpp file for template classes.
It is absolutely essential that you separate the interface of Vector and its implementation even though only one file Vector.h exists. Not making this separation will result in a mark of in the assignment and exam.
Vector.h contains the following:
#ifndef VECTORH
#define VECTORH
The class interfacedeclaration must have Doxygen comments put these in
Follow the style in modelfile.h
template
class Vector This is NOT the std::vector.
public:
Vectorint n; done for you
you fill in the rest and include Doxygen comments
make sure only method declarations are here, otherwise
no marks can be given.
So do not clutter the class declaration and keep the class
interface clean.
private:
the encapsulated dynamic array
fill in
; end of interfacedeclaration of the template class
class implementation follows with normal comments
you fill in the rest
for template classes, the implementation is in h below the interfacedeclaration shown above.
Do not put the implementation in a cpp file.
The compiler cant create an object file from an unbound type
in a template implementation in a cpp file
Read the textbook for an explanation.
#endif
How big is the Vector going to be Once you create the internal array on the heap using new the size is fixed. What happens if there is more data to be added? The Vector would need to resize itself grow once full. The user of Vector should not be bothered with this detail as the Vector would take care of this behind the scenes. Naturally, you as the designer of Vector would have to write the code to do the resize. The amount to resize is typically to times current size.
The required Vector class is a container class. It must not violate the Law of Demeter. Find out what this law is Wikipedia has an understandable explanation. Did you keep or violate this law in Lab
You will need to unit test this Vector before using it Discuss your ideas with your tutor. You will need this template Vector class for the assignment.
Your use of this Vector class in question of this lab would need to be demonstrated in person to your tutor to order to be allocated a mark for the data structure in the Assignment.
In the previous labs, you were using an array of Result objects. Assuming you had the following in Registration.h:
Result resultsMaxResults; you may have been using different names for array and max size of array, so amend this example accordingly.
Change the above to:
Vector resultsMaxResults; use the same name
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started