Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

Students also viewed these Databases questions

Question

ree! ree

Answered: 1 week ago

Question

Was there an effort to involve the appropriate people?

Answered: 1 week ago

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago