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

1. You will pick 10 stocks from this list: https://finance.yahoo.com/quote/%5EDJ

ID: 3885353 • Letter: 1

Question

1. You will pick 10 stocks from this list: https://finance.yahoo.com/quote/%5EDJI/components?p=%5EDJI

2. create a program that takes the stock's symbol, company name, last price, change, and volume as input from a file. How the file is formatted and inputed is up to you and you can put underscores between words in the companies name instead of using spaces. Store these values in either

-a 2 dimensional array or vector of strings (may require converting strings to floats using:stof(stringVariable,nullptr); )

-5 individual arrays or vectors of their correct types

-You may create a class or struct with the proper members for the data for each company, then create an array or vector of the class or struct type.

3. After input, it will display the information on the terminal. Users will have the option of sorting the information by any of the five categories of information. Depending on which category the data is being sorted by, you will sort using a different sorting algorithm.

4. The user will also be able to change the stock price.. When this option is selected,

-the user should input the stock symbol.

-The array will be searched using a binary search

-If the symbol is found, all the information for that company will be displayed, else an error message will be displayed.

-The user will be able to enter a new price for the stock.

-This value will be updated in the array.

5. When the user exits, all data will be written back to the file.

The language for this program should be in C++

Competent 200 (20%)-400 (40%) 5 Different algorithms are Sortin 0 (0%)-100 (10%) 100 (10%)-200 (20%) 1 or two algorithms are used and coded properly and/or the information in the arrays are jumbled by and/or a couple algorithmsused for the five different are not coded properly and/or the arrays are not categories to be sorted They are coded properly and the two dimensional arrays are sorted properly 0 (0%)-50 (596) 50 (5%)-100 (1096) 100 (10%)-200 (20%) Binary search not used, or completely off, or search item not returned, even if the search item is in array Binary search is used, but implementation is off a bit and/or no error message is displayed if data not Binary search is used and implemented properly Error message is displayed if data not 75 (7.5%)-150 (1596) 0 (0%)-25 (2.5%) Data is neither loaded nor outputted properly 25 (2.5%)-75 (7.5%) Data is either not loaded properly or not outputted to file properly File Input/Output Data is loaded into arrays properly and outputted to file properly 50 (5%)-100 (1096) All functions and code blocks have sufficient commenting. Any lines of code that are unclear are 0 (0%)-25 (2.5%) Little or no commenting. 25 (2.5%)-50 (596) Some functions or code blocks are not commented or several lines of unclear code are not commented 9 User Interface 0 (0%)-50 (596) 50 (596)-100 (1096) 100 (10%)-150 (15%) Formatting is messy and i Formatting is not very nice Output to console is is unclear how to use the formatted nicely Functionality is explained on screen and using the program is simple and/or how to use the program is unclear

Explanation / Answer

#include <iostream>

#include <vector>

#include <string>

#include <sstream>

#include <fstream>

using namespace std;

class Stock

{

private:

string symbol;

string company;

float lastPrice;

float change;

int volumn;

public:

Stock();

~Stock(){}

  

void setSymbol(string stockSymbol){

symbol = stockSymbol;

}

void setCompany(string companyName){

company = companyName;

}

void setLastPrice(float lastPriceTemp){

lastPrice = lastPriceTemp;

}

void setChange(float changeTemp) {

change = changeTemp;

}

void setVolumn(float volumnTemp) {

volumn = volumnTemp;

}

void printStockInfo();

  

  

};

//implementations

Stock::Stock()

{

lastPrice = 0.0;

change = 0.0;

volumn = 0;

}

//printing

void Stock:: printStockInfo()

{

cout << "Symbol : " << symbol << " ";

cout << "Company Name : " << company << " ";

cout << "Last price : " << company << " ";

cout << "Change : " << change << " ";

cout << "Volumn : " << volumn << " " <<endl;

}

int main()

{

  

std::ifstream file("Newfile.txt");

std::string line;

std::vector<Stock> tokens;

while(std::getline(file, line)) { // ' ' is the default delimiter

std::istringstream iss(line);

std::string token;

Stock *f1 = new Stock;

string symbol;

string company;

string lastPrice;

string change;

string volumn;

std::string::size_type sz;

getline (iss, symbol, '_'); //read from in, store iso and table

getline (iss, company, '_'); //getline will only use string

getline (iss, lastPrice, '_');

getline (iss, change, '_');

getline (iss, volumn, '_');

cout << symbol << company << lastPrice << change << volumn << endl ;

f1->setSymbol(symbol);

f1->setCompany(company);

float lprice = std::atof(lastPrice.c_str());

f1->setLastPrice(lprice);

float tchange = std::atof(change.c_str());

f1->setChange(tchange);

int tvolumn = std::atoi(volumn.c_str());

f1->setVolumn(tvolumn);

tokens.push_back(*f1);

}

vector<Stock>::iterator it1;

for ( it1 = tokens.begin(); it1 != tokens.end(); ++it1 ) {

it1->printStockInfo();

}

return 0;

}