Untitled
unknown
plain_text
4 years ago
5.1 kB
13
Indexable
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name[100];
int ch;
string title[100][100];
string artist[100][100];
string genre[100][100];
float length[100][100];
float totalLength = 0.0; // initialized with a value.
int contaddplaylist = 1; //What is this? this is the holder if the playlist will continue(1) or not(0)
int contaddsong = 1; //What is this? this is the holder if the playlist will continue(1) or not(0)
string decisionsong = "y"; //this is the variable for the entered key of user when the system asks if he wants to add a song
string decisionplaylist = "y"; //this is the variable for the entered key of user when the system asks if he wants to add a playlist
int indexofplaylist = 0; // this is the index of array name[], we put it outside the case
cout << "############################################################\n";
cout << "DJ Playlist Manager\n";
cout << "############################################################\n\n\n";
//this is your code do while to keep the menu going back until the user chooses to exit
do {
cout << "\n 1 - Create Playlist";
cout << "\n 2 - Display Playlist";
cout << "\n 3 - Exit";
cout << "\n\nEnter Your Choice: ";
cin >> ch;
cin.ignore();
//Conditional Expression :
switch (ch) {
case 1: //Input Data
while (contaddplaylist == 1) {
cout << "Insert a name for this playlist: ";
getline(cin, name[indexofplaylist]);
cin.clear();
cin.ignore(10000, '\n');
cout << "\nWelcome to playlist " + name[indexofplaylist];
int j = 0;
//
while (contaddplaylist == 1) {
cout << "\nInsert the title of song " + std::to_string(j + 1) + ": " << endl;
cin >> title[indexofplaylist][j];
cin.clear();
cout << "Insert the artist name of song " + std::to_string(j + 1) + ": " << endl;
cin >> artist[indexofplaylist][j];
cin.clear();
cout << "Insert the genre of song " + std::to_string(j + 1) + ": " << endl;
cin >> genre[indexofplaylist][j];
cin.clear();
cout << "Insert the length of song " + std::to_string(j + 1) + ": " << endl;
cin >> length[indexofplaylist][j];
cin.clear();
//this is where we asks if they want to continue adding song inside the current playlist
cout << "\nDo you still want to continue add song to\nyour playlist " + name[indexofplaylist] + "? Input [n] if No or input [any key] if Yes" << endl;
cin >> decisionsong;
cin.clear();
cin.ignore(10000, '\n');
if (decisionsong == "n") {
contaddsong = 0;
break;
}
else {
j++;
}
}
//this is where we asks if they want to continue adding playlist
cout << "\nDo you still want to add another playlist? Input [n] if No or input [any key] if Yes.";
cin >> decisionplaylist;
cin.clear();
cin.ignore(10000, '\n');
if (decisionplaylist == "n") {
contaddplaylist = 0;
break;
}
else {
indexofplaylist++;
}
}
break;
case 2:
for (int i = 0; i <= indexofplaylist; i++) {
float playlisttotallength = 0;
cout << "\n\nPlaylist " + name[i];
for (int j = 0; j < 100; j++) {
if (title[i][j] == "") {
break;
}
else {
cout << "\n Song #" + std::to_string(j + 1) + ": \n" << endl;
cout << " Title: " + title[i][j] + "\n";
cout << " Artist: " + artist[i][j] + "\n";
cout << " Genre: " + genre[i][j] + "\n";
cout << " Length: " + std::to_string(length[i][j]) << endl;
playlisttotallength += length[i][j];
}
}
//here we put display the playlisttotallength
cout << "\n\n Playlist " + name[i] + " has a total length of" + std::to_string(playlisttotallength) + "\n" << endl;
}
break;
case 3:
_Exit(0);
break;
default:
cout << "\n Provide correct Choice \n";
while (true);
}
} while (true);
}Editor is loading...