0% found this document useful (0 votes)
70 views

Chapter 1: Introduction: in This Chapter You Will Learn About

This document provides an overview of programming principles including: - An introduction to computer components, programming languages, and the differences between natural languages and formal programming languages. - Descriptions of different types of programming languages including machine language, assembly language, and high-level languages. - Details about C and C++ programming languages including their history and simple example programs.

Uploaded by

johnsonny
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Chapter 1: Introduction: in This Chapter You Will Learn About

This document provides an overview of programming principles including: - An introduction to computer components, programming languages, and the differences between natural languages and formal programming languages. - Descriptions of different types of programming languages including machine language, assembly language, and high-level languages. - Details about C and C++ programming languages including their history and simple example programs.

Uploaded by

johnsonny
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Principles of Programming

Chapter 1: Introduction
 In this chapter you will learn about:
 Overview of Computer Component
 Overview of Programming
 The different types of language
 Natural Language
 Formal Language
 Functional / Imperative Language
 Programming Languages

NI S2 2009/10
1
Principles of Programming

Overview of Computer Component


 Computer Hardware
 Computer Software

2
Principles of Programming

Overview of Computer Hardware

Ordered sequence
of storage location
(memory cell)

Components of a PC
3
Principles of Programming

Overview of Computer Software


 Operating System (OS)
 the collection of computer programs that control the
interaction of the user and the computer hardware.
 Application Software
 Programs developed to assist a computer user in
accomplishing specific tasks.
 E.g. Microsoft Word.
 In order to create new application software, we need
to write lists of instruction (program) to the computer
to execute.

4
Principles of Programming

What is Programming?
 Programming is instructing a computer to do
something for you with the help of a Programming
Language
 A programming language contains instructions for the
computer to perform a specific action or a specific
task:
 Display “I like programming”
 Display the current time

5
Principles of Programming

 Programming language is different compared to our


everyday-language (natural language); spoken and
written
 Does not have to be 100% correct but still understandable.
 Depends on circumstances; the context: one word can have
many meaning depending on the situation.
 For example: PUNCH

6
Principles of Programming

 Semantics – the meaning of the language within a


given context

 Syntax - Syntax are the rules to join words


together in forming a correct expression or phrase.
 In natural languages it is often possible to assemble a
sentence in more than one correct ways.

7
Principles of Programming

 Programming Language is a Formal Language used to


communicate to a computer.
 Very specific (one word means one thing – context free)
since to 'talk' to a computer; to instruct a computer; our
commands must be 100% clear and correct.
 Either Functional - tell what to do but not how (sum [1...10])
 or Imperative - describing the step by step to accomplish
the task (Take the first number and add the next number to
it; then add the next number to the sum; and …………; until
you have reached 10 as number to be added. Then print the
sum of all numbers)

8
Principles of Programming

Programming Language
 The two roles of a programming language:
 Technical: It instructs the computer to perform tasks.
 Conceptual: It is a framework within which we organize our
ideas about things and processes.
 In programming, we deal with two kind of things:
 Data - representing 'objects' we want to manipulate
 Procedures -'descriptions' or 'rules' that define how to
manipulate data.

9
Principles of Programming

Programming Language
 Can be classified into a special-purpose and general-
purpose programming languages.
 Special-purpose : is designed for a particular type of
application
 Structured Query Language (SQL)
 General-purpose : can be used to obtain solutions for
many types of problems.
 Machine Languages
 Assembly Languages
 High-Level Languages

10
Principles of Programming

Machine Language
 The only language that the processor actually
'understands‘
 Consists of binary codes: 0 and 1
 Example: 00010101
11010001
01001100
 Each of the lines above corresponds to a specific task to
be done by the processor.
 Programming in machine code is difficult and slow since it
is difficult to memorize all the instructions.
 Mistakes can happen very easily.
 Processor and Architecture dependent (different machine
language for different type of CPU) – not portable.
11
Principles of Programming

Assembly Language
 Enables machine code to be represented in words and
numbers.
 Example of a program in assembly language:
LOAD A, 9999
LOAD A, 9999 LOAD A,0111001100
9999
LOAD B, 8282 LOAD B, 8282
SUB B
LOAD
B
B, 8282
1000110011
Assembler
SUB 1001111001
SUB B MOV C, A MOV C, 1100110010
A

MOV C, A
 Easier to understand and memorize (called Mnemonics),
compared to machine code but still quite difficult to use.
 Cannot be processed directly by a computer, must be
converted to machine language using assemblers.
 Processor and Architecture dependent – not portable.

12
Principles of Programming

High-Level Language

13
Principles of Programming

Entering, translating, and running a


High-Level Language Program

14
Principles of Programming

Integrated Development Environment (IDE)


 A package that combines a simple word processor
with a compiler, linker and loader.

15
Principles of Programming

C Programming Language
Why 'C' ?
 Because based on 'B'; developed at Bell Laboratories

 Developed by Dennis Ritchie at Bell Laboratories in the


1960s

 In cooperation with Ken Thomson it was used for Unix


systems

 The C Language was only vaguely defined, not


standardized, so that almost everyone had his own
perception of it, to such an extend that an urgent need for
a standard code was creeping up
16
Principles of Programming

C Programming Language cont…


 In 1983, the American National Standards Institute (ANSI)
set up X3J11, a Technical Committee to draft a proposal
for the ANSI standard, which was approved in 1989 and
referred to as the ANSI/ISO 9899 : 1990 or simply the ANSI
C, which is now the global standard for C.

 This standard was updated in 1999; but there is no


compiler yet

17
Principles of Programming

C – An Imperative Language
 C is a highly imperative formal language
 We must tell it exactly how to do what;
 the means and functions to use;
 which libraries to use;
 when to add a new line;
 when an instruction is finished;
 in short: everything and anything…

 filename.c

18
Principles of Programming

C++ Programming Language


 Created by Bjarne Stroustrup at Bell Labroratories in
early 1980s
 Is an extension of the C language
 C++ contains all features of C and new features (C++ a
superset of C)
 C++ makes object-oriented programming possible.
 filename.cpp

19
Principles of Programming

A Simple Program in C

#include <stdio.h>

int main(void)
{
printf("I like programming in C.\n");
return (0);
}

20
Principles of Programming

A Simple Program in C - explanation


#include <stdio.h>
standard Library, input-output, header-file

Beginning of the program

int main(void)
Start of Segment
{
Function for printing text

printf("I like programming in C.\n");


Insert a new line
return (0); End of statement

}
End of Segment

21
Principles of Programming

C Output

I like programming in C.

22
Principles of Programming

Summary

 We have seen some different types of languages;


 the relevance of semantics and syntax.

 We have observed the detail necessary in an


imperative language to instruct a computer properly.

 Finally, we examined the syntax to print a line of text


to the screen of our computer.

23

You might also like