-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSong.cpp
107 lines (88 loc) · 2.52 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
97
98
99
100
101
102
103
104
105
106
107
/*
Group 1: Mario Brown, Chris Williams, Rhiana Long, Elijah Devilme
Song.cpp
*/
#include "Song.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
Song::Song()
{
title="";
artist="";
album="";
length=0;
year=0;
}
Song::Song(string title, string artist, string album, int year, int length)
{
this->title=title;
this->artist=artist;
this->album=album;
this->year=year;
this->length=length;
}
void Song::set(string title, string artist, string album, int year, int length)
{
this->title=title;
this->artist=artist;
this->album=album;
this->length=length;
this->year=year;
}
ostream& operator<<(ostream& os, const Song& song)
{
int p1=song.length/60;
int p2=(song.length%60);
os <<song.title <<endl;
os <<song.artist <<endl;
os <<song.album <<"(" << p1 <<":"<< p2 <<")" << endl;
os <<song.year;
return os;
}
ofstream& operator<<(ofstream& os, const Song& song)
{
int p1=song.length/60;
int p2=(song.length%60);
os <<song.title << ',';
os <<song.artist << ',';
os <<song.album << ',';
os <<song.year << ',';
os <<song.length;
return os;
}
istream& operator>>(istream& is, Song& song)
{
cout << "Title: ";
is >> song.title;
cout << "Artist: ";
is >>song.artist;
cout << "Album: ";
is >> song.album;
cout << "Year: ";
is >> song.year;
cout << "Length (in seconds): ";
is >> song.length;
return is;
}
fstream& operator>>(fstream& is, Song& song)
{
string y, l;
getline(is ,song.title,',');
getline(is ,song.artist,',');
getline(is ,song.album,',');
getline(is ,l,',');
getline(is ,y);
return is;
}
bool operator==(const Song& lhs, const Song& rhs)
{
bool c=false;
if ((lhs.title==rhs.title) && (lhs.artist==rhs.artist)
&& (lhs.album==rhs.album) && (lhs.length==rhs.length) && (lhs.year==rhs.year))
{
c=true;
}
return c;
}