

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: McQuain; Class: Data Structs & OO Development; Subject: Computer Science; University: Virginia Polytechnic Institute And State University; Term: Unknown 1989;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


You will implement a simple C++ program that reads a file containing information about an investor’s stock portfolio, and produces a summary report. The primary point of the assignment is to verify your understanding of basic C++ syntax, including input and output, the string type, arithmetic calculations, and user-defined functions.
Here is a sample input file, named StockData.txt, for the program. The first line specifies the name of the customer, and the second specifies the customer's account number. The third line specifies the report date. Each of the remaining lines specify the name of a particular stock, the number of shares the customer holds, and the initial and final prices for the stock. These values are separated by single tab characters.
Customer Name John Q Public Account # 432-10023-4311- Report Date 08/05/
There is no limit on the number of lines of stock data that may be supplied; your program must terminate properly when the input stream fails. There will be no sentinel line. The input values are guaranteed to be syntactically and logically correct. The customer name, account number and date are just string data. For the purpose of formatting output, you may assume that the customer name will be no more than 40 characters long, and the account number and date will be no longer than the ones shown above. However, the rest of your implementation should make no such assumptions.
For each of the given stocks, you will calculate the change in total value of all the shares the investor holds, and the percentage change in the value of a single share of the stock. The percentage change is the change in value as a percentage of the initial stock price.
In addition, you will also calculate a measure of the volatility of each stock's performance. For the purposes of this assignment, we will measure the volatility as the total range of the stock's price movement as a percentage of the opening price of the stock. More specifically, the volatility involves the sum of the absolute values of three quantities: the difference between the high and low prices, the difference between the high price and the smaller of the initial and closing prices, and the difference between the low price and the larger of the initial and closing prices. In the event the initial price is zero, we will arbitrarily define the volatility to also be zero; however that situation will not arise in actual data.
The report will end with a summary section, including the total initial and final value for the entire portfolio, the overall change, and the overall percentage change.
All monetary amounts are to be reported to two decimal places; the percentage changes are to be reported to three decimal places, as shown in the sample output file below.
There is one important data representation issue in this project. As you may already know, computer hardware almost never stores decimal values exactly, and so any calculations done with decimal values are likely to be slightly wrong. To avoid that, your program is required to store all monetary amounts internally using integer variables. You may either store dollars and cents separately, or store a total amount in cents.
Here is a sample output file, named Summary.txt, which corresponds to the input data given above:
Customer: John Q Public 432-10023-4311- Date: 06/05/
MSFT 650 57.32 55.17 -1397.50 -0.038 0. IBM 100 53.02 54.00 98.00 0.018 0. APPL 200 17.45 13.09 -872.00 -0.250 0.
Summary 46050.00 43878.50 -2171.50 -0.
The first line of the report file identifies the customer, as shown. The second line gives the date specified by the original invoice file. The third line is blank. The next line specifies column headers for the table that makes up the bulk of the report, and the next line delimits the top of the table.
Each line of the stock report table gives the number of shares, initial and final price, total change and percentage change for one stock. The table is bounded below by a single line of delimiters. The summary line gives the overall summary data for the entire stock portfolio.
If you have read the description of how the Curator scores your program in the Student Guid e, you know that is important that you use the same spelling and capitalization for all the labels shown above. The horizontal spacing does not effect scoring unless you combine things that should be separate or separate things that should be combined. You are free to experiment with the horizontal layout but you should try to align the columns neatly.
Perhaps in contrast to most of your previous programming experience, there is no requirement that you apply object- oriented principles in either your design or your implementation. There will be plenty of that to come. You may implement user-defined classes if you wish, but we will not have covered the relevant differences between Java and C++ by the time this assignment is due.
Separate compilation in C++ raises a few interesting issues, which will also not have been fully addressed in class before this assignment is due. Rather than deal with the inevitable questions offline, you are required to submit your solution in a single C++ source file.
There is no restriction on your use of the C++ Standard Libraries, including the STL. However, there is no need for any generic containers in this assignment.
You are, however, expected to identify an appropriate set of functions, and implement them using idiomatic C++. Specifically, your implementation must meet the following requirements:
Choose descriptive identifiers when you declare a variable or constant. Avoid choosing identifiers that are entirely lower-case. Use named constants instead of literal constants when the constant has logical significance. Use C++ streams for input and output, not C-style constructs. Use C++ string variables to hold character data, not C-style character pointers or arrays. Use C++ functions intelligently and appropriately. In particular, you must implement and use at least 4 functions in addition to main(). At least one of these functions must be void; at least one must return a value via a return statement, and at least one must use a reference parameter to return a value. It is acceptable that all function calls are from main() to other functions. Use the appropriate protocol when passing each parameter to a function. In particular, do not pass any parameter by reference unless it is being used to communicate a changed value from the called function to its caller.