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: 3883345 • 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.h>

#include <string.h>

#include <fstream.h>

#include <iomanip.h>

#include<math.h>

#include<stdlib.h>

#include<conio.h>

struct Stock

{

int no;

char symbol[50];

char company_name[50];

float LastPrice;

float Change;

float PercentageChange;

long Volume;

};

const int SIZE = 10;

const int INFO = 6;

fstream file;

// Function prototypes

void openInputFile(ifstream &, char str[]);

void getTotal(Stock[]);

void sort(Stock[]);

int main()

{

clrscr();

// Variables

Stock arr[SIZE];

  

ifstream inFile;

char inFileName[50] = "stdout1.txt";

// Call function to read data in file

openInputFile(inFile, inFileName);

// Read data into an array of structs

for(int count = 0; count < SIZE; count++)

{

inFile >> arr[count].symbol >> arr[count].company_name >> arr[count].LastPrice >> arr[count].Change >> arr[count].PercentageChange >> arr[count].Volume;

}

// Close input file

inFile.close();

// Sort data

sort(arr);

system("PAUSE");

//writing data to the file

file.open ("test.txt", ios::out);

if(file)

{

file.write((char*)arr,sizeof(Stock));

}

else

cout <<"Error opening the file! ";

file.close();

getch();

return 0;

}

//opening file method

void openInputFile(ifstream &inFile,char inFileName[])

{

//Open the file

inFile.open(inFileName);

//Input validation

if (!inFile)

{

cout << "Error to open file." << endl;

cout << endl;

return;

}

}

/**

Sorting method based on LastPrice

*/

void sort(Stock arr[])

{

Stock temp;

for (int i = 0; i < (SIZE - 1); i++)

{

for (int j = i + 1; j < SIZE; j++)

{

if (arr[i].LastPrice > arr[j].LastPrice)

{

temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

}

}

}

}

//**************************************************************

// Definition of function sortArray. *

// This function performs an ascending order selection sort on *

// array. size is the number of elements in the array. *

//**************************************************************

void sortArray(string names[], int size)

{

int startScan, minIndex;

string minValue;

for (startScan = 0; startScan < (size - 1); startScan++)

{

minIndex = startScan;

minValue = names[startScan];

for(int index = startScan + 1; index < size; index++)

{

if (names[index] < minValue)

{

minValue = names[index];

minIndex = index;

}

}

names[minIndex] = names[startScan];

names[startScan] = minValue;

}

}

//***************************************************************

// The binarySearch function performs a binary search on an *

*

//***************************************************************

int binarySearch(string names[], int size, string value)

{

int first = 0, // First array element

last = size - 1, // Last array element

middle, // Mid point of search

position = -1; // Position of search value

bool found = false; // Flag

while (!found && first <= last)

{

middle = (first + last) / 2; // Calculate mid point

if (names[middle] == value) // If value is found at mid

{

found = true;

position = middle;

}

else if (names[middle] > value) // If value is in lower half

last = middle - 1;

else

first = middle + 1; // If value is in upper half

}

return position;

}