-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSong.cpp
78 lines (70 loc) · 2.12 KB
/
Song.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
CSI-240-52
Joe Healy
Final Assignment
Song Class Definition
*/
#include "song.h"
const string Song::GENRE_NAMES[] = { "Alternative", "Blues", "Classical", "Country", "Electronic", "Hip-Hop/Rap", "Indie", "Jazz", "Pop", "R&B", "Rock" };
/*default constructor - initializes member data
PRE: none
POST: length, and year set to 0
album, and artist set to empty string
genre set to UNKNOWN
*/
Song::Song()
{
this->year = 0;
this->album = "";
this->artist = "";
this->genre = Genres::UNKNOWN;
}
/*value constructor - allows user to set member data on construction
PRE: n, a, al, g, and y are valid
POST:
name set to n
artist set to a,
album set to al,
genre set to g,
year set to y
*/
Song::Song(string n, string a, string al, Genres g, int y)
{
this->name = n;
this->artist = a;
this->genre = g;
this->album = al;
this->year = y;
}
/*copy constructor - allows user to create a copy of a song
PRE: other is valid
POST: new Song created, as a cop of other
*/
Song::Song(const Song& other)
{
this->name = other.name;
this->artist = other.artist;
this->genre = other.genre;
this->album = other.album;
this->year = other.year;
}
/*toString - returns a strign representation of the song object
PRE: none
POST: FCTVAL is a formatted string containing details on the song object
*/
string Song::toString()
{
string space = " ";
return "\n" + name + "\nArtist: " + space.substr(0, space.length() - artist.length()) + artist
+ "\nAlbum: " + space.substr(0, space.length() - album.length()) + album
+ "\nGenre: " + space.substr(0, space.length() - GENRE_NAMES[genre].length()) + GENRE_NAMES[genre]
+ "\nYear: " + space.substr(0, space.length() - to_string(year).length()) + to_string(year);
}
/*Comparisson operator allows user to compare two songs
PRE: other is valid
POST: returns true if attributes of this object are equal to the attributes of other
*/
bool Song::operator==(const Song &other)
{
return (this->name == other.name && this->album == other.album && this->artist == other.artist && this->genre == other.genre && this->year == other.year);
}