Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 4: Copy constructors, assignment operators, deep vs. shallow copy; templates and iterators at Due Wednesday by 11:59pm Points 1 Submitting a file upload Available

image text in transcribedimage text in transcribed

Lab 4: Copy constructors, assignment operators, deep vs. shallow copy; templates and iterators at Due Wednesday by 11:59pm Points 1 Submitting a file upload Available Jan 23 at 12am - Feb 1 at 11:59pm Attention: All files used in this lab can be downloaded by following this link, open Lab4, select and download the Lab4AllFiles folder (you will receive a .zip file containing all the files in that folder). Exercise 1: This exercise is designed to present a class that has both a copy constructor and an assignment operator and to illustrate the difference between deep and shallow copies. Please download and compile the code in Lab4/Exercise1 (MyClass.h, MyClass.cpp, and CopyAssignTest.cpp). Then do the following (30 minutes coding): 1. Question: Look at the code; do you think that MyClass::operator=() is doing a deep or shallow copy? Take Away: Know the difference between deep and shallow copy. 2. Question \& Coding: Do you notice any warning posted by the compiler? Is there a memory leak issue? How can you fix it? Take Away: How to eye-ball memory leak (constructor and destructor) 3. Coding: Is MyClass::setlp() implemented correctly? What exactly does it do? Take Away: What to watch out for when assigning value to a pointer type. 4. Coding: Derive a new subclass of MyClass, name it "MySubClass" and define a private "int" type data member named "subClassData" in this new class. What do you need to do is to ensure that the correct copy constructor and assignment operators are called. Verify that your new class works correctly. Take Away: When to and how to call super class constructor/methods Exercise 2: Template functions and classes. Be sure to create all necessary driver file, hh file and .cpp files. (60 minutes coding) 1. Coding: Write a template function for bubble sort. Take Away: Bubble sort is not supposed to be challenging, practice template syntax 2. Coding: Dynamically allocate an array of Square objects, using the Square Class provided in Lab4/Exercise2 (Square.h, Square.cpp) (with overloaded " Lab 4: Copy constructors, assignment operators, deep vs. shallow copy; templates and iterators at Due Wednesday by 11:59pm Points 1 Submitting a file upload Available Jan 23 at 12am - Feb 1 at 11:59pm Attention: All files used in this lab can be downloaded by following this link, open Lab4, select and download the Lab4AllFiles folder (you will receive a .zip file containing all the files in that folder). Exercise 1: This exercise is designed to present a class that has both a copy constructor and an assignment operator and to illustrate the difference between deep and shallow copies. Please download and compile the code in Lab4/Exercise1 (MyClass.h, MyClass.cpp, and CopyAssignTest.cpp). Then do the following (30 minutes coding): 1. Question: Look at the code; do you think that MyClass::operator=() is doing a deep or shallow copy? Take Away: Know the difference between deep and shallow copy. 2. Question \& Coding: Do you notice any warning posted by the compiler? Is there a memory leak issue? How can you fix it? Take Away: How to eye-ball memory leak (constructor and destructor) 3. Coding: Is MyClass::setlp() implemented correctly? What exactly does it do? Take Away: What to watch out for when assigning value to a pointer type. 4. Coding: Derive a new subclass of MyClass, name it "MySubClass" and define a private "int" type data member named "subClassData" in this new class. What do you need to do is to ensure that the correct copy constructor and assignment operators are called. Verify that your new class works correctly. Take Away: When to and how to call super class constructor/methods Exercise 2: Template functions and classes. Be sure to create all necessary driver file, hh file and .cpp files. (60 minutes coding) 1. Coding: Write a template function for bubble sort. Take Away: Bubble sort is not supposed to be challenging, practice template syntax 2. Coding: Dynamically allocate an array of Square objects, using the Square Class provided in Lab4/Exercise2 (Square.h, Square.cpp) (with overloaded

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_2

Step: 3

blur-text-image_3

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

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

What is a solenoid?

Answered: 1 week ago