Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The task is to write Song.cpp to complete the implementation of the Song class, as defined in the provided header file, Song.h, and then to

The task is to write Song.cpp to complete the implementation of the Song class, as defined in the provided header file, Song.h, and then to complete a program (called sales) that makes use of the class. As in Project 1, an input data file will be provided containing the song name and other information in the same format as in Program 1:

Artist Song_Title Year Sales Medium

As before, the program (sales) will use this information to compute the gross revenue and the profit generated by each member using the same information as before. Again, the cost to produce a song on physical media is taken to be 75 cents while the cost for a digitally release song is 25 cents. The sale prices are $1.50 for the physical media and 99 cents for downloads. The completed sales.cpp program will perform the following tasks:

1) Prompt for the data file name. Read it, storing the information in the array of Song classes, one instance per Song. This should all be done in the readDatafile() function.

2) Output the list of songs information. This should be done using the outputList() function prototyped in sales.cpp.

3) Sort the list alphabetically by the artist name (not the song name) using the sortAscend(). Output the list again.

4) Sort the list by profit, largest first, using the sortDescend() as in Project 1. Output the list again.

5) Test the += operator on the first Song in the list. Output that Songs new information.

Note: Do NOT make any changes to Song.h it is not necessary!

In sales.cpp, complete the functions that are prototyped and invoke them as described above to reproduce the output seen in the provided executables.

Note: You do NOT need to add any more functions or variables to sales.cpp.

In Song.cpp complete the following methods:

numItemsSold - computes the total number of items sold by the student

getGross - computes the gross revenue generated by the student

getProfit - computes the gross profit generated by the student Note: call getGross to compute the gross revenue because it is NOT stored in the class

operator> - compares based on the profit again, you should use methods where defined, call getProfit!

operator< - compares based on the artist (not song) name, i.e. an alphabetical comparison

operator+= - +=, adds to the sales number (note this value is a float)

operator>> o stream output print out the Songs information, refer to the executable (proj2) for formatting

Song.h-----------

#ifndef SONG_H #define SONG_H

#include using namespace std;

// struct definition for a child object class Song { public:

// constructor Song(string n="", string a="", int y=0, float s=0, int m=0);

// Mutators (modifiers) void setName(string n) { name= n; } void setArtist(string v) { artist= v; } void setYear(int v) { year= v; } void setSales(float v) { sales= v; } void setMedium(int v) { medID= v; }

// inspectors (accessors) string getName() const { return name; } string getArtist() const { return artist; } string getMedium() const { return mediumTypes[medID]; } int getYear() const { return year; } float getSales() const { return sales; }

// methods for computing revenue and profit float getGross() const; float getProfit() const;

// overloads // greater than - compares total sales bool operator>(const Song &) const; // greater than // less than - compares artist (not song!) names bool operator<(const Song &) const; // less than // += add more sales Song &operator+=(float); // add some sales

private: string name; // song name string artist; // artist name int year; // release year float sales; // copies sold int medID ; // medium ID

// static members //static string mediumName(int m) { return mediumTypes[m]; } static const string mediumTypes[]; // medium types static const float mediumCost[]; // cost for medium static const float mediumPrice[]; // price for medium };

// overload of external stream operators ostream &operator<<(ostream &, const Song &); istream &operator>>(istream &, Song &);

#endif

//Song.h

----------------

sales.cpp

-------------------

#include #include #include using namespace std;

#include "Song.h"

// read the data file, store in arrays int readDatafile(Song[], int); void outputList(Song[], int);

void sortAscend(/* ... */); void sortDescend(/* ... */); void swap(/* ... */);

main() { static int arraysize= 10; // size of Song array int numS=0; // the number of students read Song slist[arraysize];

} //sales.cpp

----------------

----------------

Song.cpp

#include #include using namespace std;

#include "Song.h"

const string Song::mediumTypes[]= { "physical", "digital" }; // medium types

// constructor Song::Song(string n, string a, int y, float s, int m) { name= n; artist=a; year= y; sales= s; medID= (m >= 0 && m <= 1) ? m : 0; // default to "physical" }

// istream operator overload istream &operator>>(istream &input, Song &song) {

string a; string n; int y; float s; int m;

input >> a >> n >> y >> s >> m; song.setArtist(a); song.setName(n); song.setYear(y); song.setSales(s); song.setMedium(m);

return input; // enables cascading }

-------------------

data file- 0 is physical 1 is digital, sales total individual copies

Bing_Crosby White_Christmas 1942 50 0 Elton_John Candle_in_the_Wind 1997 33 0 Mungo_Jerry In_the_Summertime 1970 30 0 Bing_Crosby Silent_Night 1935 30 0 Bill_Haley Rock_Around_the_Clock 1954 25 0 Ed_Sheeran Shape_of_You 2017 41.5 1 Luis_Fonsi Despacito 2017 36.1 1 Kesha TiK_ToK 2009 25.2 1 Ed_Sheeran Perfect 2017 21.4 1 Wiz_Khalifa See_You_Again 2015 20.9 1 Chainsmokers Closer 2016 20.7 1 Bruno_Mars Uptown_Funk 2014 20 1

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

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions

Question

=+(16.32) 81(w) for w A and 0 Answered: 1 week ago

Answered: 1 week ago