Jump to content

Help me with my project in C++

Tai Tran

Hi. I'm working on this project but I'm very new to coding so I'm having a lot of difficulties. I copy down below the project description with my code and I hope someone could help me finishing this by modifying my code to satisfy the requirement. Thank you in advance. And this is due pretty soon so I hope someone will be able to help me ASAP. ^_^

(I'm studying C++ using Visual Studio and I believe these are the basics in C++. However, I'm new so I'm trying to get used to it)


Goals for This Project:
 Break tasks down into functions
 Master pass by reference or pass by value
 Use character arrays and <cstring>
 Use struct to model composite data type
 Use array of objects to model a collection
 File input/output

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:

Stereo Hearts;Gym Class Heroes;3;34;The Papercut Chronicles II Counting Stars;OneRepulic;4;17;Native

The ';' is used as a delimiter or field separator. Each record ends with a new line character. Also the above sample data came from my teen son, not a reflection of your instructor’s music taste 
Some Implementation Requirements:
1. Write at least four functions WITH arguments for this assignment.
2. Use struct named Song to model each song
3. Use array of structs to model the collection of songs.
4. 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.
5. 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(...)!
6. 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.
7. 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.

 

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
int counter = 0;
Song collection[200];
 
struct Song
{
    string title, artist, album;
    double duration;
    Song();
    Song(string aTitle, string anArtist, string anAlbum, double aDuration);
    string getTitle();
    string getArtist();
    string getAlbum();
    string getDuration();
 
    void setTitle(string newTitle);
    void setArtist(string newArtist);
    void setAlbum(string newAlbum);
    void setDuration(double newDuration);
    string toDisplayString();
};
 
void AddNewSong();
void Display();
void Remove(int counter);
void SearchbyArt(string anArtist);
void SearchbyAlb(string anAlbum);
void Exit();
 
void main()
{
    int option;
    int menu;
 
    string title;
    string artist;
    string album;
    double duration;
 
    cout << "1)Enter information of the 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 << "\nEnter information of the new song" << endl;
        void AddNewSong();
        break;
 
        case 2:
        cout << "\nDisplay information of all songs with index" << endl;
        void Display();
        break;
 
        case 3:
        cout << "\nRemove a song by index" << endl;
        void Remove(int counter);
        break;
 
        case 4:
        cout << "\n search a song by certain Artist" << endl;
        void SearchbyArt(string artist);
        break;
 
        case 5:
        cout << "\n search a song by certain Album" << endl;
        void SearchbyAlb(string album);
        break;
 
        case 6:
        cout << "\nExit Program" << endl;
        void Exit();
        break;
 
        default:
        cout << "\nPlease input a value between 1-6" << endl;
        return menu();
    }
}
 
void AddNewSong();
{
    cout << "\nEnter song title:" << endl;
    getline(cin, title);
    collection[counter].setTitle(title);
 
    cout << "\nEnter song artist:" << endl;
    getline(cin, artist);
    collection[counter].setArtist(artist);
 
    cout << "\nEnter song album:" << endl;
    getline(cin, album);
    collection[counter].setAlbum(album);
 
    cout << "\nEnter duration of the song : " << endl;
    getLine(cin, duration);
    collection[counter].setDuration(duration);
 
    return menu();
}
 
void Display();
{
    int i;
    Song list;
    cout << "\nHere are the songs in your collection:\n\n" << endl;
    for (i = 0; i < collection.length(); i++)
    {
         list = collection;
 
         cout << "Title:" << list.getTitle() << endl;
         cout << "Artist:" << list.getArtist() << endl;
         cout << "Album:" << list.getAlbum() << endl;
         cout << "Duration:" << list.getDuration() << endl;
 
         return menu();
    }
}
 
void Remove(int counter);
{
    cout << "\nEnter index of song you want to delete" << endl;
    getline(cin, counter);
    collection[counter].remove();
 
    return menu();
}
 
void SearchbyArt(string artist)
{
    int i;
    cout << "\nPlease enter the artist name : " << endl;
    getline(cin, artist);
    for (i = 0; i < collection.length(); i++)
    {
        if (collection.getArtist() == artist)
        {
             cout << "\nPlease enter the song name : " << endl;
             cout << collection.getTitle();
         }
    }
}
 
void SearchbyAlb(string album)
{
    int i;
    cout << "\nPlease enter the album name : " << endl;
    getline(cin, album);
    for (i = 0; i <collection.length(); i++)
    {
        if (collection.getAlbum() == album)
        {
            cout << "the song of the album is : " << endl;
            cout << collection.getTitle();
        }
    }
}
 
void Exit()
{
    exit(0);
}
 
Song::Song(string aTitle, string anArtist, string anAlbum, double aDuration)
{
    title = aTitle; 
    artist = anArtist;
    album = anAlbum;
}
 
string Song::getTitle() 
{
    return title;
}
 
void Song::setTitle(string newTitle)
{
    title = newTitle;
}
 
string Song::getArtist()
{
    return artist;
}
 
void Song::setArtist(string newArtist)
{
    artist = newArtist;
}
 
string Song::getAlbum() 
{
    return album;
}
 
void Song::setAlbum(string newAlbum)
{
    album = newAlbum;
}
 
double Song::getDuration()
{
    Return duration;
}
 
void Song::setDuration(double newduration)
{
    Duration = newDuration;
}
 
string Song::toDisplayString() 
{
    string view = "\nTitle: " + title;
    view += "\nAuthor: " + artist;
    view += "\nAlbum: " + album;
    view += "\nDuration:" + duration;
    return view;
}
 
//to output it to Songs.txt file we can use :
ofstream fout(“songs.txt”)
{
    for (int i = 0; i<collection.length(); i++)
    {
        fout << collection;
    }
}
Link to comment
Share on other sites

Link to post
Share on other sites

If you fix your formatting it'd be easier to help you. Use the stock font and font size (Arial and 14) and then put your code in the code box, which you can find on the editor - looks like <>

Link to comment
Share on other sites

Link to post
Share on other sites

If you fix your formatting it'd be easier to help you. Use the stock font and font size (Arial and 14) and then put your code in the code box, which you can find on the editor - looks like <>

What is the code type for C++ ? 

Link to comment
Share on other sites

Link to post
Share on other sites

What is the code type for C++ ? 

 

You don't have to put a type. It's just easier to read in a code box.

Link to comment
Share on other sites

Link to post
Share on other sites

You don't have to put a type. It's just easier to read in a code box.

I did my best to edit it. Hope its easier for you to read and hope you can help me 

Link to comment
Share on other sites

Link to post
Share on other sites

help me finishing this by modifying my code to satisfy the requirement

 

Come on now, it's your homework, not ours. We can help but we're not here to finish it for you. How about you start by telling us what requirement you're currently working on and what about it is giving you trouble.

 

Also, please use code tags. You can add them in by using the <> icon above where you type your posts, or with your text like so

[code]Code goes here[/code]
Link to comment
Share on other sites

Link to post
Share on other sites

You should use " class " of cpp that will make the program better and to load data from " song.txt " you have to use fstream. And to continue your looping you can use " do while loop ". I can complete your project but i don't have time this are some tips.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×