Hey guys.

I need to write a program that does the following:
Requirements - The program...
- Shall allow user to enter individual songs with information:
- Shall ask for song name.
- Shall ask for length.
- Shall ask for artist name.
- Shall ask for album name.
- Shall ask for music genre.
- Shall ask for personal star rating.
- Shall ask for song year.
- Shall validate (and if needed reask for) song data:
- Shall validate that length is in seconds and is positive.
- Shall validate that genre is selected from set of known values.
- Shall validate that personal rating is between 1 and 5.
- Shall validate that song year is 1900 or greater.
- Shall allow user to review entire library.
- Shall allow user to delete song from library (and playlist if on it).
- Shall allow user to create, edit, and review playlist:
- Shall allow user to add any song created to playlist.
- Shall allow user to review playlist.
- Shall allow user to delete song from playlist.
- Shall allow user to end program.

Here are the three files I've written so far. But can you tell me:
(a) why this header/implementation file won't compile (it says library and playlist are not right type).
(b) am I doing this the right way?
(c) I think I'm not understanding how to use vectors/classes. Any advice would be great.

Main.

#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <fstream>
#include "songs.h"	
using namespace std;

void Welcome();

int main()
{
	vector <Songs*> library;
	vector <Songs*> playlist;
	
	Welcome();																// Welcome screen.
	
	
	// Main Menu: (S) enter song, (L) review library, (P)review playlist, or (X) print and end program.
		//Check SLPX in while loop.
	// S - Enter Song: Name, length (s), artist name, album name, genre, star rating, year.
		// Check length (s, ><), check genre(1 of 5), check rating(1-5), check year(>1900<2010).
		// Add to playlist? Y or N (Check); Y copy to playlist vector
		// -> Main Menu
	// L - Print library (function) 
		// Ask to delete song from libray (and playligst; search and delete), add song to playlist not on it yet, or go back to Main Menu.
	// P - Print playlist (function)
		// Ask to delete song from playlist, or back to Main Menu
	// X - Print Both (function; no questions; end)

	return 0;
}

void Welcome()
{
	cout << endl;
	cout << "-----------------------------------------" << endl;
	cout << "Name/ID - Gabe Audick #7681539807" << endl;
	cout << "Class/Assignment - CSCI-102 Disccusion 29915: Homework Assignment #1" << endl;
	cout << "-----------------------------------------" << endl;
	cout << "Welcome to myTunes." << endl << endl;
}

Songs Header

#ifndef SONGS_H_
#define SONGS_H_

#include <string>
#include <vector>
using namespace std;

class Songs
{
	private:
		string songName;
		string artistName;
		string albumName;
		string genre;
        int playTime; 
        int year;
		int starRating;		
		char yesOrNo;
	public:

		Songs();
		Songs(string SN, string ArN, string AlN, int PT, int YR, int SR, string GR);
		string getSongName();
		void setSongName(string newSong);
		string getArtistName();
		void setArtistName(string newArtist);
		string getAlbumName();
		void setAlbumName(string newAlbum);
		int getPlayTime();
		void setPlayTime(int newTime);
		int getYear();
		void setYear(int newYear);
		int getStarRating();
		void setStarRating(int newStarRating);
		string getSongGenre();
		void setSongGenre(string newGenre);
		void addSongLibrary(vector<Songs> *library, vector<Songs> *playlist);
};

#endif

Songs Implementation

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include "songs.h"
using namespace std;

Songs::Songs()
{
	this->songName = " ";
	this->artistName = " ";
	this->albumName = " ";
	this->playTime = 1; 
	this->year = 1901;
	this->starRating = 1;
	this->genre = "Other";
}

Songs::Songs(string SN, string ArN, string AlN, int PT, int YR, int SR, string GR)
{
	this->songName = SN;
	this->artistName = ArN;
	this->albumName = AlN;
	this->playTime = PT; 
	this->year = YR;
	this->starRating = SR;
	this->genre = GR;
}

string Songs::getSongName()
{
	return songName;
}

void Songs::setSongName(string newSong)
{
	this->songName = newSong;
}

string Songs::getArtistName()
{
	return artistName;
}

void Songs::setArtistName(string newArtist)
{
	this->artistName = newArtist;
}

string Songs::getAlbumName()
{
	return albumName;
}

void Songs::setAlbumName(string newAlbum)
{
	this->albumName = newAlbum;
}

int Songs::getPlayTime()
{
	return playTime;
}

void Songs::setPlayTime(int newTime)
{
	this->playTime = newTime;
}

int Songs::getYear()
{
	return year;
}

void Songs::setYear(int newYear)
{
	this->year = newYear;
}

int Songs::getStarRating()
{
	return starRating;
}

void Songs::setStarRating(int newStarRating)
{
	this->starRating = newStarRating;
}

string Songs::getSongGenre()
{
	return genre;
}

void Songs::setSongGenre(string newGenre)
{
	this->genre = newGenre;
}

void Songs::addSongLibrary(vector<Songs> *library, vector<Songs> *playlist)
{
	cout << "Please enter song name: ";
	getline(cin, songName);
	cout << "Please enter artist name: ";
	getline(cin, artistName);
	cout << "Please enter album name: ";
	getline(cin, albumName);
	while(true)
	{
		cout << "Please enter length of song in seconds: ";
		cin >> playTime;
		if(!cin.fail() && playTime > 0)
			break;
		else if(cin.fail())
			cout << "Time must be in seconds. Please enter the song's length again: ";
		else if(playTime <= 0)
			cout << "Time must be greater than 0 seconds. Please enter the song's length again: ";		
		cin >> playTime;
	}
	while(true)
	{
		cout << "Please enter the year the song was made: ";
		cin >> year;
		if(!cin.fail() && year < 1900)
			break;
		else if(cin.fail())
			cout << "Year must be in numbers. Please enter the song's year again: ";
		else if(year < 1900)
			cout << "Year must be 1900 or greater. Please enter the song's year again: ";		
		cin >> year;
	}
	while(true)
	{
		cout << "Please enter a star rating for the song (1 to 5 stars): ";
		cin >> starRating;
		if(!cin.fail() && starRating >= 1 && starRating <= 5)
			break;
		else if(cin.fail())
			cout << "Rating can only be the digits 1, 2, 3, 4, or 5. Please enter a new rating for the song: ";
		else if(starRating < 1 || starRating > 5)
			cout << "Rating must be between 1 and 5. Please enter the song's year again: ";		
		cin >> year;
	}
	while(true)
	{
		cout << "Please enter a genre (Rock, Rap, Country, Gospel, or Other) for the song: ";
		cin >> genre;
		if(genre == "Rock" || genre == "Rap" || genre == "Country" || genre == "Gospel" || genre == "Other")
			break;
		else
			cout << "Genre not recognized. Please enter one of the five given genres (Rock, Rap, Country, Gospel, or Other)";		
		cin >> genre;
	}
		
	Songs* newSongInfo = new Songs();
	newSongInfo->setSongName(songName);
	newSongInfo->setArtistName(artistName);
	newSongInfo->setAlbumName(albumName);
	newSongInfo->setPlayTime(playTime);
	newSongInfo->setYear(year);
	newSongInfo->setStarRating(starRating);
	newSongInfo->setSongGenre(genre);	
	library.push_back(newSongInfo);
	
	while(true)
	{
		cout << "Enter y to add the song to you playlist, or n to do nothing: ";
		cin >> yesOrNo;
		if(yesOrNo = 'y')
		{
			playlist.push_back(newSongInfo);
			break;
		}
		else if(yesOrNo == 'n')
			break;
		else
			cout << "Invalid operation. Please enter y to add the song to you playlist, or n to do nothing: ";
		cin >> yesOrNo;
	}	
}

Thank you so much.

line 164 in songs.cpp library->push_back(*newSongInfo);
line 171 in songs.cpp playlist->push_back(*newSongInfo);

You needed to deref library and access member push_back so that needed to be changed into an arrow and since your newSongInfo was a pointer to song and your vectors held songs you needed to dereference that also. Same applies for playlist on both counts.

I didn't look things over very carefully or fully test them out, but I figured I'd give you a head start on bug hunting.

This article has been dead for over six months. Start a new discussion instead.