Question: main.cpp #include video.h int main() { Video myVideo(Lion King, 2017); Video yourVideo; //set yourVideo's information yourVideo.setTitle(Happy Feet); yourVideo.setYear(2010); //print myVideo and yourVideo cout //assignment op

 main.cpp #include "video.h" int main() { Video myVideo("Lion King", 2017); Video

main.cpp

#include "video.h" int main() { Video myVideo("Lion King", 2017); Video yourVideo;

//set yourVideo's information yourVideo.setTitle("Happy Feet"); yourVideo.setYear(2010);

//print myVideo and yourVideo cout

//assignment op overload check yourVideo = myVideo;

//copy constructor check Video aVideo(myVideo);

//print all videos cout

return 0; }

video.h

#ifndef VIDEO_H #define VIDEO_H //Class object for video has title and yearReleased #include #include using namespace std;

//constants const int MAXCHAR = 101; //data type for Video class Video { private: char *title; int yearReleased; public: //constructors //default constructor Video(); //constructor with parameters Video(const char [], int); /*TODO: copy constructor*/ //destructor ~Video(); //mutator functions void setTitle(const char []); void setYear(int); //accessor functions void getTitle(char []) const; int getYear() const; //print video void printVideo(); /*TODO: assignment operator overloading*/ }; #endif

video.cpp

//This is the implementation file for video.h (the Video class) #include "video.h"

//default constructor Video::Video() { //allocate memory for title title = new char[MAXCHAR]; strcpy(title, "No title"); yearReleased = 0; }

//constructor with parameters Video::Video(const char tempTitle[],int yearReleased) { //allocate memory title = new char[strlen(tempTitle) + 1]; strcpy(title, tempTitle); this->yearReleased = yearReleased; }

//TODO: Copy Constructor

//destructor Video::~Video() { //deallocate memory for title if(title) { delete [] title; title = NULL; } } //mutator functions void Video::setTitle(const char newTitle[]) { //if title exists, delete and reallocate just enough for newTitle if(title) { delete [] title; title = NULL; } title = new char[strlen(newTitle)+1]; strcpy(title, newTitle); }

void Video::setYear(int newYear) { yearReleased = newYear; }

//accessor functions void Video::getTitle(char returnTitle[]) const { strcpy(returnTitle, title); }

int Video::getYear() const { return yearReleased; }

//prints to console void Video::printVideo() { cout

//TODO: assignment operator overloaded

20.10 LAB: Video Class (Copy Constructor and Assignment op overload) You are given a video class (in files video.h and video.cpp), and the client code (main 0 in main.cpp) to test the video class. Write code to do the following: - Write the prototype for the copy constructor in video.h and the definition in video.cpp for the Video class - Write a copy assignment operator for the Video class that does a deep copy of the data members and , then returns *this. - Check main.cpp to see how the copy constructor and the assignment operator is tested for the Video class. You need not change main( in main.cpp. - Sample output for the given program: myvideo information: Lion King; 2017; yourvideo information: Happy Feet; 2010; myvideo information: Lion King;2017; yourvideo information: Lion King;2017; aVideo information: Lion King;2017

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!