CPSC 231: Assignment 3 (Due Wednesday, July 17)

Weighting = 3% (1% for each program).  Executable solutions to the assignment and any applicable text-only versions of the programs can be found in Unix under /home/231/assignments/assignment3.   The names of the executables are: "fixed", "simpleInterest" and "incomeStatements".  All three parts of the assignment must be completed on the Computer Science computers.  You must hand in your submission via a printed typescript.

Program one (fixing syntax errors for compilation):

The following program has a number of syntax errors that prevent it from being compiled into an executable "a.out".  Copy the text version of this program to your home directory.  Rename the program to "fixed.p" and fix all of the syntax errors.  Run the typescript (as described in the general assignment specifications), display the program, compile and run it within the script to show that it works.

program fixed (input, output)
var
x, y: integer
begin
x = 5;
y = x * 2;
writeln('Value of x = , x, ' Value of y = ', y);
end.

Program two (using basic input and output statements and formulas to calculate simple interest):

Loans that accrue simple interest are ones in which the interest is accumulated only on the original amount borrowed (the principle) and not on the interest that is accumulated.  The following formula is used for calculating simple interest:

     interest = principle * interest rate * time

For example, suppose that someone borrows $100.00 for 7 years at 12% interest per year.  The amount of interest that will be owing after seven years have elapsed would be calculated by plugging in these values into the above formula:

     interest = 100 * 0.12 * 7
                 = $84.00

For the purposes of this assignment you can make the simplifying assumption that units of time will be only in years (and not months or weeks).  The interest rate will then be an annual one.  In order to calculate the amount owing after the duration of the loan you just add together the original principle that was borrowed with the interest that was accumulated:

     amount = principle + interest

The total amount owing in the example above would be equal to the above amount of accumulated interest added to the original principle borrowed:

     amount = $100.00 + $84.00
                 = $184.00 

While your program does not have to perform any error checking or extensive formatting of the output, the final dollar values should look like currency (e.g., two decimal places for cents) and not scientific floating point values.  (Try running the sample executable for an idea of acceptable output).  You must script your assignment submission and hand in the typescript.

 

Program three (formatting output of Income Statements by setting the field width and number of places of precision):

Income Statements are used widely in the analysis of the financial health of a company.  While calculating income can become quite complicated and involved, for the purposes of this assignment you can use the simplified formula:

          Gross Sales

     - <Cost of the goods that were sold> 

          Gross profit

     - <Operating expenses>

     =  Net income

However you do not need to specifically know this formula in order to complete this assignment, the calculations will be automatically be made for you in the program incomeStatements.p (duplicated for your reference below): 

program incomeStatements (output);
var
(* Financial information for company DefNet *)
grossSalesDN, costOfGoodsSoldDN, grossProfitDN, operatingExpensesDN: real;
netIncomeDN: real;

(* Financial information for company HiTekk *)
grossSalesHT, costOfGoodsSoldHT, grossProfitHT, operatingExpensesHT: real;
netIncomeHT: real;

(* Financial information for BigTrb *)
grossSalesBT, costOfGoodsSoldBT, grossProfitBT, operatingExpensesBT: real;
netIncomeBT: real;

(* Financial information for GoUndr *)
grossSalesGU, costOfGoodsSoldGU, grossProfitGU, operatingExpensesGU: real;
netIncomeGU: real;
begin
(* Initialize the variables containing the financial information. This
* would normally not be hard-coded of course.
*)
(* DefNet *)
grossSalesDN := 100000000;
costOfGoodsSoldDN := -65000000;
operatingExpensesDN := -12000000;
grossProfitDN := grossSalesDN + costOfGoodsSoldDN;
netIncomeDN := grossProfitDN + operatingExpensesDN;

(* HiTekk *)
grossSalesHT := 75000000;
costOfGoodsSoldHT := -65000000;
operatingExpensesHT := -300000000;
grossProfitHT := grossSalesHT + costOfGoodsSoldHT;
netIncomeHT := grossProfitHT + operatingExpensesHT;

(* Big Trouble*)
grossSalesBT := 1750000;
costOfGoodsSoldBT := -1000000;
operatingExpensesBT := -5500000;
grossProfitBT := grossSalesBT + costOfGoodsSoldBT;
netIncomeBT := grossProfitBT + operatingExpensesBT;

(* GoUndr *)
grossSalesGU := 150000;
costOfGoodsSoldGU := -150000;
operatingExpensesGU := -3375000;
grossProfitGU := grossSalesGU + costOfGoodsSoldGU;
netIncomeGU := grossProfitGU + operatingExpensesGU;

(* Display table of Income statements - this is what you need to do! *)

end.

Copy the program incomeStatements.p to your home directory and modify it so that it will display the Income Statements for the companies: DefNet, HiTekk, BigTrb and GoUndr in a presentable and neat tabular form.  Entries that are in the same column should line up and be right-justified (flush with the right margin for each column).  Numerical values should display only two decimal places of precisions.  You can run the executable solution to this part of the assignment, incomeStatements in order to get an idea of how the formatted output should look.  Again your assignment submission must take the form of printed typescript.

Learning objectives:

Understanding the syntax of a basic Pascal program enough to be able to fix common compilation errors (program one).
Knowing how to use variables in Pascal as well as forming formulas for assignment statements (program two).
Learning how to format output and make it look presentable by setting the field size and the number of places of precision for real values (program three).