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

This is C++ question, Please I need working program only, with the output. CD/DV

ID: 3581646 • Letter: T

Question

This is C++ question, Please I need working program only, with the output.

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

#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
//Class CD defined
class CD
{
//Data member
string songTitle[10], artistName, CDname;
int numberOfSongs, totalLength;
int lengthOfSong[20];
public:
//Accept the CD information
void accept()
{
int i;
//Total length is initialized to 0
totalLength = 0;
cout<<" Enter the CD Name: ";
cin>>CDname;
//Clears the buffer
fflush(stdin);
cout<<" Enter the Artist Name: ";
cin>>artistName;
fflush(stdin);
cout<<" Enter the Number of Songs: ";
cin>>numberOfSongs;
fflush(stdin);
//Accepts song title and length of each song
for(i = 0; i < numberOfSongs; i++)
{
cout<<" Enter the Song Title "<<i+1<<" ";
fflush(stdin);
cin>>songTitle[i];
cout<<" Enter the length of Song "<<i+1<<" ";
fflush(stdin);
cin>>lengthOfSong[i];
fflush(stdin);
//Calculates the total length
totalLength = totalLength + lengthOfSong[i];
}
}
//Displays the CD information
void display()
{
int j;
cout<<" CD";
cout<<" Artist: "<<CDname;
cout<<" CD Name: "<<artistName;
cout<<" Number of Songs: "<<numberOfSongs;
cout<<" Length of CD: "<<totalLength;
//Displays the song title and length of each song
for(j = 0; j < numberOfSongs; j++)
{
cout<<" Song Title: "<<j+1<<" "<<songTitle[j];
fflush(stdout);
cout<<" Song Length: "<<j+1<<" "<<lengthOfSong[j];
}
}
};
//DVD class defined
class DVD
{
//Data member
string movieTitle, nameActorsActresses[10], actor_actress[2];
int lengthOfMovie, movieReleasedYear, no;
public:
//Accept the DVD information
void accept()
{
cout<<" Enter the Movie Title: ";
cin>>movieTitle;
//Clears the buffer
fflush(stdin);
cout<<" Enter Length of Movie: ";
cin>>lengthOfMovie;
fflush(stdin);
cout<<" Enter Released Year: ";
cin>>movieReleasedYear;
fflush(stdin);
//Asks number of actor or actresses
cout<<" Number of actors/actress: ";
cin>>no;
fflush(stdin);
//Accepts each actor / actress name and gender
for(int i = 0; i < no; i++)
{
cout<<" Enter the Actor / Actress Name: "<<i+1<<" ";
cin>>nameActorsActresses[i];
fflush(stdin);
cout<<" Enter the M for Actor F for Actress: "<<i+1<<" ";
cin>>actor_actress[i];
fflush(stdin);
}
}
//Displays the DVD information
void display()
{
cout<<" DVD";
cout<<" Movie Title: "<<movieTitle;
cout<<" Length of Movie: "<<lengthOfMovie;
cout<<" Year Released: "<<movieReleasedYear;
//Displays each actor / actress name and gender
for(int i = 0; i < no; i++)
{
cout<<" Actors/Actresses: "<<i+1<<" "<<nameActorsActresses[i];
cout<<" Characters: "<<i+1<<" "<<actor_actress[i];
}
}
};
//Main menu for CD or DVD selection
void menu()
{
cout<<" Enter your choice: ";
cout<<" 1) CD ";
cout<<" 2) DVD ";
cout<<" 3) Exit ";
}
//Sub main menu for Add or Remove or Update or Display selection
void subMenu()
{
cout<<" 1) Add ";
cout<<" 2) Remove ";
cout<<" 3) Update ";
cout<<" 4) Display ";
}
//Main function
int main()
{
//Creates a vector for CD
vector<CD> myCD;
//Creates a vector for DVD
vector<DVD> myDVD;
//Creates object of CD
CD cd;
//Creates object of DVD
DVD dv;
int ch, sch, rec;
//Loops till user selects Exit
do
{
//Main menu display
menu();
//Accepts option for CD or DVD
cout<<" Enter your choice: ";
cin>>ch;
fflush(stdin);
//Outer switch for CD / DVD
switch(ch)
{
case 1:
//Sub menu displayed for add, remove, update or display
subMenu();
fflush(stdin);
//Accept choice for add, remove, update or display
cout<<" Enter your choice: ";
cin>>sch;
fflush(stdin);
//Inner switch for CD - add, remove, update or display
switch(sch)
{
//Add
case 1:
//Accept CD information
cd.accept();
//Adds record to vector CD
myCD.push_back(cd);
break;
//Remove
case 2:
//Accepts record number for delete
cout<<" Enter the record to delete: ";
cin>>rec;
//Removes record from the vector CD
myCD.erase(myCD.begin()+(rec-1));
break;
//Update
case 3:
//Accepts the record number for update
cout<<" Enter the record number to update: ";
cin>>rec;
//Accept data for update
cd.accept();
//Inserts the update record
myCD.insert (myCD.begin()+(rec-1), cd);
//Removes the old record
myCD.erase(myCD.begin()+(rec));

break;
//Display
case 4:
//Creates Iterator class object
vector<CD>::iterator it;
//Iterates till end of the vector CD
for (it = myCD.begin(); it < myCD.end(); it++)
it->display();
break;
}
break;
//DVD
case 2:
//Sub menu displayed for add, remove, update or display
subMenu();
fflush(stdin);
//Accept choice for add, remove, update or display
cout<<" Enter your choice: ";
cin>>sch;
fflush(stdin);
//Inner switch for DVD - add, remove, update or display
switch(sch)
{
//Add
case 1:
//Accept DVD information
dv.accept();
//Adds record to vector DVD
myDVD.push_back(dv);
break;
//Delete
case 2:
//Accepts record number for delete
cout<<" Enter the record to delete: ";
cin>>rec;
//Removes record from the vector DVD
myDVD.erase(myDVD.begin()+(rec-1));
break;
//Update
case 3:
//Accepts the record number for update
cout<<" Enter the record number to update: ";
cin>>rec;
//Accept data for update
dv.accept();
//Inserts the update record
myDVD.insert (myDVD.begin()+(rec-1), dv);
//Removes the old record
myDVD.erase(myDVD.begin()+rec);
break;
//Display
case 4:
//Creates Iterator class object
vector<DVD>::iterator it;
//Iterates till end of the vector DVD
for (it = myDVD.begin(); it < myDVD.end(); it++)
it->display();
break;
}
break;
case 3:
exit(0);
//Invalid choice
default:
cout<<" Invalid choice!";
}
}while(1);
}

Output:

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 1

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 1

Enter the CD Name: aa

Enter the Artist Name: ss

Enter the Number of Songs: 1

Enter the Song Title 1 as

Enter the length of Song 1 10

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 1

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 1

Enter the CD Name: qq

Enter the Artist Name: ww

Enter the Number of Songs: 2

Enter the Song Title 1 qw

Enter the length of Song 1 11

Enter the Song Title 2 wq

Enter the length of Song 2 22

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 1

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 1

Enter the CD Name: zz

Enter the Artist Name: xx

Enter the Number of Songs: 1

Enter the Song Title 1 xz

Enter the length of Song 1 33

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 1

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 4

                        CD

Artist: aa

CD Name: ss

Number of Songs: 1

Length of CD: 10

Song Title: 1 as

Song Length: 1 10

                        CD

Artist: qq

CD Name: ww

Number of Songs: 2

Length of CD: 33

Song Title: 1 qw

Song Length: 1 11

Song Title: 2 wq

Song Length: 2 22

                        CD

Artist: zz

CD Name: xx

Number of Songs: 1

Length of CD: 33

Song Title: 1 xz

Song Length: 1 33

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 1

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 3

Enter the record number to update: 2

Enter the CD Name: aaaaaaaa

Enter the Artist Name: ggggggggggg

Enter the Number of Songs: 1

Enter the Song Title 1 rttyui

Enter the length of Song 1 500

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 1

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 4

                        CD

Artist: aa

CD Name: ss

Number of Songs: 1

Length of CD: 10

Song Title: 1 as

Song Length: 1 10

                        CD

Artist: aaaaaaaa

CD Name: ggggggggggg

Number of Songs: 1

Length of CD: 500

Song Title: 1 rttyui

Song Length: 1 500

                        CD

Artist: zz

CD Name: xx

Number of Songs: 1

Length of CD: 33

Song Title: 1 xz

Song Length: 1 33

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 1

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 2

Enter the record to delete: 1

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 1

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 4

                        CD

Artist: aaaaaaaa

CD Name: ggggggggggg

Number of Songs: 1

Length of CD: 500

Song Title: 1 rttyui

Song Length: 1 500

                        CD

Artist: zz

CD Name: xx

Number of Songs: 1

Length of CD: 33

Song Title: 1 xz

Song Length: 1 33

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 2

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 1

Enter the Movie Title: ppp

Enter Length of Movie: 40

Enter Released Year: 2001

Number of actors/actress: 2

Enter the Actor / Actress Name: 1 asas

Enter the M for Actor F for Actress: 1 M

Enter the Actor / Actress Name: 2 fgghhj

Enter the M for Actor F for Actress: 2 F

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 2

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 1

Enter the Movie Title: tttt

Enter Length of Movie: 500

Enter Released Year: 2014

Number of actors/actress: 1

Enter the Actor / Actress Name: 1 rtty

Enter the M for Actor F for Actress: 1 M

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 2

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 4

                         DVD

Movie Title: ppp

Length of Movie: 40

Year Released: 2001

Actors/Actresses: 1 asas

Characters: 1 M

Actors/Actresses: 2 fgghhj

Characters: 2 F

                         DVD

Movie Title: tttt

Length of Movie: 500

Year Released: 2014

Actors/Actresses: 1 rtty

Characters: 1 M

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 2

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 3

Enter the record number to update: 2

Enter the Movie Title: qqqqqqqqqqqqq

Enter Length of Movie: 800

Enter Released Year: 2016

Number of actors/actress: 1

Enter the Actor / Actress Name: 1 lkjhgfd

Enter the M for Actor F for Actress: 1 F

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 2

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 4

                         DVD

Movie Title: ppp

Length of Movie: 40

Year Released: 2001

Actors/Actresses: 1 asas

Characters: 1 M

Actors/Actresses: 2 fgghhj

Characters: 2 F

                         DVD

Movie Title: qqqqqqqqqqqqq

Length of Movie: 800

Year Released: 2016

Actors/Actresses: 1 lkjhgfd

Characters: 1 F

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 2

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 2

Enter the record to delete: 1

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 2

1) Add

2) Remove

3) Update

4) Display

Enter your choice: 4

                         DVD

Movie Title: qqqqqqqqqqqqq

Length of Movie: 800

Year Released: 2016

Actors/Actresses: 1 lkjhgfd

Characters: 1 F

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 6

Invalid choice!

Enter your choice:

1) CD

2) DVD

3) Exit

Enter your choice: 3

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