-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSong.cpp
98 lines (74 loc) · 2.17 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include "Song.h"
#include <string>
using namespace std;
Song::Song()
{
}
Song::Song(string title, string artist, string album, int length, int year)
{
//** Sets private variable equal to the parameter value **//
this->title=title;
this->artist=artist;
this->album=album;
this->length=length;
this->year=year;
}
void Song::set(string title, string artist, string album, int length, int year)
{
//** Sets private variable equal to the parameter value **//
this->title=title;
this->artist=artist;
this->album=album;
this->length=length;
this->year=year;
}
string Song::getTitle()
{
return title;
}
// output the song in the format:
// title, artist, album, year, length
// output to console
ostream& operator<<(ostream& os, const Song& song)
{
os<< song.title<<endl<<song.artist<<endl<<song.album<<endl<<song.year<<endl<<song.length<<endl;//
return os;
}
//output to file
ofstream& operator<<(ofstream& os, const Song& song)
{
os<<song.title<<","<<song.artist<<","<<song.album<<","<<song.year<<","<<song.length<<endl;
return os;
}
// input the song in the format:
// from user
// title, artist, album, year, length
istream& operator>>(istream& is, Song& song)//inputting info from file
{
cout<<"Title: "<<endl;
is>> song.title;
cout<<"Artist: "<<endl;
is>>song.artist;
cout<<"Album: "<<endl;
is>>song.album;
cout<<"Year: "<<endl;
is>>song.year;
cout<<"Length: "<<endl;
is>>song.length;
return is;
}
//input from file
fstream& operator>>(fstream& is, Song& song)
{
is>>song.title>>song.artist>>song.album>>song.year>>song.length;
return is;
}
// compare two song objects for equality
bool operator==(const Song& lhs, const Song& rhs)
{
bool same=false;
if((lhs.title==rhs.title )&&(lhs.artist==rhs.title));//compares to different song object, compares title and song name
same=true;
return same;
}