agenda computer languages –machine language –high-level programming language –features of c...

18
Agenda Computer Languages Machine Language High-Level Programming Language Features of C Programming Language How to Write a Simple C Program How to Record a C Program (typescript)

Upload: marvin-hensley

Post on 21-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Agenda

Computer Languages– Machine Language– High-Level Programming Language– Features of C Programming Language

How to Write a Simple C Program How to Record a C Program (typescript)

Page 2: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Computer Programs

A program is a set of instructions to tell the computer what to do.

In order to better understand the programming process, we will first see how computer programs have developed over the past 50 years.

Page 3: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Computers

Computers are electronic devices that transfer and store data in wires (or gates).

Because the computer is an electronic device, the data within these wires or gates are either ON or OFF (like a light switch).

A collection of these ON and OFF combinations are used to represent data in the form of binary code(eg 010100001010111 )

Page 4: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Evolution of Programs

Early programmers needed to write programs using binary code or “machine language” to tell the computer to perform various tasks

Although the computer finds machine code efficient to perform tasks, early programmers found writing programs in machine code tedious and time-consuming.

Page 5: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Evolution of Programs Grace Hopper, while working for

the U.S. Navy in the 50’s developed a program to convert programs written in symbols to machine language - this was more convenient than writing a program using machine language.

This program used symbols to represent operations. Unfortunately, these programs didn’t work on all computers

Page 6: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Evolution of Programs High-level languages were developed to allow the program

to be run on many different computer systems. These “high-level” languages are considered “portable” programming languages since they can run on many different computers.

The programs are written in a form easily understood by the programmers (source code) and then a “compiler” program converts the source code into machine code to be run by the computer.

Examples of high-level languages: FORTRAN, COBOL & C

Page 7: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

C Programming Language

The C programming language was developed by Dennis Ritchie at Bell AT&T labs in the early 1970s.

Dennis Ritchie and Ken Thompson used the C programming language to rewrite the UNIX operating system in 1973.

This contributed to the portability and popularity of C as UNIX operating system became widely accepted.

Page 8: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Features of C Programming Language

C is portable (can write and compile C programs on many different computer systems without major adjustments)

C is powerful, but also efficient. C conforms to the ASNI standard for

programming languages C provides the basis for more complex

programming languages such as C++

Page 9: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Steps to Create a Program

Step 1: Determine the requirements for the program (inputs, outputs, formulas)

Step 2: Plan out on paper the logic of the program (flowchart, pseudo code)

Step 3: Use Text editor to enter program (Source Code) Step 4: Walk through program’s logic and

syntax (look for errors) Step 5: Compile the source code into an executable file Step 6: Run the executable file & test the program’s

logic as much as possible.

Page 10: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Debugging a Program

Debugging a program is the process of finding and removing errors from your program if it fails to compile or run properly

The compiler will NOT create an executable file if the source code contains syntax errors (but compiler will give error messages to help solve problem)

If you can compile your source code, errors can still occur due to improper logic, structure, or design approach.

Page 11: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Writing a Simple C Program

#include <stdio.h> main () { printf (“Hello World!\n”); }

Indicates to include a file that provides “standard input / output” functions (printf, scanf) which will be linked when source file is compiled

Page 12: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Writing a Simple C Program

#include <stdio.h> main () { printf (“Hello World!\n”); }

Indicates main function or “main part” of the program. All C programs have one main function. Note alllowercase. Syntax may also allow:main (void)int main (void)

Page 13: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Writing a Simple C Program

#include <stdio.h> main () { printf (“Hello World!\n”); }

Notice braces follow the main function. Other functions or commands are placed within these brackets to be executed when main function is run or “called”

begin

end

Page 14: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Writing a Simple C Program

#include <stdio.h> main () { printf (“Hello World!\n”); }

Notice how commands within braces are indented to “stand-out”. This allows programmers to be able to easily read code. Indenting is very important!

Page 15: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Writing a Simple C Program

#include <stdio.h> main () { printf (“Hello World!\n”); }

The printf command allows the display of output to be formatted: Some special codes include:\n - new line\t - tab (indent)\a - beep (alarm) Note: lowercase

Page 16: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Writing a Simple C Program

#include <stdio.h> main () { printf (“Hello World!\n”); }

Most C commands end with a semi-colon.

Page 17: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Writing a Simple C Program

Task: Write a C program to display the following

information on a separate line:– Your name – Your student number – Your section – Tell us about yourself

Page 18: Agenda  Computer Languages –Machine Language –High-Level Programming Language –Features of C Programming Language  How to Write a Simple C Program

Typescript

The script command in the Unix operating system is like a “tape recorder”: Entering command script starts recording all output on screen is saved to a file called typescript Entering command exit stops recording

Refer to Assignment #0 for practice of printing out - Assignment is not for marks.