-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSong.cpp
107 lines (98 loc) · 3.37 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
/**************************************************************
* Name of the file: Song.cpp *
* Group 6: Ra'Caria Burgess, Janei Elliston, *
* Michael Mondelice, Michael Parrish *
* Date last edited: 4/26/2020 *
* Purpose of Song.cpp: To determine that two songs are equal *
* if they have same name and artist. *
**************************************************************/
#include <iostream>
#include <string>
#include <fstream>
#include <string>
#include "Song.h"
#include <iomanip>
#include <math.h>
using namespace std;
Song::Song()
{
}
Song::Song(string title, string artist)
{
this->title = title;
this->artist = artist;
}
Song::Song(string title, string artist, string album, int length, int year)
{
this->title = title;
this->artist = artist;
this->album = album;
this->length = length;
this->year = year;
}
/**************************************************************
* set the song
**************************************************************/
void Song::set(string title, string artist, string album, int length, int year)
{
this->title = title;
this->artist = artist;
this->album = album;
this->length = length;
this->year = year;
}
/***************************************************************
* compare two song objects for equality
***************************************************************/
bool operator==(const Song& left, const Song& right)
{
return (left.title == rhs.title) && (right.artist == right.artist);
}
/**************************************************************
* 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 << ' ' << "(" << song.year << ")" << endl << "Play Time: " << song.length / 60
<< showpoint << fixed << ':'<< setw(2) << left << (song.length % 60) << 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:
* title, artist, album, year, length
***************************************************************/
istream& operator>>(istream& is, Song& song)
{
cout << "Song Details" << endl;
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;
}
/********************************************************
* input from file
********************************************************/
fstream& operator>>(fstream& is, Song& song)
{
is >> song.title >> song.artist >> song.album >> song.year >> song.length;
return is;
}