-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory.cpp
More file actions
183 lines (147 loc) · 4.59 KB
/
Inventory.cpp
File metadata and controls
183 lines (147 loc) · 4.59 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//
// Created by emurray2 on 12/11/2019.
//
#include <iostream>
#include <string>
#include <stdexcept>
#include "Inventory.h"
#include "SongsLinkedNode.h"
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
Inventory::Inventory(){
this->end= nullptr;
this->front= nullptr;
int count=0;
}
void Inventory::particularSong(string artistName,string songTitle) {
SongsLinkedNode*temp=front;
while(temp!=nullptr){
if(temp->getArtistName()==artistName&temp->getSongName()==songTitle){
cout<<temp->getArtistName()+" "+ temp->getSongName()<<endl;
cout<<"The length of the song is";
cout<<temp->getDuration();
}
temp=temp->getNext();
}
}
void Inventory::clearLibrary(){
if(front!=end){
SongsLinkedNode*newNode=front;
this->front=front->getNext();
delete newNode;
}
delete front;
delete end;
}
void Inventory::particularArtist(std::string artistName) {
SongsLinkedNode*temp=front;
while(temp!=nullptr){
if(temp->getArtistName()==artistName){
cout<<temp->getArtistName()+" "+ temp->getSongTitle()<<endl;
}
temp=temp->getNext();
}
}
void Inventory::particularAS(std::string artistName,string songtitle) {
SongsLinkedNode*temp=front;
while(temp!=nullptr){
if(temp->getArtistName()==artistName&temp->getSongTitle()==songtitle){
cout<<temp->getArtistName()+" "+ temp->getSongTitle()<<endl;
cout<< "The duration of the song is: ";
cout<<temp->getDuration()<<endl;
}
temp=temp->getNext();
}
}
void Inventory::currentSongs() {
// can be used for display and to check alphabetical order
SongsLinkedNode*temp=front;
if(front== nullptr&end== nullptr){
cout<<"Library is emppty";
}
while(temp!= nullptr){
// cout<<temp->getArtistName() +""+temp->getArtistName();
std::string str=temp->getSongName()+'\n'+temp->getArtistName();
cout<<str<<endl;
cout<<'\n';
//count=count+1;
temp=temp->getNext();
//cout<<end->getArtistName()+ " "+end->getSongName()<<endl;
}
}
void Inventory::countSongs() {
SongsLinkedNode*temp=front;
while(temp!= nullptr){
this->count=this->count+1;
}
}
void Inventory::addSong(std::string artistName,std::string title, double duration) {
SongsLinkedNode *newNode = new SongsLinkedNode(artistName, title, duration);
SongsLinkedNode *temp = front;
if (front == nullptr) {
front = newNode;
end = newNode;
} else {
temp = front;
//Songs *ahead;
if (newNode->getArtistName() < front->getArtistName()) {
newNode->setNext(front);
front = newNode;}
else if (newNode->getArtistName() > end->getArtistName()) {
end->setNext(newNode);
end = newNode;
}
else{
temp=front;
while(temp->getNext()->getArtistName()<newNode->getArtistName()){
temp=temp->getNext();
}
newNode->setNext(temp->getNext());
temp->setNext(newNode);
}
}
}
void Inventory::removeSong(string artistName,string songName) {
if (front->getArtistName()==artistName&front->getSongName()==songName) {
if(front==end){
front= nullptr;
end= nullptr;
}
}
else if(songName==end->getSongName()&artistName==end->getArtistName()) {
SongsLinkedNode*temp=front;
while(temp->getNext()!=end){
temp=temp->getNext();
}
delete end;
end=temp;
end->setNext(nullptr);}
else{
SongsLinkedNode*temp=front->getNext();
while(temp->getNext()->getArtistName()!=artistName&temp->getNext()->getSongName()!=songName){
temp=temp->getNext();
}
if(temp->getNext()->getArtistName()==artistName&temp->getNext()->getSongName()==songName){
delete temp->getNext();
temp->setNext(temp->getNext()->getNext());}
else{
cout<<"Song is not in the inventory."<<endl;
}
}
}
void Inventory ::ReadFromFile(std::string playListName) {
std::ifstream in;
in.open("ListofSongs.txt");
std::string songTitle, artistName, duration;
// std::cout << in.is_open() << std::endl;
//PlayList newSonglist = PlaylistLinkedQueue();
Inventory newSongsList();
while (!in.eof()) {
getline(in, songTitle);
getline(in, artistName);
getline(in, duration);
addSong(songTitle, artistName, std::stod(duration));
}
}