Chapter 1

Goals

From the book: What is a computer?
com · put · er n, often attrib (1646): one that computes; specific: a programmable electronic device that can store retrieve, and process data. ( Webster's Collegiate Dictionary)
At one time this was: What is a program?
program v, (1896): to work out a sequence of operations to be performed by (a mechanism): provide with a program.

To insert a program (a particular action) into or as if into a mechanism.

To predetermine the thinking, behavior, or operations of as if by computer programming. ( Webster's Collegiate Dictionary)


In our case, a series of instructions to a computer.

What do you already know how to program?

How would you program the above? Give an example?

How does programming a dog (or person) differ from programming a VCR?

My new definition:


computer n, an unintelligent machine that can very accurately follow a simple set of instructions exactly as they are given. (Dan)

How do you convert from military (24 hour) time?

     Get (read, ask ...) the time in military time
     If the time is larger than  1259
          Subtract 12 from the time
	  ending is pm
     If the time is not past 1259, 
          ending is am
     Return (say, write ...) the time and the ending

     Examples:
      0930 = 9:30 AM
      1304 = 1:04 PM
Programming is an art and a science. A programmer must learn a number of techniques and tools to correctly program, however they must also learn how to put these pieces together to solve a problem. This is somewhat like building a house, without the physical presence.

Programming

Our book suggests a three phase approach Any one of the later phases could lead us back to a previous phase.

The longer we spend at the earlier phases of this process, the easier it is to find and correct mistakes in the process.

The later in the process we find a mistake (bug), the more expensive it is to fix.


Some Definitions:

Algorithm a step by step procedure for solving a problem in a finite amount of time. bug a mistake in a computer program. The original bug was a moth that was caught in a relay.

Bugs can be in the syntax of spppeling. or formal, grammer, ov language the.

Bugs can also be in the logic of a program:

     To calculate pay:

     get hours
     get hourly_rate
     if hours are greater than 40
        pay = 1.5 * hourly_rate * hours
     if hours are 40 or less
        pay = hourly_rate * hours 
     output hours

The process of finding these errors is known as debugging.

After we have produced an algorithm for a given problem, we must translate that into a programming language.


A programming language is a set of grammatically rules and symbols used to construct a computer program.
There are many different programming languages: The process of translating an algorithm into a programming language is called coding.

An implementation of an algorithm in a programming language is called a program.


Again, let me restate the importance of a good design before you begin coding.

It is sometimes useful to write smaller programs to better understand how something works, or how to use a programing technique or concept.

Before, during and after the coding phase is the documentation phase.

Documentation is additional information that the programmer provides so

Good documentation is both internal (inside the program), and external. We will talk about this as time goes by.

Comments are a form of documentation that is within the code. Information is any knowledge that can be communicated.

Data is information in a form that a computer can use.

In some sense, as programmers we write programs that take data and turn it into useful information.

For example, we might take 100 years worth of daily high temperatures for each day of the year, and determine the monthly average temperature. It is hard to judge anything by the 36,500 data points, but the 12 numbers we would return are useful.


What is a programming Language?

Deep inside of the computer, everything is represented in binary or base 2. Each computer has, like your vcr, a set of instructions that it can follow.

These instructions are just binary numbers.

   For Example:
       100011 01001 01000 0000 0100 1011 0000
       000000 10010 01000 0100 0000 0010 0000
       101011 01001 01000 0000 0100 1011 0000
   are the machine instructions to add two numbers on a MIPS machine.
With the first electronic computers (ca 1950), programmers wrote this code and inserted it into the computer via toggle switches.

This is called Machine Language. This was:

What does it mean when two computers are binary compatible?
It is easier to remember words than numbers so someone came up with the idea of using words to represent the numbers.
   Example:
        lw  $t0, 1200($t1)
	add $t0, $s2, $t0
	sw  $t0, 1200($t1)
   The above example in MIPS assembly language
This is called assembly language, and a program that translates assembly language into machine language is called an assembler

Assembly language is


There are problems with assembly language, especially when you are writing large programs or programs that you want to move between machines. The next step in language development was high level languages.

High level languages use either a compiler or an interpreter to turn them into machine language.

This is a simplified view of this process, but it will do for now.

High level languages tend to be:

Some high level languages are:

In this class we will be learning C++.


What can a programming language do?

The operations a computer can perform: A programming language gives you access to these operations.

The most simple construct in a programming language is a sequence of instructions

   Example: Fahrenheit to Celsius conversion:
         read temperature in Fahrenheit
	 subtract 32 from that number
	 divide the result by 9
	 multiply the result by 5
	 write the result as temperature in Celsius
Languages also support decision making (in a simple form)
    Example: Military time to AM/PM time
         read in the military time
	 is the time greater than 1259
	     newtime is oldtime minus 1200
	 otherwise
	     newtime is oldtime
	 is the military time greater than 1200 but less than 2400?
	     ending is PM
	 otherwise 
	     ending is AM
Languages also support looping, or repeating tasks:
      Example: Find the average of 10 numbers
                set total to 0 
		set numberofnumbers to 0
          top:  read in a number
	        add the number to total
		add one to numberofnumbers
		is numberofnumbers less than 10?
		   goto top

	        divide  total by 10
		write the result