I\'m a C++ Programmer beginner. I had started writing this project, however, I h
ID: 3623217 • Letter: I
Question
I'm a C++ Programmer beginner. I had started writing this project, however, I have stuck some points such as Overloaded function, writing songlist. Please can someone help me get this project?Project:
Write a C++ class called Song to represent a song in a music collection. The data members of the Song class are strings representing the song title, artist’s name, and the album where the song can be found. These instance variables for the class are to have private access modifiers so you will need to write the appropriate functions to allow a client to access and modify the data values. In addition, you are to write an overloaded equality (==) function; two songs are equal if they have the same title, artist, and album, regardless of the case of the letters. In addition, this class is going to be used in data structures throughout the semester that will be sorted, so it is to implement an overloaded greater-than (>) function.
A second file is to be written called SongList that contains a main function and separate function to display a menu of options for the user. The menu will contain options that allow the user to,
1. Add a song.
2. Remove a song.
3. Display all the songs in the list.
4. Quit.
The menu must list these options in the exact same order, using these numbers (1-4). Failure to follow this specification will reduce your project grade by 10%.
For this first project, you are to store the Song objects in an array with a size of 10, the maximum number of songs for this project.
Some additional project information:
?Songs are to be compared lexicographically (first by album and then by song) when implementing the overloaded greater-than function. For example, The Decemberists' song "Sons & Daughters" on The Crane Wife album is less than their song "January Hymn" from The King is Dead. Yet, "June Hymn" is greater than "January Hymn" because both songs appear on the The King is Dead album.
?When you prompt the user to enter data for a new song, the order of the prompts needs to be,
1.song title
2.artist name
3.album
?The format of the output when the user selects menu option 3. (Display all the songs in the list) should look like this:
Title: Tiger Mountain Peasant Song
Artist: Fleet Foxes
Album: Fleet Foxes
Title: White Winter Hymnal
Artist: Fleet Foxes
Album: Fleet Foxes
Title: Your Protector
Artist: Fleet Foxes
Album: Fleet Foxes
?Keep in mind that the order that the songs are displayed should be the same order in which the songs were entered - even if a song has been removed from the beginning of the list. (In other words, if a song is removed, you must shift the songs up to "close the gap" in the array; new songs are always added to the end of the list of songs.).
Explanation / Answer
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
class Song
{
public:
//Song();
//Song(string title, string artist, string album);
string getTitle();
string getArtist();
string getAlbum();
void setTitle(string title);
void setArtist(string artist);
void setAlbum(string album);
private:
string ttl;
string art;
string alb;
};
int option;
int menu();
int counter = 0;
Song collection[10];
/**This initilizes a fnction that prints a header.*/
void printHeading(int h)
{
printf(" Project 0%d", h);
}
/**Functions for the program*/
void Addsong(int counter)
{
string ttl;
string art;
string alb;
cout << " Enter song title:" << endl;
getline(cin, ttl); getline(cin, ttl);
collection[counter].setTitle(ttl);
cout << " Enter song artist:" << endl;
getline(cin, art);
collection[counter].setArtist(art);
cout << " Enter song album:" << endl;
getline(cin, alb);
collection[counter].setAlbum(alb);
menu();
}
/**Song::Song(string title, string artist, string album)
{
ttl = title;
art = artist;
alb = album;
}*/
void Song::setTitle(string title)
{
ttl = title;
}
void Song::setArtist(string artist)
{
art = artist;
}
void Song::setAlbum(string album)
{
alb = album;
}
void Remove()
{
cout << " Pick which song you want to remove:" << endl;
menu();
}
void Display()
{
/**
int loco;
Song list;
cout << " Here are the songs in your collection: " << endl;
for(loco = 0; loco < 10; loco++);
{
list = collection[loco];
if(loco + 1 < 10)
{
cout << " " << loco + 1 << " | ";
}
else
cout << loco + 1 << " | ";
}
cout << list.getTitle() <<
cout << list.getArtist() <<
cout << list.getAlbum() <<
cout << endl;
*/
cout << " Here are the songs in your collection:" << endl;
cout << "Title:" << endl;
cout << "Artist:" << endl;
cout << "Album:" << endl;
menu();
}
void Exit()
{
cout << " Bye! " << endl;
}
int main()
{
/**Prints the heading*/
printHeading(1);
menu();
}
int menu()
{
/** Displaying the menu */
cout << " What do you want to do? " << endl;
cout << " 1. Add a song" << endl;
cout << " 2. Remove a song" << endl;
cout << " 3. Display all the songs in the list" << endl;
cout << " 4. Quit " << endl;
/** Getting input */
cin >> option;
/** Selecting case and calling functions associated */
switch (option) {
case 1:
cout << " Add a song" << endl;
Addsong(counter);
counter++;
break;
case 2:
cout << " Remove a song" << endl;
Remove();
break;
case 3:
cout << " Display a song" << endl;
Display();
break;
case 4:
Exit();
break;
default:
cout << " Input a value between 1-4" << endl;
return menu();
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.