The goal of this lab is to continue your introduction to basic concepts in the C++ programming language. Concepts you will be familiar with after this lab include:
For this assignment, you will be working with a partner. In future assignments, you will be able to change your partner, if desired. If you did not pick a partner for this lab, we have assigned partners for you. Both partners should be present and working on the code together. You will both be responsible for understanding all concepts, so dividing and conquering is not an option. The academic integrity policy applies to the partnership; you cannot work or share code with anyone outside your partner.
You and your lab partner will share the same git repository, which is named lab02-<user1>-<user2>.git
.
Please access your lab by cloning the appropriate git repository, e.g.:
$ cd ~/cs35 $ git clone git@github.swarthmore.edu:CS35-F17/lab02-mgagne1-adanner1.git ./lab02You can also get the ssh git url from CS35 github org.
We've given you a skeleton version of the program.
In this lab, you will create several classes representing different
types of media, including text, pictures, and videos. All of these
classes will be subclasses of an abstract Media
class.
This Media
class will encapsulate all functionality common to
all types of media. Your subclasses will add additional unique data
as well as implement inherited methods in a way specific to that
media. For example, "opening" a text file should be different from
"opening" a picture or video.
In addition, you will create a MediaLibrary
class which
acts as a container for up to 50 Media
objects (think of how
iTunes stores all of your eBooks, music, movies, etc.). You will
also build capability in the MediaLibrary
class for
obtaining information about your different media objects and for
playing the media itself.
Below is an overview of the files required for submitting this
week's lab. Those highlighted in blue
will require
implementation on your part. Those
in black
are complete and should
not be modified except for comments.
Makefile
- contains scripts for
compiling. You should not change this file but are responsible
for understanding its contents.example1.library
- small test file of
media items.example2.library
- input file for loading
all media objects. You do not need to modify this except to add
more examples (optional).media.h
- declares the Media
class, an abstract parent class of all media types.text.h/.cpp
- declares and defines
the Text
class, a subclass of Media
. Some
of this implementation has been provided for you.image.h/.cpp
- declares and defines
the Image
class, a subclass of Media
.video.h/.cpp
- declares and defines
the Video
class, a subclass of Media
.mediaLibrary.h
and mediaLibrary.cpp
- declares and defines
the MediaLibrary
class. This class acts as the
overall container for all Media
items.main.cpp
- This is the main function for your
program.manualTests.cpp
- This has another main
function that you can use to experiment with your
program. Graders will look at this file to see how you
tested your program.README.md
- complete this when your lab is
finished and you are ready to make your final git push to hand
in the assignment.
Media
class
contains virtual methods which are common to all media
objects. See the method comments on the declarations fo those classes
for more information about the behavior you need to implement.
Media
objects in a library. It allows a user
to ask how many Media
objects are in the library and gives
them access to them on request. Its constructor takes in a single
string which represents the name of the file containing the media
library. In the MediaLibrary
constructor, you should open
this file and create Media
objects accordingly.
$ ./iswatmedia Welcome to the iSwat Media Library! What is the name of your media file? example1.library 1. [image] Brown-Flames 2. [image] Aliens 3. [text] Gettysburg-Address 0. (quit) What would you like to open? 0 Goodbye!The first line of the media library file should indicate the number of media objects it contains. Each item is represented by several lines depending on what kind of media it is:
text
. The
following line will contain the name of the text file
e.g. (e.g. /usr/local/doc/GettsburgAddress
); the next
line will contain the document's title
(e.g. Gettysburg-Address
).
image
. The
following line will contain the name of the image file
(e.g. /usr/swat/pics/brownflames.gif
); the next line will
contain the image's title (e.g. Brown-Flames
).
video
. The
following line will be the URL for the video
(e.g. https://vimeo.com/28241047
). The line after that
will be the title of the video (e.g. Running-Gerbil
)
followed by a line containing the video length as a string
(e.g. (0:29)
)
For example, we have posted an example media library file.
As mentioned above, your main
function should ask the
user for the name of a media library file. Using that file,
it should display a menu listing the media files in order and
allow the user to pick a media file to open. Media files should be
listed by positive integers. The first media file
you show should be selected by the input 1. After
opening that media file, the menu should be repeated again. The
program should continue until the user types 0, after
which the program should terminate.
To display the media in a menu, you need to have a way of
representing it. The getDescription
method
is virtual
and unimplemented; each Media
subclass implements it in a different way.
getDescription
method on Text
should give the string "[text] "
followed by the name
of the document (e.g. "[text] Gettysburg-Address"
).getDescription
method on Image
should do likewise but with the prefix "[image]"
(e.g. "[image] Brown-Flames"
).getDescription
method on Video
uses the prefix "[video]"
and suffixes the video
length in parentheses (e.g.
"[video] Running-Gerbil (0:29)"
).The act of opening a media file is also performed by the
particular Media
subclass. The open
method of each Media
object should behave as
follows:
open
method on Text
should open the file, read it line by line, and
print each line it reads.open
method on Image
should open the image viewer gpicview
to
display the image to the user. You can accomplish this by using the
system
function discussed below.open
method on Video
should open the URL of the video using
firefox
. You should use system
for this as well.system
FunctionThe library cstdlib
contains a function system
which can run commands for
you. You pass a C-style string to the system
function and it will run it in
much the same way as the shell we use to e.g. compile our programs. For
instance, the following program will open Firefox to the Google home page.
After it does that, it will open a text editor.
#include <cstdlib> #include <string> using namespace std; int main() { string cmd1 = "firefox http://www.google.com"; string cmd2 = "gedit"; system(cmd1.c_str()); system(cmd2.c_str()); return 0; }
In larger applications, we avoid using the system
function in favor of more
precise ways to launch other programs from within our own code. For this lab,
however, the system
function suits us quite well.
Text
class – be able to view a text file.
Image
and Video
classes – be able to
open an image or play a video.
MediaLibrary
class which holds up to 50 media objects and lets the user
access the objects.
MediaLibrary
set up, complete the program. When
completed, your program should ask the user for a media library,
present a menu of media objects, and allow the user to select and
open the media.
Your code in this assignment is broken in to several different
files. To aid in the compilation process, we've created
a Makefile
which should make compilation easy. To compile
your test program, just type:
$ make manualTestsCompiling your main program is even easier. Just enter:
$ make
To summarize the requirements of this lab:
MediaLibrary
object.
manualTests.cpp
Once you are satisfied with your code, hand it in using git. Remember the add, commit, push development cycle. You can push as many times as you like, but only the most recent submission will be graded. You may want to run git status to confirm all modifications have been pushed.