-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrack.cpp
More file actions
86 lines (68 loc) · 2.52 KB
/
Track.cpp
File metadata and controls
86 lines (68 loc) · 2.52 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
//Mark Hentges 5814125
//
#include "Track.h"
#include "Disk.h"
Track::Track(std::shared_ptr<Disk> associatedDisc) {
//makes it point to a disk
discPtr = associatedDisc;
}
Track::~Track(){
std::cout << "track destructor called - track name: "<< name << std::endl;
}
void Track::printTrack() const {
//prints out track information
std::cout << "Track number: " << number << "\nTrack name: " << name << "\nTrack Artist: " << artist <<
"\nTrack play time: " << playTime/60 << ":" << playTime%60 << "\nTrack location: " << location << std::endl;
}
int Track::getNumber() const {
//prints
return number;
}
int Track::getPlayTime() const {
//printss out play time
return playTime;
}
std::shared_ptr<Track> Track::getTrackFromUser(std::shared_ptr<Disk> associatedDisk) {
//generates a track form user
try{
std::shared_ptr<Track> newTrack = std::move(std::make_shared<Track>(Track(associatedDisk)));
//all of our inputting proceeds this
std::string newName;
std::cout << "Enter the name of the track: " << std::endl;
std::getline(std::cin, newName);
std::string newArtist = "multi artist";
if(!associatedDisk->isMultiArtist()){
std::cout << "Enter the artist name: " << std::endl;
std::getline(std::cin, newArtist);
}
std::string strPlayTime;
std::cout << "Enter the play time of the track(\"min:sec\"): " << std::endl;
getline(std::cin, strPlayTime);
std::string newNum;
std::cout << "Enter the track's associated number: " << std::endl;
getline(std::cin, newNum);
int intPlaytime = 0;
for(int i = 0;i < strPlayTime.length(); ++i){
if(strPlayTime[i] == ':'){
intPlaytime += std::stoi(strPlayTime.substr(0, i)) * 60;
intPlaytime += std::stoi(strPlayTime.substr(i+1));
break;
}
}
std::string filePath;
std::cout << "Enter the path name: " << std::endl;
std::getline(std::cin, filePath);
newTrack->name = newName;
newTrack->artist = newArtist;
newTrack->playTime = intPlaytime;
newTrack->location = filePath;
newTrack->number = std::stoi(newNum);
return newTrack;
}catch(std::bad_alloc& e){
std::cerr << "ERROR: memory allocation failed" << std::endl;
return nullptr;
}catch(std::exception& e){
std::cerr << "Some extraneous error has happened" << std::endl;
return nullptr;
}
}