The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 337 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I need to add arrays to the current code I have, I use visual studio, c++. For example for this dj program you can add the ability to handle multiple songs and playlists. The electrical program should handle multiple customer scenarios.
#include <iostream>
#include <cmath>
using namespace std;
enum Genre {
Blues, Rock, Pop, Jazz, Unknown
};
int noSong = 0;
class SongInfo {
private:
string _name;
string _artist;
string _album;
Genre _g;
double _length;
public:
SongInfo() {
}
void loadSongInfo(string name, string artist, string album, Genre g,
double length) {
_name = name;
_artist = artist;
_album = album;
_g = g;
_length = length;
}
Genre getSongGenre() {
return _g;
}
void displaySongInfo() {
cout << "Song Name:" << _name << endl;
cout << "Artist Name:" << _artist << endl;
cout << "Album Name:" << _album << endl;
string g;
switch (_g) {
case Blues:
g = "Blues";
break;
case Rock:
g = "Rock";
break;
case Pop:
g = "Pop";
break;
case Jazz:
g = "Jazz";
break;
default:
g = "Unknown";
break;
}
cout << "Genre Name:" << g << endl;
cout << "Length in mins:" << _length << endl;
}
};
class Jocker {
public:
// constructor
int calculatePaylist(int songLen, int numberOfSongs) {
this->songLen = songLen;
this->numberOfSongs = numberOfSongs;
avPlayListlen = songLen * numberOfSongs;
return avPlayListlen;
}
// hidden data from outside world
int songLen;
int numberOfSongs;
int avPlayListlen;
};
SongInfo songs[100];
//Menu
int menu() {
int choice;
cout << "1. Add Song to PlayeList: \n";
cout << "2. Show Playlist by Genre\n";
cout << "3. Display Playlist\n";
cout << "4. Exit\n";
cout << "Enter the option: ";
cin >> choice;
while (choice < 1 || choice > 4) {
cout << "Option must be between (1-4): ";
cin >> choice;
}
return choice;
}
//Main function
int main() {
string name;
string artist;
string album;
Genre g;
double length;
while (true) {
int option = menu();
if (option == 1) {
cout << "Enter name of song (e.g. Last Day)" << endl;
cin >> name;
cout << "Enter name of arist (e.g. Taylor Swift)" << endl;
cin >> artist;
cout << "Enter name of album (e.g. Breaking Bad)" << endl;
cin >> album;
cout << "Enter genre - Blues = 1, Rock=2, Pop=3 and Jazz=4" << endl;
int choice = 0;
cin >> choice;
switch (choice) {
case 1:
g = Blues;
break;
case 2:
g = Rock;
break;
case 3:
g = Pop;
break;
case 4:
g = Jazz;
break;
default:
g = Unknown;
break;
}
cout << "Enter length of song in minutes (e.g. 5.2)" << endl;
cin >> length;
songs[noSong].loadSongInfo(name, artist, album, g, length);
noSong++;
} else if (option == 2) {
cout << "List songs by genre - Blues = 1, Rock=2, Pop=3 and Jazz=4"
<< endl;
int choice = 0;
cin >> choice;
cout << "Listing songs " << endl;
for (int i = 0; i < noSong; i++) {
Genre g;
switch (choice) {
case 1:
g = Blues;
break;
case 2:
g = Rock;
break;
case 3:
g = Pop;
break;
case 4:
g = Jazz;
break;
default:
g = Unknown;
break;
}
if (songs[i].getSongGenre() == g) {
songs[i].displaySongInfo();
}
}
} else if (option == 3) {
cout << "Listing all songs in your collection" << endl;
for (int i = 0; i < noSong; i++) {
songs[i].displaySongInfo();
}
} else if (option == 4) {
cout << "Good Bye!" << endl;
return 0;
}
cout << endl;
}
return 0;
}
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly