Question: Posting this question again because the last 'answer' was literally just a copy past of the code that I presented as already having. I'm looking

Posting this question again because the last 'answer' was literally just a copy past of the code that I presented as already having.

I'm looking to add the following to my code:

Now that you have designed and implemented the class stockType to implement a stock object in a program, it is time to create a list of stock objects.

Let us call the class to implement a list of stock objects stockListType. The class stockListType must be derived from the class listType, which you designed and implemented in the previous exercise. However, the class stockListType is a very specific class, designed to create a list of stock objects. Therefore, the class stockListType is no longer a template. Add and/or overwrite the operations of the class listType to implement the necessary operations on a stock list. The following statement derives the class stockListType from the class listType. class stockListType:public listType { member list }; The member variables to hold the list elements, the length of the list and the max listSize were declared as protected in the class listType. Therefore, these members can be directly accessed in the class stockListType. Because the company also requires you to produce the list ordered by the percent gain/loss, you need to sort the stock list by this component. However, you are not to physically sort the list by the component percent gain/loss. Instead, you will provide a logical ordering with respect to this component. To do so, add a member variable, an array, to hold the indices of the stock list ordered by the component percent gain/loss. Call this array sortIndicesGainLoss. When printing the list ordered by the component percent gain/loss, use the array sortIndicesGainLoss to print the list. The elements of the array sortIndicesGainLoss will tell which component of the stock list to print next.

This is what I have so far:

#include #include #include #include using namespace std; class stockType { public: friend ostream& operator<<(ostream& osObject, stockType& stockOut); friend istream& operator >> (istream& is, stockType& stockIn); //Overload relational operators. bool operator==(const stockType& otherStock) const { return (symbol == otherStock.symbol); } bool operator!=(const stockType& otherStock) const { return (symbol != otherStock.symbol); } bool operator<(const stockType& otherStock) const { return (symbol < otherStock.symbol); } bool operator<=(const stockType& otherStock) const { return ((symbol < otherStock.symbol) || (symbol == otherStock.symbol)); } bool operator>(const stockType& otherStock) const { return (symbol > otherStock.symbol); } bool operator>=(const stockType& otherStock) const { return ((symbol > otherStock.symbol) || (symbol == otherStock.symbol)); } //Set stock information. void setStock(string s, double oP, double cP, double tH, double tL, double pC, int v) { symbol = s; openingPrice = oP; closingPrice = cP; todayHigh = tH; todayLow = tL; prevClose = pC; volume = v; } //Output all information for the stock. void print() { cout << "Stock symbol: " << symbol << endl; cout << "Opening price: " << openingPrice << endl; cout << "Closing price: " << closingPrice << endl; cout << "Today's high: " << todayHigh << endl; cout << "Today's low: " << todayLow << endl; cout << "Previous close: " << prevClose << endl; cout << "Percent gain: " << calculateGain(closingPrice, prevClose) << "%" << endl; cout << "Volume: " << volume << endl; } //Output prices for the stock. void showPrices() { cout << "Opening price: " << openingPrice << endl; cout << "Closing price: " << closingPrice << endl; cout << "Today's high: " << todayHigh << endl; cout << "Today's low: " << todayLow << endl; cout << "Previous close: " << prevClose << endl; } //Calculate gain or loss. double calculateGain(double current, double previous) { return (current - previous) / previous * 100; } stockType() { symbol = "N/A"; openingPrice = 0.00; closingPrice = 0.00; todayHigh = 0.00; todayLow = 0.00; prevClose = 0.00; volume = 0; } stockType(string s, double oP, double cP, double tH, double tL, double pC, int v) { symbol = s; openingPrice = oP; closingPrice = cP; todayHigh = tH; todayLow = tL; prevClose = pC; volume = v; } private: string symbol; double openingPrice; double closingPrice; double todayHigh; double todayLow; double prevClose; int volume; }; //Overload insertion and extraction operators. ostream& operator<<(ostream& osObject, stockType& stockOut) { osObject << setprecision(2) << fixed << stockOut.symbol << " " << stockOut.openingPrice << " " << stockOut.closingPrice << " " << stockOut.todayHigh << " " << stockOut.todayLow << " " << stockOut.prevClose << " " << stockOut.calculateGain(stockOut.closingPrice, stockOut.prevClose) << "% " << stockOut.volume; return osObject; } istream& operator >> (istream& is, stockType& stockIn) { is >> stockIn.symbol >> stockIn.openingPrice >> stockIn.closingPrice >> stockIn.todayHigh >> stockIn.todayLow >> stockIn.prevClose >> stockIn.volume; return is; } int main() { system("pause"); } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!