26
Introduction to Programming Using C Introduction to Computer Programming

Introduction to Programming Using C Introduction to Computer Programming

Embed Size (px)

Citation preview

Page 1: Introduction to Programming Using C Introduction to Computer Programming

Introduction to Programming Using C

Introduction to Computer Programming

Page 2: Introduction to Programming Using C Introduction to Computer Programming

2

Contents

Computers Programming

Page 3: Introduction to Programming Using C Introduction to Computer Programming

3

What is a Computer ?

We live in a world of electronic devices

Not all of these are computers

What makes a computer different from the other devices?

Page 4: Introduction to Programming Using C Introduction to Computer Programming

4

What is a Computer ?

A computer can– Receive data from the outside world– Process this data in some way to compute results– Store data for varying periods of time– Output results to the outside world– Allow the user to have the computer remember a

series of operations to perform so that the same thing can be done again

Page 5: Introduction to Programming Using C Introduction to Computer Programming

5

How does this differ from a calculator?

A calculator can– Accept input from the world via the

keys– Perform calculations by pressing keys– Store values in its memory– Output results

A calculator cannot– Store a series of operations to be

performed later

Page 6: Introduction to Programming Using C Introduction to Computer Programming

6

Programmability

The ability to store a series of operations and perform them later is called programmability

It is programmability which distinguishes a computer from a calculator

Programmability allows– Long sequences of operations to be stored– These sequences to be repeated any time– Conditional logic to be included

Page 7: Introduction to Programming Using C Introduction to Computer Programming

7

Conditional Logic

Conditional logic allows a computer to– Compare two values– Do different things depending on the result of the

comparison For example

– If customer age >= 65 Apply senior discount

– Otherwise Charge regular price

Page 8: Introduction to Programming Using C Introduction to Computer Programming

8

Hardware & Software

Hardware is– The physical parts of the computer

The keyboard and display The chips which make it work

Software is– The series of programs which are stored and instruct the

hardware to do what we want– This course is an introduction to how to write software

Firmware– Software permanently stored in the computer

Page 9: Introduction to Programming Using C Introduction to Computer Programming

9

What is Programming ?

Programming is the act of writing a computer program

This program will tell the hardware of the computer what operations need to be performed

These programs are written in one of several programming languages

Page 10: Introduction to Programming Using C Introduction to Computer Programming

10

Programming Languages

Much more precise than human languages Much smaller than human languages Many are based on a mathematical notation Take much less time to learn than a human

language

Page 11: Introduction to Programming Using C Introduction to Computer Programming

11

Programming

Computers are dumb They are glorified calculators Therefore

– They do exactly what they are told to do– You must be very careful that you tell them to do

the right thing– This requires attention to detail

Page 12: Introduction to Programming Using C Introduction to Computer Programming

12

Programmers

Many people do not have the patience to program computers

Many people do not like to deal with the low-level details of programming computers

People who like math often like programming However, there is another group who never

liked math but like programming

Page 13: Introduction to Programming Using C Introduction to Computer Programming

13

The Programmer Personality

Patient Persistent Precise Likes to figure out how to solve small

problems Can plan what is needed to solve a larger

problem Confidence that they can solve to problem

Page 14: Introduction to Programming Using C Introduction to Computer Programming

14

How much math do you need?

You need high school math You need to be good at basic math For some areas, like game programming,

you will need more math In general business programming, you need

relatively little math

Page 15: Introduction to Programming Using C Introduction to Computer Programming

15

Computer Architecture

Before looking at programming, it helps to understand how a computer works

A computer consists of– A Central Processing Unit (CPU)– Memory for storing short-term data– Disk drives for long-term storage– Keyboards for data input– Displays and printers for output

Page 16: Introduction to Programming Using C Introduction to Computer Programming

16

Computer Architecture

ProcessorProcessor

Control Control UnitUnit

Arithmetic Arithmetic Logic Unit (ALU)Logic Unit (ALU)

Arithmetic Arithmetic Logic Unit (ALU)Logic Unit (ALU)

InputInputDevicesDevices

StorageStorageDevicesDevices

OutputOutputDevicesDevices

CPU Interprets and carries out basic instructions that operate a computer

MemoryMemoryDataData InformationInformation

InstructionsInstructionsDataData

InformatioInformationn

InstructionsInstructionsDataData

InformatioInformationn

Control Control UnitUnit

Control unit directs and coordinates operations in computer

Arithmetic logic unit (ALU) performs arithmetic, comparison, and logical operations

Also called the processor

Page 17: Introduction to Programming Using C Introduction to Computer Programming

17

Data Representation

Recognize only two discrete states: on or off

Use a binary system to recognize two states

Use Number system with two unique digits: 0 and 1, called bits (short for binary digits)

Page 18: Introduction to Programming Using C Introduction to Computer Programming

18

Memory

Electronic components that store instructions, data, and results

Consists of one or more chips on motherboard orother circuit board

Each byte stored in unique location called an address, similar to seats in a concert hall

Page 19: Introduction to Programming Using C Introduction to Computer Programming

19

Storage Devices

Magnetic disk drive Floppy disk drive

CD / DVD Drive Tape Drive Flash Drive

Page 20: Introduction to Programming Using C Introduction to Computer Programming

20

Input / Output Devices

Monitors

Keyboards

Mice

Printers

Page 21: Introduction to Programming Using C Introduction to Computer Programming

21

The Programming Process

1. Gather the requirements1. You have to know what the program need to do

2. Analyze the requirements1. Read and understand what is needed

3. Design a solution1. Plan what the program will look like

4. Write the program5. Compile the program6. Test the program

Page 22: Introduction to Programming Using C Introduction to Computer Programming

22

Compilation

Computers do not speak C Each computer has its own language in the

same way that each calculator works slightly differently

A compiler is a program which translates C to the native language of the computer

You must compile the program before it can be executed

Page 23: Introduction to Programming Using C Introduction to Computer Programming

23

Writing the program

Writing the program is usually done with a text editor

Do not use a word processor Once the program is written, it is then

compiled

Page 24: Introduction to Programming Using C Introduction to Computer Programming

24

Testing the Program

Just because you write a program does not mean it is correct

It must be tested This executes the program with a variety of data and

then checks the results Locating te source of a problem is called debugging The program is modified to fix the bug, recompiled,

and tested again

Page 25: Introduction to Programming Using C Introduction to Computer Programming

25

The C Programming Language

One of many programming languages Written at AT&T in the 1970s Used to write the UNIX operating system Has become one of the most popular

programming languages Based on the concept of structured

programming

Page 26: Introduction to Programming Using C Introduction to Computer Programming

26

Problems with C

It is a low-level language Gives the user the ability to make mistakes

which are really hard to find Is not object-oriented

– Although it leads you into the next course where you will learn C++, the object-oriented version of C

– C is a subset of C++ and you must know C to study C++