Hey guys, this is my last assignment of the year. My grade in c++ isn't that good and I just want to finish this program completely so I can bump up my grade a bit.
The program has to use classes. I attempted it a bit but I'm not too familiar with classes(only spent about 3 days on it).
Here is the program requirements:
- A textfile with 15 songs (must have artist, title, and time of track, but you can format it however you'd like)
- A CD class
- The user should be able to choose songs from the textfile to add to the cd
- the user should be able to "delete" songs from the cd
- the user should be able to see a current list of songs
- the user should be able to see a length of any song, or the length of the entire cd in the format "hh:mm:ss"
- in addition, the user should able to request to see a specific song's information - for example if they want to get all the
information on the song "don't speak" you'll get "no doubt - don't speak - 3:48" or something along those lines.
I got the textfile with the songs done:
Dream on - Aerosmith - 4:28
Sweet Child O' Mine - Guns N' Roses - 5:56
Thunderstruck - AC/DC - 4:52
Breathe Into Me - Red - 3:36
Fireproof - Pillar - 3:46
Hero - Skillet - 3:09
Don't Stop Believin' - Journey - 4:11
New Divide - Linkin Park - 4:37
Wanted Dead Or Alive - Bon Jovi - 5:11
All The Right Moves - OneRepublic - 3:24
Sweet Home Alabama - lynyrd Skynyrd - 4:45
One - Metallica - 7:24
Crazy Train - Ozzy Osbourne - 4:52
Back in Black - AC/DC - 4:16
Iron Man - Black Sabbath - 5:37
I will post my code once I finish with the int main. Thanks to anyone that helps!
That sounds pretty straightforward right? Just create a stack. A function to "push" a new song into the stack shouldn't be that hard. Deleting might get slightly more complicated however. The rest sounds like basic I/O file handling.
#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
class CD
{
private:
string Song;
public:
void Delete(string Song);
void AddSongs(string Song);
void SeeSongs();
void Time(string song);
}
void CD::AddSongs(string Song)
{
for(int x = 0; x < 15; x++)
{
Song = SongList[x];
}
}
void CD::Delete(string Song)
{
if(Song != CDList)
cout << "This song is not added on your CD list." << endl;
else
{
Song.delete;
cout << "The song was deleted." << endl;
}
}
void CD::SeeSongs()
{
for(int x = 0; x < 15; x++)
{
getline(CDPlayer, Song, '#');
cout << Song << endl;;
}
}
void CD::Time(string Song)
{
}
int main()
{
CDPlayer AddSong, DeleteSong, ListSongs, Time;
string SongList[15] = {""};
ifstream CD;
string Song;
int Option;
char Continue = ' ';
CDPlayer.open("CD Program", ios::in);
Continue = 'y';
while(Continue == 'y')
{
cout << "Press 1 to add songs, 2 to delete songs, 3 to see a current list of songs,"" 4 to see entire length, or 5 to see a specific song information: ";
cin >> Option;
if(Option == 1)
{
cout << "Enter the song you want to add: ";
cin >> Song;
AddSong.AddSongs(Song);
cout << Song << " was added to your CD." << endl;
}
elseif(Option == 2)
{
cout << "Enter the song you want to delete: ";
cin >> Song;
DeleteSong.Delete(Song);
cout << Song << " was deleted from your CD." << endl;
}
elseif(Option == 3)
{
ListSongs.SeeSongs();
}
else
{
Time.Time(string Song);
}
cout << "Would you like to continue? ";
cin >> Continue;
}
system("PAUSE");
return 0;
}