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

Greetings, The following is a course proiect that is to be completed in the C++

ID: 3674603 • Letter: G

Question

Greetings, The following is a course proiect that is to be completed in the C++ programming Tanguage. I ask that you please include good code commenting. Pleascmment in such a way that it allows someone who knows nothing about coding to understand what is going on in your progr amming. Please, if your answer involves a header file and implementation file, that you designate which portion of your code belongs to the .h and.cpp files so that I can apportion it proper ly within the Microsoft vs Express files and get the code to compile correctly Thank you for your help and your best effort as this is a large chunk of points r help and your best effort as this 1s a arge chunk

Explanation / Answer

main.cpp

#include <iostream>
#include "CD.h"
#include "DVD.h"

/*************************
menu function prototypes
*************************/
int menu();
void addCD(Linked_List<CD> *);
void addDVD(Linked_List<DVD> *);
void removeCD(Linked_List<CD> *);
void removeDVD(Linked_List<DVD> *);
void updateCD(Linked_List<CD> *);
void updateDVD(Linked_List<DVD> *);
void displayCDs(Linked_List<CD> *);
void displayDVDs(Linked_List<DVD> *);


int main()
{
   Linked_List<CD> CD_List;
   Linked_List<CD> *CD_List_Ptr;
   CD_List_Ptr = &CD_List;

   Linked_List<DVD> DVD_List;
   Linked_List<DVD> *DVD_List_Ptr;
   DVD_List_Ptr = &DVD_List;


   int menuChoice;
   do
   {
       menuChoice = menu();

       switch (menuChoice)
       {
       case 1:
           addCD(CD_List_Ptr);
           break;
       case 2:
           addDVD(DVD_List_Ptr);
           break;
       case 3:
           removeCD(CD_List_Ptr);
           break;
       case 4:
           removeDVD(DVD_List_Ptr);
           break;
       case 5:
           updateCD(CD_List_Ptr);
           break;
       case 6:
           updateDVD(DVD_List_Ptr);
           break;
       case 7:
           displayCDs(CD_List_Ptr);
           break;
       case 8:
           displayDVDs(DVD_List_Ptr);
           break;
       }
   } while (menuChoice != 9);

   // end of program
   cout << endl;
   system("pause");
   return 0;
}

int menu()
{
   int choice;
   cout << endl;
   cout << "Menu" << endl
       << "1. Add CD" << endl
       << "2. Add DVD" << endl
       << "3. Remove CD" << endl
       << "4. Remove DVD" << endl
       << "5. Update CD" << endl
       << "6. Update DVD" << endl
       << "7. Display CDs" << endl
       << "8. Display DVDs" << endl
       << "9. Quit" << endl;
   cout << "Enter your choice (1-9): ";
   cin >> choice;

   while (choice < 1 || choice > 9)
   {
       cout << "Invalid choice. Reenter (1-9): ";
       cin >> choice;
   }

   return choice;
}

void addCD(Linked_List<CD> *cdList)
{
   CD myCD;
   string str;
   cin.ignore();

   cout << endl << "Enter CD Artist Name: ";
   getline(cin, str);
   myCD.setArtist(str);

   cout << "Enter CD Length: ";
   cin >> str;
   myCD.setLength(str);

   cin.ignore();
   cout << "Enter CD Album Title: ";
   getline(cin, str);
   myCD.setTitle(str);

   cin.clear();
   char more = 'Y';
   int acc = 0;

   while (toupper(more) == 'Y')
   {
       acc++;
       cin.ignore();
       cout << "Enter Track " << acc << " Title: ";
       getline(cin, str);
       myCD.setSongInstanceTitle(str);

       cout << "Enter Track " << acc << " Length: ";
       getline(cin, str);
       myCD.setSongInstanceLength(str);
       myCD.setSongList();

       cout << "Is there another track? (Y/N): ";
       cin >> more;
   }

   cdList->appendNode(myCD);
}
void addDVD(Linked_List<DVD> *dvdList)
{
   DVD myDVD;
   string str;
   cin.ignore();

   cout << endl << "Enter DVD Title: ";
   getline(cin, str);
   myDVD.setTitle(str);

   cout << "Enter Length of Movie: ";
   getline(cin, str);
   myDVD.setLength(str);

   cout << "Enter Year Released: ";
   getline(cin, str);
   myDVD.setYearReleased(str);

   char more = 'Y';
   int acc = 0;

   while (toupper(more) == 'Y')
   {
       acc++;
       cin.ignore();
       cout << "Enter Actor/Actress " << acc << " Name: ";
       getline(cin, str);
       myDVD.setActorInstance(str);

       cout << "Enter Character " << acc << " Name: ";
       getline(cin, str);
       myDVD.setCharacterInstance(str);
       myDVD.setActorList();

       cout << "Is there another actor/actress/character? (Y/N): ";
       cin >> more;
   }

   dvdList->appendNode(myDVD);
}
void removeCD(Linked_List<CD> *cdList)
{
   CD myCD;
   string str;

   cdList->displayList();

   cin.ignore();
   cout << endl << "What CD would you like to remove? ";
   getline(cin, str);
   cout << endl;

   myCD.setTitle(str);

   if (cdList->searchList(myCD) == -1)
       cout << "That CD does not exist in your collection." << endl;
   else
       cdList->deleteNode(myCD);
}
void removeDVD(Linked_List<DVD> *dvdList)
{
   DVD myDVD;
   string str;

   dvdList->displayList();

   cin.ignore();
   cout << endl << "What DVD would you like to remove? ";
   getline(cin, str);
   cout << endl;

   myDVD.setTitle(str);

   if (dvdList->searchList(myDVD) == -1)
       cout << "That DVD does not exist in your collection." << endl;
   else
       dvdList->deleteNode(myDVD);
}
void updateCD(Linked_List<CD> *cdList)
{
   CD oldCD;
   CD newCD;
   string str;

   cdList->displayList();
   cin.ignore();
   cout << endl << "What CD would you like to update? ";
   getline(cin, str);
   cout << endl;

   oldCD.setTitle(str);

   int choice;
   char more = 'Y';
   int acc = 0;

   if (cdList->searchList(oldCD) == -1)
       cout << "That CD does not exist in your collection." << endl;
   else
   {
       oldCD = cdList->returnItem(oldCD);

       newCD.setArtist(oldCD.getArtist());
       newCD.setTitle(oldCD.getTitle());
       newCD.setLength(oldCD.getLength());
       cdList->deleteNode(oldCD);

       cout << "What would you like to update? " << endl
           << "1. Artist" << endl
           << "2. Album" << endl
           << "3. Length" << endl
           << "4. Song List" << endl
           << "Enter 1 - 4: ";
       cin >> choice;

       if (choice == 1)
       {
           cin.ignore();
           cout << "Enter the new Artist: ";
           getline(cin, str);
           newCD.setArtist(str);
       }
       else if (choice == 2)
       {
           cin.ignore();
           cout << "Enter the new Album: ";
           getline(cin, str);
           newCD.setTitle(str);
       }
       else if (choice == 3)
       {
           cin.ignore();
           cout << "Enter the new Length: ";
           getline(cin, str);
           newCD.setLength(str);
       }
       else if (choice == 4)
       {
           cin.ignore();
           while (toupper(more) == 'Y')
           {
               acc++;
               cin.ignore();
               cout << "Enter Track " << acc << " Title: ";
               getline(cin, str);
               newCD.setSongInstanceTitle(str);

               cout << "Enter Track " << acc << " Lenth: ";
               getline(cin, str);
               newCD.setSongInstanceLength(str);
               newCD.setSongList();

               cout << "Is there another track? (Y/N): ";
               cin >> more;
           }
       }
       cdList->appendNode(newCD);
   }
}
void updateDVD(Linked_List<DVD> *dvdList)
{
   DVD oldDVD;
   DVD newDVD;
   string str;

   dvdList->displayList();
   cin.ignore();
   cout << endl << "What DVD would you like to update? ";
   getline(cin, str);
   cout << endl;

   oldDVD.setTitle(str);

   int choice;
   char more = 'Y';
   int acc = 0;

   if (dvdList->searchList(oldDVD) == -1)
       cout << "That DVD does not exist in your collection." << endl;
   else
   {
       oldDVD = dvdList->returnItem(oldDVD);

       newDVD.setTitle(oldDVD.getTitle());
       newDVD.setYearReleased(oldDVD.getYearReleased());
       newDVD.setLength(oldDVD.getLength());
       dvdList->deleteNode(oldDVD);

       cout << "What would you like to update? " << endl
           << "1. Title" << endl
           << "2. Length of Movie" << endl
           << "3. Year Released" << endl
           << "4. Actors/Actresses/Characters List" << endl
           << "Enter 1 - 4: ";
       cin >> choice;

       if (choice == 1)
       {
           cin.ignore();
           cout << "Enter the new Title: ";
           getline(cin, str);
           newDVD.setTitle(str);
       }
       else if (choice == 2)
       {
           cin.ignore();
           cout << "Enter the new Length: ";
           cin >> str;
           newDVD.setLength(str);
       }
       else if (choice == 3)
       {
           cin.ignore();
           cout << "Enter the new Year Released: ";
           cin >> str;
           newDVD.setYearReleased(str);
       }
       else if (choice == 4)
       {
           cin.ignore();
           while (toupper(more) == 'Y')
           {
               acc++;
               cin.ignore();
               cout << "Enter Actor/Actress " << acc << " Name: ";
               getline(cin, str);
               newDVD.setActorInstance(str);

               cout << "Enter Character " << acc << " Name: ";
               getline(cin, str);
               newDVD.setCharacterInstance(str);
               newDVD.setActorList();

               cout << "Is there another Actor/Actress? (Y/N): ";
               cin >> more;
           }
       }
       dvdList->appendNode(newDVD);
   }
}
void displayCDs(Linked_List<CD> *cdList)
{
   cout << endl
       << left << setw(16) << "Artist"
       << left << setw(16) << "CD Name"
       << left << setw(16) << "Length of CD"
       << left << setw(16) << "Song Title"
       << left << setw(16) << "Song Length"
       << left << setw(16) << "______"
       << left << setw(16) << "_______"
       << left << setw(16) << "____________"
       << left << setw(16) << "__________"
       << left << setw(16) << "___________";
   cdList->displayList();
}
void displayDVDs(Linked_List<DVD> *dvdList)
{
   cout << endl
       << left << setw(16) << "Movie Title"
       << left << setw(16) << "Length of Movie"
       << left << setw(16) << "Year Released"
       << left << setw(16) << "Actor/Actress"
       << left << setw(16) << "Characters"
       << left << setw(16) << "___________"
       << left << setw(16) << "_______________"
       << left << setw(16) << "_____________"
       << left << setw(16) << "_____________"
       << left << setw(16) << "__________";
   dvdList->displayList();
}

CD.h

#ifndef CD_H
#define CD_H

#include "Media.h"

#include <string>
#include <iomanip>
using namespace std;

class CD;

struct SongInfo
{
   string songTitle;
   string songLength;
};

ostream &operator << (ostream&, const CD&);
ostream &operator << (ostream&, const SongInfo&);
ostream &operator << (ostream&, const Linked_List<CD>&);
ostream &operator << (ostream&, const Linked_List<SongInfo>&);

class CD : public Media
{
private:

   SongInfo songInstance;
   Linked_List<SongInfo> songList;

   string artist;

   SongInfo getSongInstance() const;
   Linked_List<SongInfo> getSongList() const;

public:

   CD();
  
   void setArtist(string);
   void setSongInstanceTitle(string);
   void setSongInstanceLength(string);
   void setSongList();

   string getArtist() const;

   friend ostream &operator << (ostream&, const CD&);
   friend ostream &operator << (ostream&, const SongInfo&);
   friend ostream &operator << (ostream&, const Linked_List<CD>&);
   friend ostream &operator << (ostream&, const Linked_List<SongInfo>&);

   bool operator=(string str)
       { return this->getTitle() == str; }

   bool operator==(string str)
       { return this->getTitle() == str; }

   bool operator==(const CD &cd)
       { return this->getTitle() == cd.getTitle(); }

   bool operator!=(const CD &cd)
       { return this->getTitle() == cd.getTitle();}
};
#endif

CD.cpp

#include "CD.h"

CD::CD()
{
   artist = "(none)";
   songInstance.songTitle = "(none)";
   songInstance.songLength = "(none)";
}

void CD::setArtist(string a)
   { artist = a; }

void CD::setSongInstanceTitle(string t)
   { songInstance.songTitle = t; }

void CD::setSongInstanceLength(string len)
   { songInstance.songLength = len; }

void CD::setSongList()
   { songList.appendNode(songInstance); }

string CD::getArtist() const
   { return artist; }

SongInfo CD::getSongInstance() const
   { return songInstance; }

Linked_List<SongInfo> CD::getSongList() const
   { return songList; }

ostream &operator << (ostream& strm, const SongInfo &obj)
{
   strm << left << setw(16) << obj.songTitle
       << left << setw(64) << obj.songLength;

   return strm;
}

ostream &operator << (ostream &strm, const CD &obj)
{
   strm << endl
       << left << setw(16) << obj.getArtist()
       << left << setw(16) << obj.getTitle()
       << left << setw(16) << obj.getLength()
       << left << setw(0) << obj.getSongList();

   return strm;
}

ostream &operator << (ostream& strm, const Linked_List<SongInfo> &obj)
{
   obj.displayList();
   return strm;
}

ostream &operator << (ostream& strm, const Linked_List<CD> &obj)
{
   obj.displayList();
   return strm;
}

DVD.cpp

#include "DVD.h"

DVD::DVD()
{
   yearReleased = ("none");
   actorInstance.actor = "(none)";
   actorInstance.character = "(none)";
}
void DVD::setYearReleased(string y)
   { yearReleased = y; }

void DVD::setActorInstance(string a)
   { actorInstance.actor = a; }

void DVD::setCharacterInstance(string c)
   { actorInstance.character = c; }

void DVD::setActorList()
   { actorsList.appendNode(actorInstance); }
string DVD::getYearReleased() const
   { return yearReleased; }

DVDActors DVD::getActorsInstance() const
   { return actorInstance; }

Linked_List<DVDActors> DVD::getActorsList() const
   { return actorsList; }
ostream &operator << (ostream& strm, const DVDActors &obj)
{
   strm << left << setw(16) << obj.actor
       << left << setw(64) << obj.character;

   return strm;
}
ostream &operator << (ostream &strm, const DVD &obj)
{
   strm << endl
       << left << setw(16) << obj.getTitle()
       << left << setw(16) << obj.getLength()
       << left << setw(16) << obj.getYearReleased()
       << left << setw(0) << obj.getActorsList();

   return strm;
}
ostream &operator << (ostream& strm, const Linked_List<DVDActors> &obj)
{
   obj.displayList();
   return strm;
}
ostream &operator << (ostream& strm, const Linked_List<DVD> &obj)
{
   obj.displayList();
   return strm;
}
DVD.h

#ifndef DVD_H
#define DVD_H

#include "Media.h"

#include <iomanip>
#include <string>
using namespace std;

class DVD;

struct DVDActors
{
   string actor;
   string character;
};

ostream &operator << (ostream&, const DVD&);
ostream &operator << (ostream&, const DVDActors&);
ostream &operator << (ostream&, const Linked_List<DVD>&);
ostream &operator << (ostream&, const Linked_List<DVDActors>&);

class DVD : public Media
{
private:

   DVDActors actorInstance;
   Linked_List<DVDActors> actorsList;

   string yearReleased;

   DVDActors getActorsInstance() const;
   Linked_List<DVDActors> getActorsList() const;

public:

   DVD();

   void setYearReleased(string);
   void setActorInstance(string);
   void setCharacterInstance(string);
   void setActorList();

   string getYearReleased() const;

   friend ostream &operator << (ostream &, const DVD &);
   friend ostream &operator << (ostream&, const DVDActors &);
   friend ostream &operator << (ostream&, const Linked_List<DVD>&);
   friend ostream &operator << (ostream&, const Linked_List<DVDActors>&);

   bool operator=(string str)
       { return this->getTitle() == str; }

   bool operator==(string str)
       { return this->getTitle() == str; }

   bool operator==(const DVD &dvd)
   {   return this->getTitle() == dvd.getTitle(); }

   bool operator!=(const DVD &dvd)
           { return this->getTitle() == dvd.getTitle(); }
};
#endif
Linked_List.h

#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include <iostream>
using namespace std;

template <class T>
class Linked_List
{
private:

   struct ListNode
   {
       T value;
       struct ListNode *next;
   };

   ListNode *head;

public:
   Linked_List();
   ~Linked_List();

   void appendNode(T);
   void insertNode(T);
   void deleteNode(T);
   void displayList() const;

   int searchList(T) const;
   T returnItem(T);
};

/********* constructor ***********/
template <class T>
Linked_List<T>::Linked_List()
{
   head = nullptr;
}

/********* destructor ***********/
template <class T>
Linked_List<T>::~Linked_List()
{
   ListNode *nodePtr;
   ListNode *nextNode;
   nodePtr = head;

   while (nodePtr != nullptr)
   {
       nextNode = nodePtr->next;
       // delete nodePtr;
       nodePtr = nextNode;
   }
}

/********* append ***********/
template <class T>
void Linked_List<T>::appendNode(T num)
{
   ListNode *newNode;
   ListNode *nodePtr;

   newNode = new ListNode;
   newNode->value = num;
   newNode->next = nullptr;

   if (!head)
       head = newNode;
   else
   {
       nodePtr = head;

       while (nodePtr->next)
           nodePtr = nodePtr->next;

       nodePtr->next = newNode;
   }
}

/********* insert ***********/
template <class T>
void Linked_List<T>::insertNode(T num)
{
   ListNode *newNode;
   ListNode *nodePtr;
   ListNode *previousNode = nullptr;

   newNode = new ListNode;
   newNode->value = num;

   if (!head)
   {
       head = newNode;
       newNode->next = nullptr;
   }
   else
   {
       nodePtr = head;
       previousNode = nullptr;

       while (nodePtr != nullptr && nodePtr->value < num)
       {
           previousNode = nodePtr;
           nodePtr = nodePtr->next;
       }

       if (previousNode == nullptr)
       {
           head = newNode;
           newNode->next = nodePtr;
       }
       else
       {
           previousNode->next = newNode;
           newNode->next = nodePtr;
       }
   }
}

/********* delete ***********/
template <class T>
void Linked_List<T>::deleteNode(T num)
{
   ListNode *nodePtr;
   ListNode *previousNode = nullptr;

   if (!head)
       return;

   if (head->value == num)
   {
       nodePtr = head->next;
       delete head;
       head = nodePtr;
   }
   else
   {
       nodePtr = head;

       while (nodePtr != nullptr && nodePtr->value != num)
       {
           previousNode = nodePtr;
           nodePtr = nodePtr->next;
       }

       if (nodePtr)
       {
           previousNode->next = nodePtr->next;
           delete nodePtr;
       }
   }
}

/********* display ***********/
template <class T>
void Linked_List<T>::displayList() const
{
   ListNode *nodePtr;
   nodePtr = head;

   while (nodePtr)
   {
       cout << nodePtr->value;
       nodePtr = nodePtr->next;
   }
}

/********* search ***********/
template <class T>
int Linked_List<T>::searchList(T item) const
{

   int index = 0;

   ListNode *nodePtr;
   nodePtr = head;

   while (nodePtr)
   {
       if (nodePtr->value == item)
           return index;
       else
       {
           nodePtr = nodePtr->next;
           index++;
       }
   }
   index = -1;
   return index;
}

template <class T>
T Linked_List<T>::returnItem(T item)
{
   ListNode *nodePtr;
   nodePtr = head;

   while (nodePtr)
   {
       if (nodePtr->value == item)
           return nodePtr->value;
       else
       {
           nodePtr = nodePtr->next;
       }
   }
   return item;
}
#endif


Media.cpp
#include "Media.h"

Media::Media()
{
   title = "(none)";
   length = "(none)";
}

void Media::setTitle(string t)
{
   title = t;
}

void Media::setLength(string len)
{
   length = len;
}

string Media::getTitle() const
{
   return title;
}

string Media::getLength() const
{
   return length;
}


Media.h

#ifndef MEDIA_H
#define MEDIA_H

#include "Linked_List.h"

#include <string>
using namespace std;

class Media
{
private:
   string title;
   string length;

public:
   Media();

   void setTitle(string);
   void setLength(string);

   string getTitle() const;
   string getLength() const;
};
#endif

output

1. Add CD                                                                                                                                                   
2. Add DVD                                                                                                                                                  
3. Remove CD                                                                                                                                                
4. Remove DVD                                                                                                                                               
5. Update CD                                                                                                                                                
6. Update DVD                                                                                                                                               
7. Display CDs                                                                                                                                              
8. Display DVDs                                                                                                                                             
9. Quit                                                                                                                                                     
Enter your choice (1-9): 1                                                                                                                                  
                                                                                                                                                            
Enter CD Artist Name: Hari                                                                                                                                  
Enter CD Length: 25                                                                                                                                         
Enter CD Album Title: melody                                                                                                                                
Enter Track 1 Title: movie                                                                                                                                  
Enter Track 1 Lenth: drama                                                                                                                                  
Is there another track? (Y/N): N