PROGRAM Investment; {Programmer: Gregory A. Perkins CS 65 Due : 7 OCT 96} {This is the graphical version of the RealInvest program found in Ch. 4. It accepts the amount to be invested, the rate of interest, and the years of investment from the user, then displays the investment in graphical form. It also calculates the effects of inflation over the term of the investment and displays a warning if the value of the investment will decline.} USES cs65; VAR Amount, AmountIn, Rate : REAL; VAR Term, Year, Height : INTEGER; CONST Inflat = 0.041; BEGIN {Program} SetGraph; {Introduction section} OUTTEXTXY(5, 35, 'WELCOME TO THE INVESTMENT GRAPHER!!!'); OUTTEXTXY(5, 65, 'I will provide you with a graphical representation of your investment.'); OUTTEXTXY(5, 80, 'I will figure the effects of both the rate of interest and the approximate'); OUTTEXTXY(5, 95, 'rate of inflation on your investment over the course of the term invested,'); OUTTEXTXY(5, 110, 'and I will inform you if the value of the investment will decline. I will'); OUTTEXTXY(5, 125, 'display the yearly value of your investment in graphical form. I can'); OUTTEXTXY(5, 140, 'display a maximum of 13 years, and a maximum value of $10,000. Amounts that'); OUTTEXTXY(5, 155, 'exceed $10,000, will cause the graph to exceed the edges of the screen.'); OUTTEXTXY(5, 170, 'I hope that I can be of assistance to you in making a wise'); OUTTEXTXY(5, 185, 'investment decision. Good Luck!!!'); OUTTEXTXY(5, 225, 'Hit any key to continue...'); Pause; ClrScr; {obtain initial information from user} OUTTEXTXY(5, 50, 'Please enter the amount to be invested(MUST BE UNDER $10000): '); ReadReal(Amount); AmountIn := Amount;{keep initial value of investment for warning of decline in value} OUTTEXTXY(5, 65, 'What is the rate of interest (as a decimal): '); ReadReal(Rate); OUTTEXTXY(5, 95, 'How many years is the investment to run(MUST NOT BE MORE THAN 13 YEARS): '); ReadInt(Term); OUTTEXTXY(5, 150, 'Hit any key to view investment graph...'); Pause; ClrScr; {set up chart labels - dollar amounts} OUTTEXTXY(10, 30, 'CHART OF INVESTMENT GROWTH'); OUTTEXTXY(10, 46, '$10,000'); OUTTEXTXY(10, 146, '$7,500'); OUTTEXTXY(10, 246, '$5,000'); OUTTEXTXY(10, 346, '$2,500'); OUTTEXTXY(10, 446, '$000'); {set up chart labels - years} OUTTEXTXY(60, 461, 'Init.'); OUTTEXTXY(100, 461, 'Yr 1'); OUTTEXTXY(140, 461, 'Yr 2'); OUTTEXTXY(180, 461, 'Yr 3'); OUTTEXTXY(220, 461, 'Yr 4'); OUTTEXTXY(260, 461, 'Yr 5'); OUTTEXTXY(300, 461, 'Yr 6'); OUTTEXTXY(340, 461, 'Yr 7'); OUTTEXTXY(380, 461, 'Yr 8'); OUTTEXTXY(420, 461, 'Yr 9'); OUTTEXTXY(460, 461, 'Yr 10'); OUTTEXTXY(500, 461, 'Yr 11'); OUTTEXTXY(540, 461, 'Yr 12'); OUTTEXTXY(580, 461, 'Yr 13'); {Set the color to use for all following graphics} setColor(2); {Calculate and display bars.} FOR Year := 0 TO Term DO BEGIN Height := TRUNC(Amount*0.04); Bar(40*Year+60, 450-Height, 40*Year+90, 450); Amount := Amount*(1+Rate);{calculate rate of interest} Amount := Amount/(1+Inflat);{calculate effect of inflation} END; {Determine if value of investment decline warning is necessary and display} IF Amount < AmountIn THEN BEGIN setColor(14);{set to background color for warning line to yellow} Bar(0, 466, 639, 475); setColor(4);{display WARNING in red} OUTTEXTXY(191, 475, 'WARNING!!! VALUE OF INVESTMENT WILL DECLINE'); END;{Warning test} Pause; END.{Investment Program}