Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Add comments and the output. Description: Part 1: define a C++ class LargeType which will store a single member variable: vector T> data initialized

Please Add comments and the output.

image text in transcribed

image text in transcribed

Description: Part 1: define a C++ class LargeType which will store a single member variable: vector T> data initialized with some size in the constructor. Because LargeType has no heap-allocated member variables, there is no need to define the big 5 (can omit the big 5 entirely or set them to default as in section 1.5.6). However, LargeType must be a class template (section 1.6.2), and it must also overload the operator function (section 1.6.3) so two LargeType objects can be compared with each other. LargeType should provide a single accessor method getSize () which takes no arguments and returns an int (the size of data). Part 2: convert insertion sort pseudocode (below) to C++ and apply it to a vector of LargeType objects. It must also be a template function (section 1.6.1). INSERTION-SORT (A) 12345678forj2tolength[A]dokeyA[j]InsertA[j]intothesortedsequenceA[1j1].ij1whilei>0andA[i]>keydoA[i+1]A[i]ii1A[i+1]key N.B: the pseudocode above assumes that array indices start at 1 , while in C++ they start at 0 (the first element in a C++ array or vector is at index 0 ). To apply this on your vector of LargeType objects, your vector must contain LargeType objects with data of different sizes (can use random number generation). Then, insertion sort will sort the vector of LargeType objects in ascending order, based on the size of each LargeType instance's data field. Part 3: create a second C++ class called LargeTypeRaw where instead of using vector to hold data, use the built-in C++ array as the type of the data member variable (can be a simple int* data). This will necessitate implementation of the big 5 , because you will now have heap-allocated memory in your LargeTypeRaw instances (check 'Rule of the big 5 ' pdf on moodle). Be sure to test your LargeTypeRaw class by running code that calls all methods of the big 5. Part 4: timing experiments. Using any timing library (ctime, for example) measure the performance of your insertion sort implementation on both LargeType and LargeTypeRaw. You can test both on a vector size 50,000. Report the time taken for sorting as a comment at the top of your source code file. Submission: Submit your c++ source code with your name and the results of the timing experiment as a comment at the top, as well as any additional remarks on your source code (especially if your work is incomplete). Marks: part 1=30%, part 2=30%, part 3=20%, part 4=20%. Hints: The C++ skeleton for the LargeType class (part 1 ) is provided below. You need to fill in the method bodies and convert it to a template class. class LargeType \{ public: explicit LargeType(int size =10 ) : data(size) \{\} int getSize() const \{ // YOUR CODE HERE 3 bool operator data; And here is a sample main (the timing code for part 4 is not included)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

6. How do histories influence the process of identity formation?

Answered: 1 week ago