SAN JOSÉ STATE UNIVERSITY
ECONOMICS DEPARTMENT
Thayer Watkins

Econ 196E
Computer Applications in Economics

Course Green Sheet

Primer on HTML

Scripting languages

Student Webpages

History of the Computer

Technology

History of the development of the PC: Hardware and Software

Languages

Basic structure of computer

History of operating systems

References: Fire in the Valley by Paul Freiberger and Michael Swaine
Hackers: Heroes of the Computer Revolution by Steven Levy

Programming Languages

The Rudiments of Pascal

The basic structure of a Pascal program is:

A program typically consists of a part to obtain the input, a part to carry out the computation, and a part to provide output to the user.

Input is usually handled by means of the Pascal readln statement. A readln statement tells the computer what variables are to be read in and in what order. The actual input from the keyboard has to conform to the data types for the variables.

It is usually necessary to prompt the user for data. This is done by means of the writeln or write statement. The difference between writeln and write is that writeln moves to the next line after the write operation whereas write does not.

As the above program is written, the computer has not been instructed as to the format for printing out the discount factor df. It may print out 0.05 in the form .500E-01, which means 0.5x10-1. To make the format of df an 8 digit number with 6 digits after the decimal one replaces

writeln('The discount factor equals ',df);

with writeln('The discount factor equals ',df:9:6);

The assignment of a value to a variable is achieved by means of := (colon equal sign). The equal sign by itself stands for testing for equality.

Pascal variables are strongly typed; i.e. care must be taken to distinguish between variables which are integers and variables which are floating point numbers (reals). The aritmetic operations of addition, subtraction, and multiplication are denoted by +,-, and *, regardless of whether integers or reals are involved. Division requires a little care. Division of a real number by a real number or integer is handled with slash (/). Division of integers requires two special operations, denoted as div and mod. A div B stands for the quotient of A divided by B; A mod B stands for the remainder when A is divided by B.

Much of the computation in a program is handled by means of loops, sequences of instructions that are executed repeatedly. In Pascal there are a variety of loops. The simplest is the FOR loop. It has the structure:


                  FOR i:=1 TO n DO

                      instructions;.

If there is more than one instruction then they must be enclosed between BEGIN and END statements.

The most frequent error in Pascal programming is losing track of BEGIN and END statements. It is good practice to always create the corresponding END statement when you create a BEGIN statement. For easier reading of the programs the BEGIN and END statements should be lined up.

Pascal is not case sensitive so BEGIN can be written as Begin, begin or any other variation. You can use this to keep the BEGIN and END statements matched up.

Another important instruction is the IF statement. It can have the structure:


         IF (condition) THEN instruction1 ELSE instruction2;

Usually for readability it is written on several lines. The ELSE clause is optional. If there is an ELSE clause then there should be no semicolon after instruction1.

Pascal has no instruction for exponentiation. One has to create the exponential out of other instructions.

Subprograms can be created in Pascal. They are called Procedures. A procedure takes parameters. In the specification of the parameters their types must be given. If the parameters are to be modified by the procedure they must be proceded by the term VAR.

Pascal has a data type called ARRAY. To indicate that a variable x is a vector of reals or M is a matrix of integers one uses


                    x:ARRAY[1..n] OF real;

                    M[1..m,1..n] OF integer;

Economics 196e

Programming problems

Econ 196e Spread Sheeets

Spreadsheets, along with word processors, are the most useful types of software for the general user. This is an application of Excel to microeconomics. It involves computing revenue, costs, and profit as functions of output.