Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write a C++ program to finish it!!! Question 1: Write a C++ program that accepts stock data from a text file named stock.txt which
Please write a C++ program to finish it!!!
Question 1: Write a C++ program that accepts stock data from a text file named stock.txt which contains a maximum of 10 stocks with their stock codes and their market prices for the morning and the afternoon during one day. Create a single dimensional array to hold the maximum of 10 stock codes, which should be found from the first line of the stock file, being separated by a whitespace. Create a two dimensional array to hold the two market prices of each stock, and they should be found starting from the second line of the input file, being separated by a whitespace, and the morning market price will be followed by the afternoon market price for each stock. Please initialize your arrays to 0 and they may not be always full. An instruction will be displayed at the beginning, requesting the user to retrieve stock data from the stock file and create the two arrays. Any updates will be stored in an output file named "outfile.txt. Then the user could choose to perform any one of the following functions in the menu: 1. Count Size : Count the total number of stocks in the stock file 2. Get Minimum : Find the minimum market price among all stocks, and show the corresponding stock code and minimum price 3. Compare Prices : Compare and identify whether there is a rise or drop between the morning and afternoon market prices of one stock by accepting the stock code to check 4. Update Target : Check whether a particular stock is found within the stock code array, and update its market prices 5. Display Stock : Display all the stock codes with their morning and afternoon market prices in a tabular format 6. Exit P.1 *Reminder: Include all kinds of error handling such as integer value checking for stock codes, double value for market prices, array size checking, and possible errors from the input file. Each item from the user menu should be a separate function of its own. The function prototypes are as follows: 1. int countSize (const int stock[l, const double prices[][], int arraysize); 2. double getMin(const int stock[], const double prices[][], int arraysize); 3. bool comparePrice (int stockcode, const int stock[], const double prices[][], int arraysize); 4. void updateTarget (int target, int stock[], double prices [] [], int arraysize); 5. void display(const int stock[l, const double prices[][], int arraysize); Sample Input & Output: Please make sure that you have created the "stock.txt" as input for this program! Your input file should have a maximum of 10 stock data (including stock code and their corresponding market prices in the morning and in the afternoon per day)! Your output should be stored in a textfile named "outfile.txt" afterwards. Welcome to the Stock Analysis System! Would you like to create your stock arrays now? Y/N: Y Stock code array and Prices array are successfully built! ++++++ Stock Analysis System ++++++++++++++++++++++++ 1. Count Size 2. Get Minimum 3. Compare Prices 4. Update Target 5. Display All 6. Exit +++++++ +++++ Please enter your choice (1-6): 1 There are 4 stocks in your file! +++ ++ Stock Analysis System +++++++++++++ 1. Count Size 2. Get Minimum 3. Compare Prices 4. Update Target 5. Display All 6. Exit +++++++ ++++++++++++++++ +++ Please enter your choice (1-6): 2 The minimum price is $2.30, obtained by stock 0012. +++++++++++++++++++++++++++++++++++++++++++++ Stock Analysis System ++++++++++++ +++++ - +++++ 1. Count Size 2. Get Minimum 3. Compare Prices 4. Update Target 5. Display All 6. Exit +++ -++ Please enter your choice (1-6): 3 Please enter the stock code: 0005 The morning price $36.56 is higher than the afternoon price $35.45! ++++ +++++++++ ++++++ Stock Analysis System ++++ +++ 1. Count Size 2. Get Minimum 3. Compare Prices 4. Update Target 5. Display All 6. Exit +++++ Please enter your choice (1-6): 4 Please enter the target stock code: 0212 Stock found! Please enter the new morning price in $: 3.33 Please enter the new afternoon price in $: 3 Stock prices updated in the arrays and the output file! ++++ ++++++++ +++++++ ++++ Stock Analysis System ++++ 1. Count Size 2. Get Minimum 3. Compare Prices 4. Update Target 5. Display All 6. Exit ++++- Please enter your choice (1-6): 5 Stock Code Morning Price Afternoon Price 0001 0005 0012 0212 84.53 36.56 2.33 3.33 89.33 35.45 2.30 3.00 +++ + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + . + + + + + + +++++ P.3 Stock Analysis System + + + + + 1. Count Size 2. Get Minimum 3. Compare Prices 4. Update Target 5. Display All 6. Exit +++ Please enter your choice (1-6): 6 Done! Thank you very muchStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started