Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Posting this question again because the last \'answer\' was literally just a cop

ID: 3805938 • Letter: P

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 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:

Explanation / Answer

#ifndef STOCKTYPE_H
#define STOCKTYPE_H

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

class stockType
{
public:
stockType(string symbol="", double openPrice=0.0, double closePrice=0.0, double highPrice=0.0,
double lowPrevPrice=0.0, double closePrevPrice=0.0, int shares=0);

friend istream& operator>>(istream& ins, stockType& stock);
friend ostream& operator<<(ostream& outs, const stockType& stock);

//sets the variables
void setStockInfo(string syms, double open, double close, double high,
double lowPrev, double closePrev, int no_of_shares);
//calculates the gain
void calculateGain(double closeP, double prevP);


bool operator==(const stockType& stock1) const;
bool operator!=(const stockType& stock1) const;
bool operator<=(const stockType& stock1) const;
bool operator<(const stockType& stock1) const;
bool operator>=(const stockType& stock1) const;
bool operator>(const stockType& stock1) const;

//member functions
string getSymbols()const {return symbols;}
double getOpenPrice()const {return open_price;}
double getClosePrice()const {return close_price;}
double getHighPrice()const {return high_price;}
double getLowPrevPrice()const {return low_prev_price;}
double getClosePrevPrice()const {return close_prev_price;}
double getShares()const {return no_shares;}
double getGain()const {return gain;}

private:
string symbols;
double open_price, close_price, high_price, low_prev_price, close_prev_price, gain;
int no_shares;
};

#include "stockType.h"

stockType::stockType(string symbol, double openPrice, double closePrice, double highPrice,
double lowPrevPrice, double closePrevPrice, int shares)
{
setStockInfo(symbol, openPrice, closePrice, highPrice, lowPrevPrice, closePrevPrice, shares);
}

void stockType::setStockInfo(string syms, double open, double close, double high,
double lowPrev, double closePrev, int no_of_shares)
{
symbols = syms;
open_price = open;
close_price = close;
high_price = high;
low_prev_price = lowPrev;
close_prev_price = closePrev;
no_shares = no_of_shares;
}

istream& operator>>(istream& ins, stockType& stock)
{
ins>>stock.symbols;
ins>>stock.open_price;
ins>>stock.close_price;
ins>>stock.high_price;
ins>>stock.low_prev_price;
ins>>stock.close_prev_price;
ins>>stock.no_shares;
stock.calculateGain(stock.close_price, stock.close_prev_price);
return ins;

}

ostream& operator<<(ostream& outs, const stockType& stock)
{

outs<<stock.getSymbols()
<<fixed<<showpoint<<setprecision(2)
<<setw(10)<<stock.getOpenPrice()<<setw(10)
<<stock.getClosePrice()<<setw(10)
<<stock.getHighPrice()<<setw(10)
<<stock.getLowPrevPrice()<<setw(11)
<<stock.getClosePrevPrice()
<<setw(10)<<stock.getGain()<<"%"<<setw(13)
<<stock.getShares()<<endl<<endl;
return outs;
}

void stockType::calculateGain(double closeP, double prevP)
{

gain = ((closeP - prevP)/(prevP)*100);
}
bool stockType::operator==(const stockType& stock1) const
{
return (symbols==stock1.symbols);
}
bool stockType::operator!=(const stockType& stock1) const
{
return (symbols!=stock1.symbols);
}
bool stockType::operator>=(const stockType& stock1) const
{
return (symbols>=stock1.symbols);
}
bool stockType::operator>(const stockType& stock1) const
{
return (symbols>stock1.symbols);
}
bool stockType::operator<=(const stockType& stock1) const
{
return (symbols<=stock1.symbols);
}
bool stockType::operator<(const stockType& stock1) const
{
return (symbols<stock1.symbols);
}


#ifndef stockListType_H
#define stockListType_H

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include "stockType.h"

using namespace std;

class stockListType
{
public:
stockListType()
{
}

void insert(const stockType& item);
void sortStockSymbols();
void sortStockGain();
void printStockSymbols();
void printStockGain();

private:
vector<int> indexByGain;
vector<stockType> list;
};
#endif

#include <algorithm>
#include "stockListType.h"


void stockListType::insert(const stockType& item)
{
list.push_back(item);
}

void stockListType::printStockSymbols()
{
int k = 0;
double closing_assets = 0;
cout<<"***************** First Investor's Heaven ******************************"<<endl<<endl;
cout<<" Financial Report "<<endl;
cout<<"********************************************************************************"<<endl<<endl;
cout<<"Stock Today Previous Percent"<<endl<<endl;
cout<<"Symbol Open Close High Low Close Gain Volume"<<endl;
cout<<"------ ------ ------ ------ ------- ------- ------- -------"<<endl;

for (k=0; k<list.size(); k++)
{
cout<<list[k]<<endl;
closing_assets =+(list[k].getClosePrice()*list[k].getShares());
}
cout<<endl<<"****************************************";
cout<<endl<<"* Closing Assests: "<<closing_assets<<endl;
cout<<"****************************************"<<endl;
}

void stockListType::printStockGain()
{
int k = 0;
double closing_assets =0;
cout<<"***************** First Investor's Heaven ******************************"<<endl<<endl;
cout<<" Financial Report "<<endl;
cout<<"********************************************************************************"<<endl<<endl;
cout<<"Stock Today Previous Percent"<<endl<<endl;
cout<<"Symbol Open Close High Low Close Gain Volume"<<endl;
cout<<"------ ------ ------ ------ ------- ------- ------- -------"<<endl;

for (k=0; k<list.size(); k++)
{
cout<<list[k]<<endl;
closing_assets = closing_assets + (list[k].getClosePrice()*list[k].getShares());
}
cout<<endl<<"****************************************";
cout<<endl<<"* Closing Assests: "<<closing_assets<<endl;
cout<<"****************************************"<<endl;

}

void stockListType::sortStockSymbols()
{
sort(list.begin(), list.end());

}

void stockListType::sortStockGain()
{
//need help implementing the code
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote