Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ PROGRAM THAT DOES THE FOLLOWING: Problem You Need to Solve for This Lab: You

ID: 3601724 • Letter: C

Question

C++ PROGRAM THAT DOES THE FOLLOWING:

Problem You Need to Solve for This Lab:

You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should save the data back to the same data file when the program exits.

What Your Program Should Do:

Write an interactive text based menu interface (using a loop) that will allow the user to

Enter information for a new song

Display information for all the songs in the database with index for each song

Remove a song by index

Search for songs by a certain artist

Search for songs by a certain album

Quit

For each song, you need to keep track of:

title

artist

duration

album

Allow the program to keep looping until user wants to quit. When the program starts, it should load the tasks from external file ("songs.txt") into memory. When user enters information about the new song, the program needs to read them in, save them in memory and eventually write them to the external data file ("songs.txt"). The file format could look like:

The ';' is used as a delimiter or field separator. Each record ends with a new line character.

Some Implementation Requirements:

Write at least four functions WITH arguments for this assignment.

Use struct named Song to model each song

Use array of structs to model the collection of songs.

Hint: In this assignment, some data fields may have multiple words in it. Therefore,

you now SHOULD read using the 3 argument version of get.

Watch out. When using the 3 argument version of get you need to make sure to

remove the delimiter or newline. Therefore, anytime you read (even a confirmation

message), make sure to eat the newline using cin.ignore(...)!

Make sure to have a delimiter written between each item in the file – like a newline.

This will be important when you read the information back from the file.

For submission, your data file should contain a sufficient set of test data. It should have test cases for same artist with multiple songs and same album with multiple songs in it.

Do-Not List:

No Global Variables (you can have global constants)

Do not use Classes or Linked Lists

You must use cstring and char arrays.

No use of the stdio library (use iostream and fstream)

Instead of the string class, you will be using arrays of characters and the cstring library

No STL containers such as vector. You must implement your own array for this class.

Explanation / Answer

CODE

#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <fstream>

#include <cstdlib>

Using namespace std;

nt option;
int menu
int counter = 0;
Song collection[200];

Struct Song

{

String title,

           artist,

           album;

double duration;

public:

Song(); //default constructor
Song(string aTitle, string anArtist, string anAlbum, double aDuration);

string getTitle()const;
string getArtist()const;
string getAlbum()const;

string getDuration()const;
void setTitle(string newTitle);
void setArtist(string newArtist);
void setAlbum(string newAlbum);
void setDuration(double newDuration);
string toDisplayString() const;

void AddNewsong();
void Remove(int counter);
void Display();

void SearchbyArt(string anArtist);

void SearchbyAlb(string anAlbum);
void Exit();

private:

string title;
string artist;
string album;

double duration;

};

void main()

{

cout<<"1)Enter information of New Song"<<endl;

cout<<"2)display information of all songs with index"<<endl;

cout<<"3)Remove a song by index"<<endl;    

cout<<"4)Search a Song by certain artist"<<endl;

cout<<"5)Search a Song by certain album "<<endl;

cout<<"6)Exit Program"<<endl

cin >> option;

switch (option) {
case 1:
cout << " Add a new songs information" << endl;
void AddNewsong ();
counter++;
break;
case 2:
cout << " Remove a song by particular index" << endl;
void Remove(int counter);
break;
case 3:
cout << " Display a all songs" << endl;
void Display();
break;

case 4: “ search a song by certain Artist”<<endl;

void SearchbyArt(string artist);

break;

case 5: “ search a song by certain Album”<<endl;

void SearchbyAlb(string album);

break;
case 6:
cout<< " Quit" << endl;
void Exit();
break;
default:
cout << " Input a value between 1-6" << endl;
return menu();

}

void AddNewsong()
{

cout << " Enter song title:" << endl;
getline(cin, title);
collection[counter].setTitle(title);


cout << " Enter song artist:" << endl;
getline(cin, artist);
collection[counter].setArtist(artist);

cout << " Enter song album:" << endl;
getline(cin, album);
collection[counter].setAlbum(album);

cout<< “ enter duration of song:”<<endl;

getLine(cin,duration);

collection[counter].setDuration(duration);

return menu();
}

void Remove(int counter);
{
cout << " Enter index of song you want to delete" << endl;
getline(cin, counter);
collection[counter].remove();

return menu();
}

void DisplayallSongs(int counter);
{
int i;
Song list;

cout << " Here are the songs in your collection: "<< endl;

for(i = 0; i <collection.length(); i++)
{
list = collection[i];

cout << "Title:" << list.getTitle() << endl;
cout << "Artist:" << list.getArtist()<< endl;
cout << "Album:" << cout << list.getAlbum()<< endl;
cout<<”duration:”<<cout<<list.getDuration()<<endl;
return menu();
}
void SearchbyArt(string artist)

{

cout<<” please enter the artist name:”<<endl;

getLine(cin,artist);

for(i = 0; i <collection.length(); i++)

{

if(collection[i].getArtist() == artist)

{

cout<<”the song by the artist is:”<<endl;

cout<<collection[i].getTitle();

}

}

}

void SearchbyAlb(string album)

{

cout<<” please enter the album name:”<<endl;

getLine(cin,album);

for(i = 0; i <collection.length(); i++)

{

if(collection[i].getAlbum() == album)

cout<<”the song of the album is:”<<endl;

cout<<collection[i].getTitle();

}

}

void Exit()
{

}


Song:: Song()
{
title= " ";
artist = " ";
album = " ";
}

Song::Song(string aTitle, string anArtist, string anAlbum,double aDuration)
{

title = aTitle; //Assing parameters
artist = anArtist;
album = anAlbum;

}
string Song::getTitle() const
{
return title;
}

void Song:: setTitle(string newTitle)
{
title= newTitle;
}

string Song::getArtist() const
{
return artist;
}

void Song:: setArtist(string newArtist)
{
artist=newArtist;
}

string Song::getAlbum() const
{
return album;
}
void Song::setAlbum(string newAlbum)
{
album= newAlbum;
}
double Song::getDuration() const

{

Return duration;

}

Void Song::setDuration(double newduration)

{

Duration =newDuration;

}
string Song::toDisplayString() const
{
string view = " Title: " + title;
view += " Author: " + artist;
view += " Album: " + album;

View+=” Duration:” +duration+ " ";
return view;
}

Note: to output it to Songs.txt file we can use:

Ofstream fout(“songs.txt”);

for(int i=0;i<collection.length();i++)

{

fout<<collection[i];

}

IF ANY QUERIES REGARDING CODE AND EXECUTION PLEASE GET BACK TO ME
THANK YOU

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote