CLASS: SONG

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
//Song Class
#ifndef SONG_CLASS
#define SONG_CLASS


using namespace std;

class Song
{
private:
	string title; //dynamic allocation
	string album;
	string genre;
	string artist;
	double durationn;

public: 
	Song();
	void setTitle(string t);
	void setDuration(double d);
	void setAlbumName(string a);
	void setGenre(string g);
	void setArtist(string a);
	string getTitle();
	string getAlbum()const;
	string getGenre()const;
	string getArtist()const;
	double getDuration)(); //accessor
};

//constructor
Song::Song() //constructor
{
	title="";
	album="";
	genre="";
	artist="";
	duration=0;
}

//accessor for name
string Song::getTitle()
{
return title;
}
//mutator
void Song::setTitle(string t)
{
title=t;
}
//accessor for name
string Song::getAlbum()
{
return album;
}
//mutator
void Song::setAlbumName(string a)
{
album=a;
}
//accessor for name
string Song::getGenre()
{
return genre;
}
//mutator
void Song::setGenre(string g)
{
genre=g;
}
//accessor for name
string Song::getArtist()
{
return artist;
}
//mutator
void Song::setArtist(string s)
{
artist=s;
}

void Song::setDuration(double d)
{
duration=d;
}
double Song::getDuration()
{
return duration;
}

#endif   // SONG_CLASS



//FOR THE .CPP

I DO NOT KNOW HOW TO DISPLAY IT THERE.
CAN ANYONE HELP?

//file test.cpp
#include <iostream>
#include <fstream>
#include <string>
#include "song.h"

using namespace std;

int main()
{

	return 0;
}

Last edited on
I don't know where do you have problem. But for me is confusing line Song::Song(): title(""), album(""), artist(""), genre(""), duration(0){}

If I remove this line everything Ok. Is this sort of inheritance or what?
You've written the default constructor twice:
Here:
1
2
3
4
5
6
7
8
9
10
//Implement a constructor
Song::Song() //constructor
{
title="";
album="";
genre="";
artist="";
duration = 0;
}



and then again here:
1
2
//Initialization List
Song::Song(): title(""), album(""), artist(""), genre(""), duration(0){}



PS - use code tags to display your code
Last edited on
Topic archived. No new replies allowed.