SlideShare a Scribd company logo
1 of 2
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)
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

More Related Content

Similar to Programming homework

Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxhartrobert670
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfKiranKumari204016
 
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docxQuestion- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docxHarryXQjCampbellz
 
Pf cs102 programming-10 [structs]
Pf cs102 programming-10 [structs]Pf cs102 programming-10 [structs]
Pf cs102 programming-10 [structs]Abdullah khawar
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptxarjun431527
 
Python-oop
Python-oopPython-oop
Python-oopRTS Tech
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Manykenatmxm
 
Implementation Your program shall contain at least the follo.pdf
Implementation Your program shall contain at least the follo.pdfImplementation Your program shall contain at least the follo.pdf
Implementation Your program shall contain at least the follo.pdfADITIEYEWEAR
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"Gouda Mando
 
MyTunesbuild.xml Builds, tests, and runs the project M.docx
MyTunesbuild.xml      Builds, tests, and runs the project M.docxMyTunesbuild.xml      Builds, tests, and runs the project M.docx
MyTunesbuild.xml Builds, tests, and runs the project M.docxgilpinleeanna
 
JavaBasicsCore1.ppt
JavaBasicsCore1.pptJavaBasicsCore1.ppt
JavaBasicsCore1.pptbuvanabala
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ Dev Chauhan
 

Similar to Programming homework (20)

Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
Term 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdfTerm 2 CS Practical File 2021-22.pdf
Term 2 CS Practical File 2021-22.pdf
 
10slide.ppt
10slide.ppt10slide.ppt
10slide.ppt
 
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docxQuestion- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
Question- Write the Java code below in IDE ECLIPSE enviroment and prov.docx
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
Pf cs102 programming-10 [structs]
Pf cs102 programming-10 [structs]Pf cs102 programming-10 [structs]
Pf cs102 programming-10 [structs]
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
Python-oop
Python-oopPython-oop
Python-oop
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
 
Implementation Your program shall contain at least the follo.pdf
Implementation Your program shall contain at least the follo.pdfImplementation Your program shall contain at least the follo.pdf
Implementation Your program shall contain at least the follo.pdf
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"Java™ (OOP) - Chapter 10: "Thinking in Objects"
Java™ (OOP) - Chapter 10: "Thinking in Objects"
 
MyTunesbuild.xml Builds, tests, and runs the project M.docx
MyTunesbuild.xml      Builds, tests, and runs the project M.docxMyTunesbuild.xml      Builds, tests, and runs the project M.docx
MyTunesbuild.xml Builds, tests, and runs the project M.docx
 
JavaBasicsCore1.ppt
JavaBasicsCore1.pptJavaBasicsCore1.ppt
JavaBasicsCore1.ppt
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
 
Structures_Final_KLE (2).pptx
Structures_Final_KLE (2).pptxStructures_Final_KLE (2).pptx
Structures_Final_KLE (2).pptx
 

Programming homework

  • 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