-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSong.cpp
More file actions
115 lines (101 loc) · 2.51 KB
/
Song.cpp
File metadata and controls
115 lines (101 loc) · 2.51 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**@file Song.cpp
* Implementation of Song.h to create Song objects
* @authors Forrest Wargo, Rup Patel, Elias Platt
*/
#include "Song.h"
#include <iostream>
#include <sstream>
/***
*
* @param artist
* @param title
* constructor
*/
Song::Song(std::string artist, std::string title){ //default constructor int length, int year
this->title = title;
this->artist = artist;
this->length = 0;
this->year = 0;
playcount = 0;
}
/***
* default constructor
*/
Song::Song(){
this->artist = "default";
this->title = "default";
this->length = 0;
this->year = 0;
playcount = 0;
}
/***
* takes in string of songs and splits each in the form of title, artist, length and year
* @param songStr
*/
Song::Song(std::string songStr) {
//song string should be in form: title, artist, length, year, playcount
std::stringstream splitter (songStr);
std::string yearStr, lengthStr, space;
getline(splitter, title, ',');
getline(splitter, space, ' ');
getline(splitter, artist, ',');
getline(splitter, space, ' ');
getline(splitter, lengthStr, ',');
getline(splitter, space, ' ');
getline(splitter, yearStr, ',');
if(yearStr.find("*") != lengthStr.npos){
year = std::stoi(yearStr.substr(0,yearStr.rfind("*")));
playcount = std::stoi(yearStr.substr(yearStr.rfind("*")+1));
}else{
year = std::stoi(yearStr);
playcount = 0;
}
if(lengthStr.find(":") != lengthStr.npos){
length = std::stoi(lengthStr.substr(0,lengthStr.rfind(":")))*60;
length += std::stoi(lengthStr.substr(lengthStr.rfind(":")+1));
}else{
length = std::stoi(lengthStr);
}
}
std::string Song::toString() {
std::string result = "";
result+= this->getTitle() +", by "+this->getArtist()+", "+ std::to_string(this->getLength())+" seconds long, year: "+ std::to_string(this->getYear())+", playCount: "+std::to_string(playcount);
return result;
}
/***
* @return title of the song
*/
const std::string &Song::getTitle() const {
return title;
}
/***
* @return artist of the song
*/
const std::string &Song::getArtist() const {
return artist;
}
/***
* @return length of the song
*/
int Song::getLength() const {
return length;
}
/***
* @return year song was released
*/
int Song::getYear() const {
return year;
}
/***
* increases count of song played
*/
void Song::incrementPlaycount() {
playcount++;
}
/**
* gets playCount of the song
* @return playcount (int)
*/
int Song::getPlaycount() {
return playcount;
}