Microsoft Word - PA4.docx CPSC 2430 Winter 2021 Programming Assignment #4 Due date: Mar 1, XXXXXXXXXX:59pm DO NOT USE any of the STL in your code. SongHeap Implement a min-heap using a dynamic array...

1 answer below »
Please help on my heap hw C++


Microsoft Word - PA4.docx CPSC 2430 Winter 2021 Programming Assignment #4 Due date: Mar 1, 2021 11:59pm DO NOT USE any of the STL in your code. SongHeap Implement a min-heap using a dynamic array implementation. The class should be named SongHeap, and it uses the same dataset as in PA 3 (Billboard Top 100). Write all basic class functions (default and copy constructors, destructor, copy assignment). SongHeap has a data member songList, which is an array of Songs. Set the initial size of songList to 5, and double the size as needed. A Song is similar to a TreeNode in PA 3. The song title acts as a key, and smaller keys have higher priority (ex. “A” before “B”). struct Song{ string title; //used as key string artist; string dates[52]; //filled starting from index 0 int frequency; //should match # of elements in dates }; Heap Functions Implement the following functions: 1. void insert(string title, string artist, string date). You should first check all the songs in songList to see if the song is already in the heap. If so, update the frequency and dates of the Song. Otherwise, create and add a Song to the heap (i.e., songList). The heap should grow as needed. 2. string deleteMin(): deletes the Song with the min key and returns its title. 3. print(): prints all the songs in the heap using the following format – arr[i]: title (See the execution example). 4.printSong(string title): finds and prints all the information about the song. Testing and submission Provide a driver/client program to demonstrate your functions. You can create a SongHeap and add all the songs in top1.csv to the heap, similarly to how you read in the file for PA 3. Test ALL the functions thoroughly in the driver, including all the edge cases. Submit your program using the following command: /home/fac/hkong/submit/cpsc2430/submit_pa4 The SongHeap class should be in two files named songheap.h and songheap.cpp. The driver should be in a file named pa4.cpp. Execution example [PA4]./pa4 Hello! Processing the first 30 lines of top1.csv file. The array is full. Resizing array to 10 elements. The array is full. Resizing array to 20 elements. Printing tree: arr[1] = All I Want For Christmas Is You arr[2] = Blinding Lights arr[3] = Say So arr[4] = Circles arr[5] = Rain On Me arr[6] = The Scotts arr[7] = The Box arr[8] = Stuck With U arr[9] = Savage arr[10] = Toosie Slide arr[11] = Rockstar arr[12] = Trollz Which song do you want to print? Blinding Lights Title: Blinding Lights Artist: The Weeknd Appeared on the Billboard chart 4 times on: 2020-04-11 2020-04-18 2020-05-02 2020-05-09 Which song do you want to print? Testing Testing is not in the heap. Removing the min value. "All I Want For Christmas Is You" has been removed. Printing the updated heap: arr[1] = Blinding Lights arr[2] = Circles arr[3] = Say So arr[4] = Savage arr[5] = Rain On Me arr[6] = The Scotts arr[7] = The Box arr[8] = Stuck With U arr[9] = Trollz arr[10] = Toosie Slide arr[11] = Rockstar Removing the min value. "Blinding Lights" has been removed. Printing the updated heap: arr[1] = Circles arr[2] = Rain On Me arr[3] = Say So arr[4] = Savage arr[5] = Rockstar arr[6] = The Scotts arr[7] = The Box arr[8] = Stuck With U arr[9] = Trollz arr[10] = Toosie Slide This is the end of the execution example. Goodbye!
Answered Same DayMar 01, 2021

Answer To: Microsoft Word - PA4.docx CPSC 2430 Winter 2021 Programming Assignment #4 Due date: Mar 1,...

Sonu answered on Mar 02 2021
148 Votes
a10/out.exe
a10/songheap.cpp
a10/songheap.cpp
#include
#include 
#include 
#include  
#include "songheap.h"
using namespace std;
int main(){
    Heap heap;
    ifstream fin("top.csv");

    string line, word, temp; 
    if(!fin.is_open())
       throw std::runtime_error("Could not open file");

    getline(fin, line);
    while (getline(fin, line)) {  
        stringstream s(line); 
        vector row;
        while (getline(s, word, ',')) {  
            row.push_back(word); 
        }
        heap.insert(row[0],row[1],row[2]);
    }
    fin.close();
    int in;
    cout<<"Enter 1 to print heap, Enter 2 to deleteMin, Enter 3 to find song, Enter 4 to exist"<    cin>>in;
    while(in != 4){
        if(in == 1){
            cout<<"Printing the tree:"<            heap.print();
        }
        else if(in == 2){
            string s = heap.deleteMin();
        }
        else if(in == 3){
            cout<<"Enter song name."<            string s;
            cin>>s;
            heap.printSong(s);
        }
        cout<<"Enter 1 to print heap, Enter 2 to deleteMin, Enter 3 to find song, Enter 4 to exist"<        cin>>in;
    }

}
a10/songheap.h
#include
#include
#include
#include
#include // std::pair
#include // std::runtime_error
#include // std::stringstream
using namespace std;
struct Song{
    string title; //used as key
    string artist;
    string dates[52]; //filled starting from index 0
    int frequency; //should match # of elements in dates
};
bool comp(Song a, Song b){
    return a.title > b.title;
}
class Heap{
    int size;
    int k;
    Song *arr;
    public:
        Heap(){
            size = 5;
            k = 0;
            arr = new Song[5];
        }
        ~Heap(){
            delete [] arr;
        }
        int parent(int i){
    return...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here