My program has a vector of albums(a class). Class Album can set and get the name of the album and artist.
I want to have two vectors of chars, one is AlbumNameVector(ANV) and the other is Artist Name Vector(ArtV).
is the following legal?
MY PROGRAM IS NOT WOKRING, FOR SOME REASON IT SKIPS OVER ALBUM NUMBER 0, that is my biggest problem.Code:while(EnteringData) { AV.push_back(new Album);//adds a new Album to the AlbumVector ANV.push_back(new char[50]); //adds a new 50 byte character array to the AlbumNameVector ArtV.push_back(new char[50]); //adds a new 50 byte character array to the ArtistVector }
I have decided to include what i have for the full source in case you wanted to look
[code]
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <vector>
#include <string.h>
#include <fstream>
using namespace std;
class Album {
public:
void SetAlbumName(char *name) {strncpy(AlbumName, name, 50);}
void SetArtistName(char *name) {strncpy(ArtistName, name, 50);}
void SetSongName(char *name) {strncpy(SongName, name, 50);}
char* GetAlbumName() {return AlbumName;}
char* GetArtistName() {return ArtistName;}
char* GetSongList() {return SongName;}
protected:
char AlbumName[50];
char ArtistName[50];
char SongName[50];
};
int main() {
int Answer;
int Index = 0;
bool EnteringData;
typedef vector<Album*> AlbumVector;
typedef vector<char*> AlbumNameVector;
typedef vector<char*> ArtistVector;
typedef vector<char*> SongListVector;
AlbumVector AV;
AlbumNameVector ANV;
ArtistVector ArtV;
SongListVector SLV;
cout << "Would you like the enter an album to the database? " << endl; //asks user if he/she would like to enter information
cout << "1) Yes " << endl << "2) No " << endl;
cin >> Answer;
if(Answer == 1)
EnteringData = true;
else
EnteringData = false;
while(EnteringData) {
AV.push_back(new Album); //adds a new Album to the AlbumVector
ANV.push_back(new char[50]); //adds a new 50 byte character array to the AlbumNameVector
ArtV.push_back(new char[50]); //adds a new 50 byte character array to the ArtistVector
SLV.push_back(new char[50]); //adds a new 50 byte character array to the SongListVector
cout << "Enter the name of album #" << Index<< endl; //asks user the name of the album
cin.getline(ANV[Index],50); //Inputs the Album name
AV[Index]->SetAlbumName(ANV[Index]); //Sets the name of the Album[Index] (uses class methods)
Index++;
}
cout << "End of program" << endl;
getch();
system("CLS");
return 0;
}
//1) store album name, artist name, and list of songs in a database
//create class album, derive artist name from class album
//derive song list from class album
//album name, artist name, song list
//2) be able to read the album name, artist name, and list of songs from database
//3) be able to search the database based on user input