Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a C++ question. This has been asked many times on here but every program

ID: 3773311 • Letter: T

Question

This is a C++ question. This has been asked many times on here but every program does not work. Can someone please help with a working program?

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

DVD.h

#pragma once
#include<iostream>
#include<string>
#include<vector>
using namespace std;

class DVD
{
public:
   DVD(string mtitle,string year,int length);
   ~DVD();
   void addActor(string actor, string character);
   int getDuration();
   string getYear();
   string getTitle();
   vector<string> getActor();
   vector<string> getCharacter();
private:
   vector<string> actors;
   vector<string> characters;
   string title;
   string releaseYear;
   int duration; // duration of movie in minutes

};

DVD.cpp

#include "DVD.h"


DVD::DVD(string mtitle,string year,int length)
{
   title = mtitle;
   releaseYear = year;
   duration = length;
}


DVD::~DVD()
{
}

void DVD::addActor(string actor, string character)
{
   actors.push_back(actor);
   characters.push_back(character);
}

int DVD::getDuration()
{
   return duration;
}

string DVD::getYear()
{
   return releaseYear;
}
string DVD::getTitle()
{
   return title;
}

vector<string> DVD::getActor()
{
   return actors;
}

vector<string> DVD::getCharacter()
{
   return characters;
}

DVDStore.cpp (This is the which will have all the functionality)

#include<iostream>
#include <iomanip>
#include "DVD.h"
using namespace std;

void addDVD(vector<DVD>& collection, DVD dvd)
{
   collection.push_back(dvd);
}


//This function will remove the last DVD in the collection vector
void removeLastDVD(vector<DVD>& collection)
{
   collection.pop_back();
}

//Function will add a actor to movie whose title is specified
void updateDVDActor(vector<DVD>& collection,string title,string actor, string character)
{
   for (std::vector<DVD>::iterator it = collection.begin(); it != collection.end(); ++it)
   {
       if (it->getTitle() == title)
       {
           it->addActor(actor, character);
       }
   }
}

void display(vector<DVD>& collection)
{
  
   for (std::vector<DVD>::iterator it = collection.begin(); it != collection.end(); ++it)
   {
       cout << setw(15) << "Movie title " << setw(15) << "Length of movie" << setw(15) << "Year released"
           << setw(20) << "Actor/Actress" << setw(12) << "Character";
       vector<string> actor = it->getActor();
       vector<string> character = it->getCharacter();
       cout << setw(15) << it->getTitle() << setw(15) << it->getDuration() << setw(10) << it->getYear() <<setw(actor[0].length()+10)<<actor[0]<<setw(10)<<character[0];
       for (int i = 1; i < actor.size(); i++)
       {
           cout << setw(63) << actor[i] << setw(15) << character[i] << endl;
       }
       cout << endl;
   }
}


int main()
{
   vector<DVD> collection;

   DVD inception("Inception", "2012", 120);
   inception.addActor("LeonardoDi Caprio", "Cobb");
   inception.addActor("Ellen Page", "Ariadne");
   inception.addActor("Tom Hardy", "Eames");
   addDVD(collection, inception);
   DVD darkknight("Dark Knight", "2012", 125);
   darkknight.addActor("Christian Bale", "Bruce Wayne");
   darkknight.addActor("Michael Cane", "Alfred");
   addDVD(collection,darkknight);
   display(collection);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote