Classes and Objects

I am making this program simulates an ipod and has songs and makes playlists. We are using lots of pointers which I understand them but not necessarily how to incorporate them. My problem right now is that when i print the list you have to print the song name and first line. How do i access my GetName and GetFirstline function to print it out? Is that even possible?
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
#include <iostream>
#include <vector>
#include <string>
#include "Song.h"
#include "Playlist.h"

using namespace std;

void PrintMenu(){
    
    cout << "Please select one of the following options: " << endl;
    cout << endl;
    cout << "0 - Quit the program" << endl;
    cout<< "1 - Add songs" << endl;
    cout << "2 - List all songs" << endl;
    cout << "3 - Add a playlist" << endl;
    cout << "4 - Add a song to a playlist" << endl;
    cout << "5 - Play a playlist" << endl;
    cout << endl;
    cout << "Enter your selection now: " << endl;
}

vector <Song*>AddSong() {
    string songName;
    string songFirstLine;
    vector<Song*> songs;
    cout << "Read in Song names and first lines: " << endl;
    while (true) {
        cout << "Song Name (type \"STOP\" when done): " << endl;
        cout << endl;
        getline (cin, songName);
        if (songName == "STOP") {
            break;
        }
        cout << "That song's first line: " << endl;
        getline(cin, songFirstLine);
        Song* song = new Song(songName, songFirstLine);
        songs.push_back(song);
    }
    return songs;
}

void PrintSongList(vector<Song*> songs) {
    int count = 0;
    for(unsigned int i=0; i < songs.size(); i++) {
        cout << i << ": " << "Name: \"" << songs.at(i) << "\" FirstLine: \"" << songs.at(i) << "\" Played " << count << " times." << endl;
    }
    
}

int main() {
    int menuOption;
    vector <Song*> songs;
    
    cout <<"Welcome to the Firstline Player!" << endl;
    cout << endl;
    cout << endl;
    
    do {
        PrintMenu();
        cin >> menuOption;
        cin.ignore();
    
    switch(menuOption){
        case 0:
            cout << "GOODBYE!" << endl;
            return 0;
        case 1: {
            vector<Song*> songsList = AddSong();
            songs.insert(songs.end(), songsList.begin(), songsList.end());
            break;
        }
        case 2:
            PrintSongList(songs);
            break;
        /*case 3:
            break;
        case 4:
            break;
        case 5:
            break;
        default:
        */
        }
    }while (menuOption == true);
    return 0;
}

#ifndef Song_h
#define Song_h

#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

class Song {
public:
    Song(string songName, string songFirstLine);
    string GetName();
    string GetFirstLine();
    void IncreaseCount();
    
private:
    string songName;
    string songFirstLine;
    int count;
    
};


#endif /* Song_h */

#include "Song.h"

Song::Song(string songName, string songFirstLine) {
    this->songName = songName;
    this->songFirstLine = songFirstLine;
    count = 0;
    return;
}
string Song::GetName(){
    return songName;
}
string Song::GetFirstLine() {
    return songFirstLine;
}
void Song::IncreaseCount() {
    count++;
    return;
    
}
Last edited on
Topic archived. No new replies allowed.