C++ CD/DVD Collection This program will allow the user to keep track of a CD or
ID: 671953 • Letter: C
Question
C++
CD/DVD Collection
This program will allow the user to keep track of a CD or DVD collection. This can only work exclusively with either CDs or DVDs since some of the data is different—your choice. Each CD/DVD in the collection will be represented as a class, so you will have one class that is a single CD/DVD.
The CD class will use a vector to keep track of the titles of the songs on the CD; this will allow each CD to have a different number of songs. It should also maintain the length of each song thus another vector. The class will also keep track of the total length of the CD. The class will also have a data member for the artist name and the name of the CD.
The DVD class will have data members for the title of the movie, the length of the movie, and the year the movie was released. The class will have a vector which is used to store the name of the actors and actresses in the movie. Another vector will be used to maintain the character names that the actor/actress played in the movie. These two vectors must work in parallel, meaning the first actor/actress in the list must correspond to the first character in the other vector.
The program will maintain a list of CD/DVDs. This list will be a vector of that class type (CD or DVD). The program must provide methods (functions) to add a CD/DVD, remove a CD/DVD and update a CD/DVD. There should also be a function that displays the entire list of CDs/DVDs. The output must be a table format, with heading.
For the DVDs:
Movie Title Length of Movie Year Released Actors/Actresses Characters
NOTE: the movie title, length of movie and year released should only appear once while the actors/actresses and characters will have several lines. So the other columns must be displayed with blanks.
For the CDs:
Artist CD Name Length of CD Song Title Song Length
NOTE: the artist name, CD name and length of CD should only appear once while the song title and length will have several lines. So the other columns must be displayed with blanks.
Explanation / Answer
my header file
My file for the header
My other Header file
Code:
. End of Code .
Also have same type of project if you like see bellow code
here is main()
item = library->addMusicCD("Sergeant Pepper's Lonely Hearts Club Band", "Beatles", 10);
if (item != NULL) {
library->addKeywordForItem(item, "acid rock");
library->addKeywordForItem(item, "sixties");
library->addBandMember(item, "John Lennon");
library->addBandMember(item, "George Harrison");
library->addBandMember(item, "Ringo Starr");
library->printItem(cout, item);
}
here is the libray.h file where i am adding the info
#include "Library.h"
#include "book.h"
#include "cd.h"
#include "dvd.h"
#include <iostream>
// general functions
ItemSet allBooks;
ItemSet allCDS;
ItemSet allDVDs;
ItemSet* temp;
ItemSetMap allBooksByAuthor;
ItemSetMap allmoviesByDirector;
ItemSetMap allmoviesByActor;
ItemSetMap allMusicByBand;
ItemSetMap allMusicByMusician;
const Item* Library::addMusicCD(const string& title, const string& band, const int nSongs)
{
ItemSet* obj = new ItemSet();
CD* item = new CD(title,band,nSongs);
allCDS.insert(item);
obj->insert(item);
//allMusicByBand[band] = obj;
ItemSetMap::iterator myband = allMusicByBand.find(band);
if(myband != allMusicByBand.end())
{
myband->second->insert(item);
}
else{
allMusicByBand.insert(make_pair(band, obj));
}
return item;
}
void Library::addBandMember(const Item* musicCD, const string& member)
{
ItemSet* obj = new ItemSet();
(((CD*) musicCD)->addBandMember(member));
obj->insert((CD*) musicCD);
ItemSetMap::iterator MByMusician = allMusicByMusician.find(member);
if(MByMusician != allMusicByMusician.end())
{
MByMusician->second->insert((CD*) musicCD);
}
else
{
allMusicByMusician.insert(make_pair(member, obj));
}
}
and here is the cd.cpp class
#include "CD.h"
using namespace std;
CD::CD(const string& theTitle, const string& theBand, const int snumber)
: Item(theTitle), band(theBand),number(snumber)
{
}
CD::~CD()
{
}
const string CD::getBand() const
{
return band;
}
const string CD::getMusician() const
{
return musicians;
}
const int CD::getNumber() const
{
return number;
}
void CD::addBandMember(const string &member)
{
this->musicians = member;
}
void CD::print(ostream &out) const
{
out << "-MusicCD-" << endl;
out << "band: " << this->getBand() << endl;
out << "musicians: " << this->getMusician() << endl;
out << "songs: " << this->getNumber() << endl;
out << "title: " << this->getTitle() << endl;
out << "keywords: " << this->printKeywords(this->getKeywords()) << endl;
out << endl;
}
ostream& operator<<(ostream& out, const CD* cd)
{
cd->print(out);
return out;
}
finally, here is the cd.h
#ifndef CD_H
#define CD_H
#pragma once
#include "item.h"
class CD : public Item
{
public:
CD(const string& theTitle, const string& theBand, const int snumber);
void addBandMember(const string& member);
const int getNumber() const;
const string getMusician() const;
const string getBand() const;
virtual void print(ostream& out) const;
~CD();
private:
string band;
string musicians;
string title;
int number;
};
ostream& operator<<(ostream& out, const CD* cd);
#endif
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.