cpsc 110 - pascal brent m. dingle texas a&m university chapter 1

50
CPSC 110 - Pascal Brent M. Dingle Texas A&M University Chapter 1

Upload: domenic-johns

Post on 31-Dec-2015

219 views

Category:

Documents


2 download

TRANSCRIPT

CPSC 110 - Pascal

Brent M. DingleTexas A&M University

Chapter 1

Chapter 1

Here we will present some basic definitions and describe how to use DOS and the Turbo Pascal Environment.

We will also look at a little history of Computer Science.

In the beginning…

There were rocks and sticks.

From that we now have computers.

How that came to be will be discussed more in the next Chapter, for now we need to establish some basic skills and definitions.

Program, Software, Hardware

A program is a set of instructions for a computer to follow.

Software is a collection of programs used by a computer.

Hardware is the actual physical machines that make up a computer installation.

Hardware – 5 Components

Input devices Output devices CPU (central processing unit) Main memory Secondary memory

Input Devices

An input device is any device that allows a person to communicate information to the computer.

Mouse, keyboard, microphone, etc.

Output Devices

An output device is anything that allows the computer to communicate information to the user.

Monitor, printer, speaker, etc. Notice the book refers to monitors as display

screens, video display terminals or VDTs. Do NOT confuse output devices with

secondary memory !!!

CPU – Central Processing Unit This is where the real ‘brain’ of the

computer is.

Some examples of CPU’s are the 8086, 486 DX 2, Pentium II, Pentium III, etc.

The CPU follows the instructions in a program and performs the necessary calculations.

Main Memory

This is where the computer temporarily stores information needed to perform its operations.

An example of this is RAM (random access memory).

Think of it as ‘scratch paper’ (with each line and page numbered).

Secondary Memory (storage)

Secondary memory is used for keeping a permanent record of information after (and before) the computer is used.

Such information is stored in files. For example an MS-Word document is saved

as a file, a program is saved as a file, a jpeg image is saved as a file, etc.

Secondary Memory (cont) Hard drives, floppy drives, tape drives and

Read/Write CD-ROMS would be examples of secondary memory.

Secondary Memory is also referred to as Auxiliary Memory or Auxiliary Storage.

We will see more about memory later.

Hardware (continued)

For most computers the CPU, main memory and secondary memory are placed together in some form of box.

The CPU and main memory are generally placed on a motherboard.

The secondary memory is now usually the hard disk drive, floppy disk drives and read/write CD-ROMS which ‘plug into’ the motherboard.

Hardware (continued 2) Notice in recent history we have

increased the number and quantity of input and output devices – for example speakers and video recording devices.

This has led to ‘cards’ being added to the motherboard, which allow the additional devices to be ‘plugged’ into the motherboard.

Software

If it’s not hardware, then it’s software. Here we will be looking at:

The Operating System Programs Data

Operating Systems

You communicate to with the computer through the operating system.

An operating system is really a program, but a specially designed one.

DOS, Windows, UNIX, and Linux are all Operating systems.

DOS stands for Disk Operating System.

Program

A program is a set of instructions for the computer to follow.

Data

The word data is often used in a variety of contexts.

The general meaning of data is any information available to the computer.

A more narrow usage of the word is in reference to the input to a program.

Programming Languages

High-level languages

Low-level languages

High level languages

High level languages are designed to be easily read by humans and to make programs easier to write.

Some examples are:Pascal, FORTRAN, BASIC, COBOL, C, Modula-2, Scheme and Ada.

High level languages (cont)

High level language instructions are usually much more complicated than the CPU can immediately understand, however humans can usually figure them out quickly.

High level languages (cont 2)

Most high level languages require a source code file to be created.

A source code file is just a text file with a ‘special’ extension.

For example the file: hello.pasis probably the source code file for a Pascal program that prints the message “hello.”

Low level languages

Low level language instructions are easier for the CPU to understand than for humans to understand.

Remember it this way:Computers think at a LOWER level than humans.

Low level languages (cont) An example of a low level language is

assembly language. An instruction would look like:

ADD X Y ZThis would add the contents of memory address X and the contents of memory address Y and store the result at memory address Z.

Obviously, right ? =)

Low level languages (cont 2)

An even lower level language than assembly is machine language.

In this language every instruction is a sequence of ones and zeros.

For example the assembly command ADD X Y Z might be: 0110 1001 1010 1011in machine language.

High versus Low

The important thing you need to keep straight is that Pascal is a high level language and machine code is a low level language.

So you might wonder how the computer understands high level languages…

Compilers

For the computer to understand a high level language, such as Pascal, the high level source code must be translated into low level object code by a compiler.

DOS

DOS stands for Disk Operating System

You should become familiar with some of the DOS commands as YOU WILL BE QUIZZED/TESTED on THEM.

DOS – capital and lowercase

DOS is NOT case sensitive – that means it does not care if you use capital or lowercase letters.

The filename Howdy.paS, HOWDY.PAS, and howdy.pas are all the same to DOS.

DOS Commands - Format

format a:will format the disk in drive a:

DOS Commands – dir

dirwill display the contents (files and subdirectories) of the current directory.

dir a:\ will display the contents of the root directory of drive a:

dir a:will display the contents of the current directory of drive a:

DOS Commands –changing drives If the current prompt is:

a:\>then the current drive is a:

To change to drive c: type:c: and press enter.The prompt will change to: c:\>(assuming the current directory of c is the root directory)

DOS Commands – type

type howdy.paswill display the contents of the file named howdy.pas (if it exists in the current directory)

DOS Commands – copy

copy oldfile.pas newfile.paswill copy the contents of oldfile.pas into the file newfile.pas (notice newfile.pas may be overwritten)

DOS Commands – CTRL-C

Pressing CTRL-C while a DOS program is running should stop the program.

DOS Commands – erase

erase dumbfile.paswill erase the file dumbfile.pas from the current directory (assuming it exists).

The more common command to do this today is del. For example:del dumfile.paswould also erase the file dumfile.pas from the current directory.

DOS Commands – rename

rename badname.pas newname.paswill rename the file badname.pas to newname.pas.

The move command does something similar. For example you could also say:move badname.pas newname.pasand achieve the same effect – with some subtle differences.

DOS Commands – diskcopy

diskcopy a: b:would copy ALL the contents of the disk in drive a: to the disk in drive b:

This of course assumes the two disks are the same ‘size’ (i.e. you could not copy an entire hard drive onto a 3.5” floppy).

DOS Commands – diskcomp

diskcomp a: b:will tell you if two disks are identical in content.

This is useful after you have done a diskcopy.

DOS Wildcards

The asterisk (*) and the question mark (?)act as wildcard characters in DOS.

The * represents zero to many characters. The question mark represents 1

character.

DOS Wildcards – usage

If you wanted to copy all the files with the .pas extension in the current directory of the c: drive to the a: drive you could type: copy c:*.pas a:

DOS Wildcards – usage

If you had the files:bob1.pas, bob2.pas, bob3.pas and bob5.txtand you wanted to copy all 3 of the pascal files to the a: drive you could type copy 3 times, or you could type:

copy bob?.pas a:

Directories DOS directories are tree structured, this

implies a hierarchical relationship among directories.

The top, or main directory, of a drive is the root directory.

DOS directories may contain files and/or subdirectories.

DOS – directory commands

mkdir (or just md)

rmdir (or just rd)

cd

DOS Commands – mkdir

mkdir newdircreates a new directory named newdir.

md newdiralso creates a new directory named newdir.

DOS Commands – rmdir

rmdir olddir removes the directory named olddir.

rd olddiralso removes the directory named olddir.

DOS Commands – cd cd

prints the current directory path.

cd \takes you to the root directory of the current drive.

cd mydirtakes you into the subdirectory named mydir

Full Path Name A full path name is a list of directories you would

pass through in going from the root directory to the file.

If the drive letter is known it IS part of the full path name.(do not be misled by the textbook)

The full path name ends with the filename.

Relative Path Name

A relative path name is a list of directories to a file relative to the current directory.

The relative path name ends with the filename.

Going up directories

The directory named “..”is the directory above the current.

So to move up a directory type:cd ..

Using the Turbo Pascal Environment

Please refer to the handout given in class and ATTEND THE LABS !

You will be quizzed/tested on how to use DOS and the Turbo Environment – so be prepared.