This document provides instructions for programming homework assignment #3 involving inheritance and composition in C++. Students are asked to write class definitions for a Date class with year, month, day data members and related functions. A Film class is defined containing title, director, length, release date data and related functions. Entertainment and Educational classes inherit from Film and contain additional data members and functions specific to each type of film. The document includes sample main code to test the classes and instructions for submitting the completed assignment files.
1. Programming Homework #3: Inheritance and Composition
Write the definition for the following classes
Class Date:
Data members: class Date has 3 data members which are year, month, and day
ointyear, month, day;
Member functions:
oNote: no default constructor is needed.
oConstructor with parameters to initialize year, month, and day
oSetDate: sets values to the data members of the class i.eyear, month, and day
oGetDate: returns the data members of the class i.eyear, month, and day
oPrint: prints year, month, and day
Class Film:
classFilm
{
public:
// Constructor: takes title, director, length, and year, month, and day
Film (string, string, int, int, int, int);
// FileInformation: prints all film information
voidFilmInformation () const;
voidSetTile (string);
voidSetDirector (string);
voidSetLength (int);
voidSetReleaseDate (Date);
stringGetTile () const;
stringGetDirector () const;
intGetLength () const;
Date GetReleaseDate () const;
private:
string title; // film title
string director; // film director
intlength; // film length in minutes
Date releaseDate; // file release date
};
is a is a
has a
Film
Entertainment Educational
Date
Class Entertainment:
Class Entertainment inherits class Film and has some data members unique to it
Data members (unique to class Entertainment)
otype: holds the type of the film e.g. (Action, Comedy, SciFi, …)
orating: holds the rating of the film e.g. (G, PG, PG-13, R, …)
Member functions:
oNote: no default constructor is needed.1
oConstructor with parameters to initialize type and rating
oSetTypeand SetRatingto set the values of type and rating
oGetTypeand GetRatingto return the values of type and rating
oFilmInformation: override the member function FilmInformationso it also prints the
type and
rating
Class Educational:
Class Educational inherits class Film and has some data members unique to it
Data members (unique to class Educational)
2. osubject: holds the subject of the film e.g. (Science, Math, Earth Science, …)
ogradeLevel: holds the appropriate grade level of the film e.g. (1, 2, 3, 4, …)
Member functions:
oNote: no default constructor is needed.
oConstructor with parameters to initialize subject and gradeLevel
oSetSubjectand SetLevelto set the values of subject and gradeLevel
oGetSubjectand GetLevelto return the values of subject and gradeLevel
oFilmInformation: override the member function FilmInformationso it also prints the
subject
andgradeLevel
Testing:
Here’s a sample main to test some functionalities of your code. Make sure you
extensively test all the
functionalities of your classes
#include <iostream>
using namespace std;
#include "Film.h"
#include "Entertainment.h"
#include "Educational.h"
voidmain ()
{
Entertainment DieHard ("Action", "PG", "Die Hard", "John McTiernan", 90, 88,
5, 2);
DieHard.FilmInformation ();
cout<<endl;
cout<<DieHard.GetDirector ()<<endl;
cout<<DieHard.GetTile ()<<endl;
DieHard.SetLength (95);
cout<<endl;
DieHard.FilmInformation ();
cout<<endl<<endl;
Educational Algebra ("Math", 5 ,"Algebra for Kids", "John Smith", 45, 2011,
11, 25);
Algebra.FilmInformation ();
Algebra.GetReleaseDate ().Print ();
Algebra.SetDirector ("Jeff");
Algebra.SetLevel (7);
cout<<endl;
Algebra.FilmInformation ();
}
Submission:
Upon the successful completion of the above tasks you should have the following files:
main.cpp, Date.h, Date.cpp, Film.h, Film.cpp, Entertainment.h, Entertainment.cpp,
Educational.h, and
Educational.cpp
Do not submit these files individually.
Do not submit your work as a word document or copy it as a text into
an email.
Select all 9 files, right click and compress it to generate
FirstName_LastName_Section#.zip