Asg 3: Stock Portfolio

Objectives

Implement a simple stock portfolio ledger, where the user enters in a number of stocks (e.g., 3), and then inputs initial holdings. The program then loops through asking the user to enter in a stock and change in the holdings (until sentinel entry). When the user inputs the sentinal to end the loop the portfolio is output in the form of a side bar chart.

Assignment

  1. Loop by asking the user to enter in a number of stocks, checking for validity of input (should be > 0 and ≤ 100).
  2. Given the number of stocks, dynamically allocate a float array with size large enough to record stock information.
  3. Loop through the array loading it up with initial holding of each stock (array element) by asking the user for initial value.
  4. Loop through transactions that increment or decrement each stock value until the user enters in sentinel information (-1 -1).
  5. Print out the final stock holdings in the form of a side barchart.

Details

  1. The main idea here is to dynamically allocate a float array where each array element holds the quantity of stock.
  2. The rest of the code is then concerned with looping through the array to either update or print its contents.
  3. Do not forget to free() the array upon exit.

Example Program Run

How many stocks? 3
Input initial holding of 0: 10
Input initial holding of 1: 10
Input initial holding of 2: 10

Enter stock and change (-1 -1 to end): 0 1
Stock 0 is now 11.00
Enter stock and change (-1 -1 to end): 1 -1
Stock 1 is now 9.00
Enter stock and change (-1 -1 to end): -1 -1
0: ============================================================ 11.00
1: ================================================== 9.00
2: ======================================================= 10.00
	

Supplemental

  1. If you call your source code file main.c here is a Makefile that you can use to try to compile the project:
    CC = gcc
    
    .c.o:
    	$(CC) -c -o $@ $<
    
    all: main
    
    main: main.o
    	$(CC) -o $@ $@.o
    
    main.o: main.c
    
    clean:
    	rm -f *.o
    	rm -rf main
    	
    Note that each line underneath the targets is indented by a tab, not just spaces, this is important!

Turn in

Turn in all of your code, in one tar.gz archive of your asg##/ directory, including:
  1. A README file containing
    1. Course id--section no
    2. Name
    3. Brief solution description (e.g., program design, description of algorithm, etc., however appropriate).
    4. Lessons learned, identified interesting features of your program
    5. Any special usage instructions
  2. Makefile
  3. source code (.h headers and .c source)
  4. object code (do a make clean before tar)

How to hand in

See handin notes

Grading scheme