Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write the code according to the information below, and present the needed code output, make sure that your output matches the given instruction txt

Please write the code according to the information below, and present the needed code output, make sure that your output matches the given instruction txt files, and don't forget to present your full output with the code. Do not copy anyone else's code for this assignment because they are all incorrect, I will not upvote if the code is copied from someone else, or if you don't present your output, everything is given below. Thank You.

image text in transcribed

image text in transcribed

image text in transcribed

Main.cpp

#include #include #include "Song.h" #include #include // max size of the dynamic array const int SIZE = 300; //selection sort to sort according to chart position int sortSongs(Song **, int size);

//print the top ten songs in the sorted array void printTopTen(Song **,int size); //print all the songs in the array void print(Song**,int size);

//returns the actual number of songs read // if more songs than size, then they are ignored.

int populateArray(std::string filename, Song**); //search by title int searchASong(Song** dataArray,int size); //get the song by chart position Song getSong(Song** dataArray, int size, int chartPosition);

int main() { // create a dynamic array of pointers to Song objects Song ** dataArray = new Song*[SIZE]; //populate the array by reading data from the file int size=populateArray("SongsData.txt",dataArray); //print the data Array //print(dataArray,size); // sort the song array using selection sort int sortSteps=sortSongs(dataArray,size); //print the number of steps //print the sorted data Array print(dataArray,size); //print the top ten songs printTopTen(dataArray,size); //search for a song by title

int searchSteps=searchASong(dataArray,size); //print the number of steps } // Requires non negative size // Effects Sorts the Songs dataArray //using selection sortSongs //Modifies dataArray int sortSongs(Song ** dataArray, int size){ //GIVEN CODE int steps=0; Song * minValue= new Song(); int minIndex=0; for (int i=0;i

// Requires valid filename to open file // Effects fills the Songs dataArray // //Modifies dataArray int populateArray(std::string filename, Song** dataArray){ //GIVEN CODE int size=0; std::string line; std::string title; std::string singer; int chartPosition;

try{ std::ifstream input(filename); if (input.fail()) throw new std::string(filename + " File Open Error"); while(!input.eof()){ getline(input,line); std::istringstream inpline(line); std::getline(inpline,title,','); std::getline(inpline,singer,','); inpline>>chartPosition; dataArray[size]= new Song(title,singer,chartPosition); size++;

} } catch(std:: string e){ std::cout0 //E uses the overloaded 0 //Effects Prints top ten songs by calling print data method // if there are less than 10 songs in array then it prints them all otherwise it prints first 10 songs //Modifies nothing void printTopTen(Song** dataArray,int size){ //TODO } //Requires size >0 //Effects Linear Searches for the song based on title //Prompts user for title //Modifies Nothing int searchASong(Song **dataArray, int size){ int steps=0; std::cout

//Requires size >=0 // Effect Searches for song by title using chart position returns index if found otherwise -1 //uses linear search //Modifies nothing

Song getSong(Song** dataArray, int size, int chartPosition){ //GIVEN CODE if (chartPosition

Song.h

#include class Song{ private: std::string title; std::string singer; int chartPosition; public: //default constructor Song(); //custom constructor Song(std::string title,std:: string singer, int chartPosition); // convert object to string std::string toString(); //operator overloading for ostream operator friend std::ostream & operator

Song.cpp

#include "Song.h" //default constructor Song::Song(){ title=""; singer=""; chartPosition=0; } //custom constructor Song::Song(std::string title, std::string singer, int chartPosition){ //TODO } //GIVEN CODE std::string Song::toString(){ return "Title: "+title+ " Singer: "+singer+ " ChartPosition: "+std::to_string(chartPosition); } //GIVEN CODE std::ostream& operatortoString(); return str; } // int Song::getChartPosition(){ return 0;// change this //TODO } //GIVEN CODE //operator getChartPosition(); } //return title std::string Song::getTitle(){

//TODO return "";// change this }

The output txt files are in the URL code below, the code output should match the output exactly as in Output.txt and OutputDouble.txt, don't forget to show your output.

file:///D:/Donloads/Output.txt

file:///D:/Donloads/OutputDouble.txt

file:///D:/Donloads/SongsData.txt

file:///D:/Donloads/SongsDataDouble.txt

\# Write a class called Song in a file called Song.h with three fields: Title (string) Singer (string) Chart Position (int) \# Place these method headers in the Song. h file 1. Getter and setter for each field 2. Other methods 1. Song(); // default constructor 2. Song(std::string title,std:: string singer, int chartPosition); I/ custom constructor 3. std::string toString(); // returns object as a string 4. bool operator

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

=+ (b) Show that the condition is sufficient as well.

Answered: 1 week ago