Write a program to predict the performance of various stocks.
**Part 0: Read in the data.** The following program reads in a sequence of stock prices and prints them out.
``` #include <stdio.h int main(void) { float price; while (scanf("%f", &price) != EOF) printf("%7.3f\n", price); return 0; } ```
Type the program exactly as is; save as `input.c`; and compile with `gcc input.c`. To read in the data from a file named `stock15.txt`, type `a.out < stock15.txt`. You can also test your program on `stock1000.txt`, a larger file that contains real data.
**Part 1: Plot.** Write a program `plot.c` to display the stock values graphically instead of just printing the values. Round the stock price down to the nearest integer, and print that number of `*`'s. The correct output is:
**Part 2: Detect a pattern.** Write a program to identify specific trends in the data. Dilbert the Day Trader believes that if the stock goes up 3 (or more) consecutive time periods and then down in the next period, then it is a good time to sell the stock. Analogously, Dilbert believes that if the stock goes down 3 consecutive time periods and then up in the next period, then it is a good time to buy the stock. Write a program `pattern.c` that prints out the time period and stock price, along with the word `buy` or `sell` according to Dilbert's rule. The output should look like this:
**Part 3: Invest.** Write a program `invest.c` to determine how much money you would have won or lost using Dilbert's rule. You start with $10,000.00 cash. Assume that you will convert all of your cash to stock when Dilbert's rule signals you to buy, and that you will convert all of your stock to cash when Dilbert's rule signals you to sell. For each time period, print out the price, cash, shares owned, and portfolio value. The value of your portfolio is cash plus the number of shares multiplied by the price per share. (For simplicity, assume that you can buy fractional amounts of stock, and there are no transaction fees.) For `stock15.txt`, the correct output is: