Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ISOM 3029 - Computer Programming Using C++

2022/2023 (First Semester)

Assignment 2

Instructions:

Read the Assignment Requirements posted in the UMMoodle before attempting

to solve the following problems with C++ programs.

Both the hardcopy and softcopy of your assignment should be submitted on time. All programs are to be compressed and uploaded to the UMMoodle under the

Submit Assignment 2” button.

The compressed file should be named with your student number such as

ba12345_Ass2.zip”.

Question 1:

Write a C++ program that accepts stock data from a text file named stock.txt” which contains 10 stock records containing Stock Code”, “Morning Price” and Afternoon Price” .    The 10 stock codes in the file should be automatically generated (e.g. 10001, 10002, 10003 etc.) in advance by your program, and their market prices for the morning and the afternoon during one day should also be randomly generated with the price range between $0.00 to $100.00. Your program should randomly generate integers between

0 to 10000 and divide the random numbers by 100.0 to obtain a decimal value for the stock prices. Create a single dimensional array to hold the 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 be reminded to initialize all your arrays to 0 upon declaration. An instruction will be displayed at the beginning upon program execution, requesting the user to generate stock data to 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.   Get Maximum    : Find the maximum market price among all stocks, and show the corresponding stock code and that maximum price

2.   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

3.   Count Falls         : Count the total number of stocks with afternoon price lower than morning price and list them out

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

*Reminder: Include all kinds oferror handling such as integer value checkingfor stock codes, double valuefor market prices, array size checking, and possible errorsfrom the inputfile.

Each item from the user menu should be a separate function of its own. The function prototypes are as follows:

1. double getMax (const int stock[], const double prices[][], int arraysize);

2. bool comparePrice (int stockcode, const int stock [], const double prices[] [],

int arraysize);

3. int countFalls(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 [], const double prices[][], int arraysize);

Sample Input & Output:

Please make sure that you have created the stock.txtas input for this

program! Your input file should have 10 stock records (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. Get Maximum

2. Compare Prices

3. Count Falls

4. Update Target

5. Display All

6. Exit

+++++++++++++++++++++++++++++++++++++++++++++

Please enter your choice (1-6): 1

The maximum price is $92.30, obtained by stock 10002.

+++++++++++++++++++++++++++++++++++++++++++++

Stock Analysis System

+++++++++++++++++++++++++++++++++++++++++++++

1. Get Maximum

2. Compare Prices

3. Count Falls

4. Update Target

5. Display All

6. Exit

+++++++++++++++++++++++++++++++++++++++++++++

Please enter your choice (1-6): 2

Please enter the stock code: 10006 The morning price $36.56 is lower than the afternoon price $85.45!

+++++++++++++++++++++++++++++++++++++++++++++

Stock Analysis System

+++++++++++++++++++++++++++++++++++++++++++++

1. Get Maximum

2. Compare Prices

3. Count Falls

4. Update Target

5. Display All

6. Exit

+++++++++++++++++++++++++++++++++++++++++++++

Please enter your choice (1-6): 3

There are 2 stocks with price falling! They are:

Stock Code Morning Price Afternoon Price

10003        $ 10.54         $ 9.40

10005        $ 33.12         $ 3.45

Stock Analysis System

+++++++++++++++++++++++++++++++++++++++++++++

1. Get Maximum

2. Compare Prices

3. Count Falls

4. Update Target

5. Display All

6. Exit

+++++++++++++++++++++++++++++++++++++++++++++

your choice (1-6): 4

the target stock code: 10004

the new morning price in $: 3.33

the new afternoon price in $: 3.60

updated in the arrays and the output file !

+++++++++++++++++++++++++++++++++++++++++++++

Stock Analysis System

+++++++++++++++++++++++++++++++++++++++++++++

1. Get Maximum

2. Compare Prices

3. Count Falls

4. Update Target

5. Display All

6. Exit +++++++++++++++++++++++++++++++++++++++++++++ Please enter your choice (1-6): 5

Stock Code Morning Price Afternoon Price

======================================================

10001

10002

10003

10004

10005

10006

10007

10008

10009

10010

84.53

90.23

10.54

3.33

33.12

36.56

6.56

2.33

13.33

23.33

89.33

92.23

9.40

3.60

3.45

85.45

15.45

12.30

33.22

83.34

+++++++++++++++++++++++++++++++++++++++++++++

Stock Analysis System

+++++++++++++++++++++++++++++++++++++++++++++

1. Get Maximum

2. Compare Prices

3. Count Falls

4. Update Target

5. Display All

6. Exit +++++++++++++++++++++++++++++++++++++++++++++ Please enter y