Need assistance in the assignment on using an Array of structs.
I need to know if the array is initialized properly or what i need to do to get it initialized.
Some code has been commented out until i get the array initialized.
Here is the code:
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<string>
using namespace std;
struct Song
{
string title;
int track;
};
struct Album
{
string albumName;
string artistName;
Song songList[4];
};
int main()
{
Album collection[5];
collection[0].albumName = "Private Investigations";
collection[0].artistName = "Dire Straits";
collection[0].songList[0].title = "Sultans of Swing";
collection[0].songList[0].track = 2;
collection[0].songList[1].title = "Romeo and Juliet ";
collection[0].songList[1].track = 4;
collection[0].songList[2].title = "Money for Nothing ";
collection[0].songList[2].track = 9;
collection[0].songList[3].title = "Walk of Life ";
collection[0].songList[3].track = 10;
/*collection[1].albumName = " ";
collection[1].artistName = " ";
collection[1].songList[0].title = " ";
collection[1].songList[0].track = 1;
collection[1].songList[1].title = " ";
collection[1].songList[1].track = 2;
collection[1].songList[2].title = " ";
collection[1].songList[2].track = 3;
collection[1].songList[3].title = " ";
collection[2].songList[3].track = 4;
collection[2].albumName = " ";
collection[2].artistName = " ";
collection[2].songList[0].title = " ";
collection[2].songList[0].track = 1;
collection[2].songList[1].title = " ";
collection[2].songList[1].track = 2;
collection[2].songList[2].title = " ";
collection[2].songList[2].track = 3;
collection[2].songList[3].title = " ";
collection[2].songList[3].track = 4;
collection[3].albumName = " ";
collection[3].artistName = " ";
collection[3].songList[0].title = " ";
collection[3].songList[0].track = 1;
collection[3].songList[1].title = " ";
collection[3].songList[1].track = 2;
collection[3].songList[2].title = " ";
collection[3].songList[2].track = 3;
collection[3].songList[3].title = " ";
collection[3].songList[3].track = 4;
collection[4].albumName = " ";
collection[4].artistName = " ";
collection[4].songList[0].title = " ";
collection[4].songList[0].track = 1;
collection[4].songList[1].title = " ";
collection[4].songList[1].track = 2;
collection[4].songList[2].title = " ";
collection[4].songList[2].track = 3;
collection[4].songList[3].title = " ";
collection[4].songList[3].track = 4;*/
string albumName;
cout<<"what album to search for? ";
cin>> albumName;
}
int search(Album collection[], string albumName)
{
int location;
location = albumName;
for(int i = 0; i<5; i++);
{
if(location == -1)
return -1;
cout<<"Album name not found.";
else
cout<<"Album name is:"<<collection[i].albumName<<"at"
<<location<<".";
}
}