Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Hey I need help with this program there are 4 diff files in this program a

Hey I need help with this program there are 4 diff files in this program a

Computer Science

Hey I need help with this program there are 4 diff files in this program a. Driver.cppb.Timer.cppc.Timer.hd.Song.h IMPORTANT!!! You are sorting the entire song OBJECT, not just the song title.Driver.cpp is partially provided for you. This is the file that contains the main function. You will be adding all the necessary programmer-defined functions to Driver.cpp to accomplish the sorting algorithms. You should not have to write or modify code in any of the other given files!!

 

The Song class (Song.h) is provided for you. A Song object has a song title, artist, and length of song (integer). After the sorting algorithm has happened, the song objects should be sorted in increasing order (ascending order) by song title.

 

The Timer class (Timer.h & Timer.cpp) is provided for you. This is the class that is used in the Driver.cpp file to time the algorithm

 

 

 

//Driver.cpp Starts

 

#include "Song.h"

#include "Timer.h"

#include <iostream>

#include <fstream>

using namespace std;

 

//LOOK!!  ENTER YOUR FUNCTION PROTOTYPES HERE

 

 

int main()

{

    Song *mySongArray;

    mySongArray = new Song[150000];

    int numSongs = 0;

    float length;

    string temp;

    

    ofstream outFile;

    ifstream inFile;

 

    time_t start, end;

    char filename[50];

    cout << "\n\nWhat is the name of the file with songs? (example.txt)\n";

    cin >> filename;

    inFile.open(filename);

    

    if(!inFile)

    {

        cout << "\n\nSorry, I can't open the file songs.txt\n\n";

        exit(1);

    }

    

    while(getline(inFile, temp) && numSongs != 150000)

    {

        mySongArray[numSongs].setTitle(temp);

        getline(inFile, temp);

        mySongArray[numSongs].setArtist(temp);

        inFile >> length;

        inFile.ignore();

        mySongArray[numSongs].setLength(length);

        numSongs++;

    }

    cout << "\n\nYou have created " << numSongs << " Song objects.\n\n";

    

    

    

    //sort the songs using insertion sort and print them out to the text file sortFileInsertion.txt

    start = getTime(); //Starts timer.   

    

    //LOOK!!!!  CALL THE INSERTION SORT ALGORITHM HERE

    

    

    end = getTime(); //Ends timer.

    outFile.open("sortFileInsertion.txt");

    cout << "\nInsertion sort: " << totalTime(start, end) << " seconds\n\n";

    for(int x=0; x<numSongs; x++)

    {

        outFile << mySongArray[x];

    }

    outFile.close();

    

    

    

    //sort the songs in reverse order using bubble sort & print them out to the text file sortFileReverseBubble.txt

    start = getTime(); //Starts timer. 

    

    //LOOK!!!!  CALL THE REVERSE BUBBLE SORT ALGORITHM HERE

    

    

    end = getTime(); //Ends timer.

    outFile.open("sortFileReverseBubble.txt");

    cout << "\nReverse bubble sort: " << totalTime(start, end) << " seconds\n\n";

    for(int x=0; x<numSongs; x++)

    {

        outFile << mySongArray[x];

    }

    outFile.close();

    

    

    

    //sort the songs with quick sort & print them out to sortFileQuick.txt

    start = getTime(); //Starts timer. 

    

    //LOOK!!!!  CALL THE QUICKSORT ALGORITHM HERE

    

    

    end = getTime(); //Ends timer.

    cout << "\nQuicksort: " << totalTime(start, end) << " seconds\n\n";

    outFile.open("sortFileQuick.txt");

    for(int x=0; x<numSongs; x++)

    {

        outFile << mySongArray[x];

    }

    outFile.close();

    

    

    delete [] mySongArray;

    return 0;

}

 

//LOOK!  WRITE YOUR INSERTION SORT FUNCTION HERE

 

 

 

//LOOK!  WRITE YOUR REVERSE BUBBLE SORT FUNCTION HERE

 

 

 

//LOOK!  WRITE YOUR RECURSIVE QUICK SORT FUNCTION HERE

 

 

 

//LOOK!  WRITE YOUR PARTITION FUNCTION HERE

//Driver.cpp Ends

//Song.h Starts

/////////////////////////////

// Song class

/////////////////////////////

#ifndef SONG_H

#define SONG_H

 

#include <iostream>

#include <string>

using namespace std;

 

class Song

{

 

    private:

        string title;

        string artist;

        float length;       

 

    public:

        Song() 

        {

        }

    

        Song(string t, string a, float len ) 

        {

            title = t;

            artist = a;

            length = len;

        }

 

        //***********************ACCESSOR FUNCTIONS***************************

        string getTitle() const

        {

            return title;

        }

        string getArtist() const

        {

            return artist;

        }

        float getLength() const

        {

            return length;

        }

        

        //***********************MUTATOR FUNCTIONS***************************

        void setTitle(string t)

        {

            title = t;

        }

        void setArtist(string a)

        {

            artist = a;

        }

        void setLength(float len)

        {

            length = len;

        }

        

        //***********************OVERLOADED OPERATORS***************************

        

        friend ostream &operator << (ostream &strm, Song &s)

        {

            strm << "Song Title: " << s.title << "\nArtist: " << s.artist << "\nSong Length: " << s.length << endl << endl;

            return strm;

        }

};

 

#endif

//Song.h ends

 

//Timer.cpp starts

#include "Timer.h"

 

using namespace std;

 

time_t getTime()

{

    return time(NULL);

}

 

double totalTime (time_t start, time_t end)

{

    return difftime (end, start);

}

//Timer.cpp ends

 

 

//Timer.h starts

 

/*

    Filename:  Timer.h

    Author:  Dr. Brown, modified by April Crockett

    Date:  3/14/2018

    Purpose:  provides function to get the current time and get the total time given an

        end and start time.

*/

#include <ctime>

#include <cmath>

#include <cstdlib>

 

/*

    Pre: None

    Post: Returns the current system time

*/

time_t getTime();

/*

    Pre: start and end are variables of type time_t containing 2 different system times, start is before end

    Post: Will return the number of seconds separating two times

*/

double totalTime (time_t start, time_t end);

//Timer.h ends

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE