In c++ In this program you will make suggestions as to what stock to make additi
ID: 3831716 • Letter: I
Question
In c++
In this program you will make suggestions as to what stock to make additional purchases of from among ones that are already in a portfolio. There is a file named stocks dat. Copy this file into your directory using the unix command. It is located here:/export/home/public/carelli/csc135/stocks.dat Each line of the file has four values on it. The first is the stock symbol. The second value is the current (closing) price of the stock. The third is the original purchase price of the stock. The fourth and last is the number of shares currently owned. When you read these values in you are to store them in arrays, one for each of the types of values (4 arrays). You will have an array for the stock symbol, an array for the current price of the stock, an array for the buying price of the stock, and, finally, an array for the number of shares owned. Set the array sizes to each hold 15 items. Once you the arrays loaded, you are to find stocks that may be possible "buy" candidates. A buy candidate is defined as follows: 1) The number shares owned must be less than 100 shares 2) The current price of the stock should be less than or equal to the purchase price of the stock already owned. The output of this program should look as follows: And so on for as many stocks that you can find that meet the criteria above. All of the tasks in this program should be carried out in functions. So, you will need a function to prompt for the file name and open it. Another function will read the information into arrays. A third function will both identify the "buy" candidates and print them out. Add any other functions you deem necessary to print out any additional information, as needed. The main function should consist, basically, of calls to functions only. You cannot use GLOBAL variables. Any information that needs to be passed between functions should be either pass-by-value or pass-by-reference (if you need to change the value).Explanation / Answer
#include<iostream.h>
#include<string>
void getInputFile(string &name){
cout << "Enter filename" << endl;
cin >> name;
}
void readFile(string &filename, string (&symbol)[15], float (&close)[15], float (*purchase)[15], int (*shares)[15]){
ifstram infile;
string sym;
float clo;
float pur;
int sha;
int count = 0;
infile.open(filename);
while (infile >> sym >> clo >> pur >> sha){
symbol[count] = sym;
close[count] = clo;
purchase[count] = pur;
shares[count] = sha;
count++;
}
}
void identifyBuy(string (&symbol)[15], float (&close)[15], float (*purchase)[15], int (*shares)[15]){
cout << "Symbol" << " " << "Closing" << " " << "Purchased" << " " << "Shares" << endl;
cout << "---------------------------------------------------------------------------" << endl;
for (int i = 0; i<15; i++){
if ((shares[i] < 100) && (close[i] <= purchase[i])){
cout << symbol[i] << " $" << close[i] << " $" << purchase[i] << " " << shares[i] << endl;
}
}
}
void main(){
string symbol[15];
float close[15];
float purchase[15];
int shares[15];
string filename;
getInputFile(filename);
readFile(filename,symbol, close, purchase,shares);
identifyBuy(symbol, close, purchase,shares);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.