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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#include <iostream>
#include <string>
#include <fstream>
#include "Song.h"
#include "Song.cpp"
using namespace std;
class Song playlist[200];
void readFile (Song playlist[], string line, int counter); //For all declarations - Expected ')' and Incomplete type void
void addSong (Song playlist[], int counter);
void removeSong (Song playlist[], int counter);
void displaySongs (Song playlist[], int counter);
int quitProgram();
int main ()
{
ifstream inFile;
ofstream outFile;
string infilePath;
cout << "Enter the file path for 'songs.txt'.";
cin >> infilePath;
inFile.open(infilePath.c_str(), ifstream::in);
if (!inFile)
{
cout << "Can not open input file."<< endl;
return 1;
}
string line;
getline(inFile, line);
int counter = 0;
while (!inFile.eof())
{
readFile(playlist, line, counter); //Use of undeclared identifier readFile
getline(inFile, line);
counter++;
}
char option;
cout << "Enter the number of the option you which to use:" << endl;
cout << "1 Add a song." << endl << "2 Remove a song." << endl << "3 Display all songs." << endl << "4 Quit." << endl;
cin >> option;
switch (option)
{
case 1: addSong (playlist, counter); //Use of undeclared identify addSong
counter++;
break;
case 2: removeSong (playlist, counter); //Use of undeclared identifier removeSong
counter--;
break;
case 3: displaySongs (playlist, counter); //Use of undeclared identifier displaySong
break;
case 4: quitProgram();
break;
default:
cout << "That is not a valid choice." << endl;
return main();
}
}
//*********************************
void readFile(Song playlist[], string line, int counter) //Variable has incomplete type void (x2)
{ //Expected ')'
int first = line.find_first_of(':'); //Take input line then take out the : and create a substring
playlist[counter].songTitle = line.substr(0, first);
int second = line.find(':', first + 1);
playlist[counter].songArtist = line.substr(first + 1, second - (first + 1));
int third = line.find(':', second + 1);
playlist[counter].songAlbum = line.substr(second + 1, third - (second + 1));
return;
}
void addSong(Song playlist[], int counter) //function that adds a song to the playlist
{
cout << "Enter the name of the song you wish to add:" << endl;
cin >> playlist[counter].songTitle;
cout << "Enter the name of the artist of the song:" << endl;
cin >> playlist[counter].songArtist;
cout << "Enter the album of the song:" << endl;
cin >> playlist[counter].songAlbum;
return;
}
void removeSong(Song playlist[], int counter)
{
int indexToRemove;
cout << "What number song do you wish to remove?" << endl;
cin >> indexToRemove;
//decrease the number of elements
for(int i = indexToRemove; i < counter; i++)
playlist[i] = playlist[i+1]; //shift elements over to remove element in index
return;
}
void displaySongs(Song playlist[], int counter)
{
cout << "The current songs on the playlist are:" << endl;
int ticker;
for (ticker = 0 ; ticker <= counter; ticker++)
{
cout << playlist[ticker].songTitle << ':' << playlist[ticker].songArtist << ':'<< playlist[ticker].songAlbum << endl;
}
return;
}
int quitProgram()
{
//Output the updated song list to songs.txt
return 0;
}
|