In: Computer Science
Program is to be written in C++ using Visual studios Community
You are to design a system to keep track of either a CD or DVD/Blu-ray collection. The program will only work exclusively with either CDs or DVDs/Blu-rays since some of the data is different. Which item your program will work with will be up to you. Each CD/DVD/Blu-ray in the collection will be represented as a class, so there will be one class that is the CD/DVD/Blu-ray. The CD class will be limited to five (5) songs, and the class will need to keep an array of five (5) strings for the song titles. It should also maintain the length of each song and the total length of the CD, as well as the artist name. The DVD/Blu-ray class will have a data member for the title of the movie, length of the movie, the year of the movie, and for the names of two of the main actors in the movie. There will be a class that maintains the list of CD/DVDs/Blu-rays. This list can be limited to just 5 CD/DVD/Blu-rays and provide a method to add a CD/DVD/Blu-ray, to remove a CD/DVD/Blu-ray, and to update a CD/DVD/Blu-ray.
The program should provide a menu for the user to be able to add, delete, update and display the information in a CD/DVD/Blu-ray. Include a comment block at the top of the code file of what the program does.
1. The solution contains 3 classes Cd , Dvd and CollectionCD_DVD.
2. Implementation can be seen inside the code.
3. Methods like display can be fully implemented using the below code as reference.
Code :
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//class CD
class Cd{
public :
string songs[5];
int songLen[5];
int cdLen;
string artistName;
public : Cd (){
}
public : Cd(string song[], int songLe[],int cdL, string artistn)
{
for(int i = 0; i < 5; ++i)
{songLen[i] = songLe[i];
songs[i] = song[i];}
cdLen = cdL;
artistName = artistn;
}
};
// class dvd
class Dvd{
public :
string title;
int length;
int year;
string actor1;
string actor2;
public : Dvd(){
}
public : Dvd(string mtitle, int mlength,int myear, string mactor1,string mactor2)
{
title = mtitle;
length = mlength;
year = myear;
actor2 = mactor2;
actor1 = mactor1;
}
};
//class containing the list of cd/dvd
class CollectionCD_DVD{
int noCd=0;
int noDvd=0;
Cd cdList[5];
Dvd dvdList[5];
public : CollectionCD_DVD()
{}
void addCd(Cd cd)
{
cdList[noCd++]=cd;
cout<<"added cd\n";
}
void addDvd(Dvd dvd)
{
dvdList[noDvd++]=dvd;
cout<<"added dvd\n";
}
void updateCD(int index, Cd cd)
{
cdList[index]=cd;
cout<<"updated cd\n";
}
void updateDvd(int index, Dvd dvd)
{
dvdList[index]=dvd;
cout<<"updated dvd\n";
}
void deleteCd()
{
noCd--;
//last element of the cd gets deleted
}
void deleteDvd()
{
noDvd--;
//last element of the dvd gets deleted
}
void display()
{
for(int i=0;i<5;i++)
cout<<cdList[i].artistName<<endl;
//you can display other fields similarly
}
};
int main()
{
CollectionCD_DVD obj = CollectionCD_DVD();
string s[5]= {"a","b","c","d","e"};
int l[5] = {1,2,3,4,5};
Cd cd = Cd(s,l,15,"dummyartist");
Dvd dvd = Dvd("avb",12,12,"abc","abc");
//adding item to list cd
obj.addCd(cd);
obj.addCd(cd);
obj.addCd(cd);
obj.addCd(cd);
obj.addCd(cd);
//adding item to the list dvd
obj.addDvd(dvd);
obj.addDvd(dvd);
obj.addDvd(dvd);
obj.addDvd(dvd);
obj.addDvd(dvd);
//methods of the class
obj.display();
obj.deleteDvd();
obj.deleteCd();
obj.updateCD(2, cd);
return 0;
}
Output :