0% found this document useful (0 votes)
67 views92 pages

TOPIC 1.0 INTRODUCTORY TO PROGRAMMING - Farah

This document provides an introduction to C programming, including: - A description of C programming and its history and popularity. - An overview of the development of C programming from earlier languages like B. - Examples of C programming code structure and components. - Explanations of compiling and executing C programs. - Learning outcomes related to understanding C programming basics.

Uploaded by

nurul iqin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views92 pages

TOPIC 1.0 INTRODUCTORY TO PROGRAMMING - Farah

This document provides an introduction to C programming, including: - A description of C programming and its history and popularity. - An overview of the development of C programming from earlier languages like B. - Examples of C programming code structure and components. - Explanations of compiling and executing C programs. - Learning outcomes related to understanding C programming basics.

Uploaded by

nurul iqin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 92

TOPIC 1 :

INTRODUCTORY TO
PROGRAMMING

NOR FARAHWAHIDA MOHD


NOOR
PROGRAMMING LANGUAGE

HISTORY TYPES

STRUCTURE
Learning Outcomes

Subtopic 1.1 REMEMBER PROGRAMMING


LANGUAGE

By the end of this subtopic, student should be able to:


 Describe C programming.
 Explain background of C programming.
 Describe sample of C programming.
 Explain compile and execute programs.
C PROGRAMMING
What is C programming?
– C is a general-purpose programming
language that is extremely popular, simple
and flexible. It is machine-independent,
structured programming language which is
used extensively in various applications.
– C was the basics language to write
everything from operating systems
(Windows and many others) to complex
programs like the Oracle database, Python
interpreter and more.
C PROGRAMMING
What is C programming?
– It is said that 'C' is a god's programming
language. One can say, C is a base for the
programming. If you know 'C,' you can easily
grasp the knowledge of the other
programming languages that uses the
concept of 'C'.
IEEE best 10 top programming
language in 2018
IEEE best 10 top programming
language in 2019
Learning Outcomes

Subtopic 1.1 REMEMBER PROGRAMMING


LANGUAGE

By the end of this subtopic, student should be able to:


 Describe C programming.
 Explain background of C programming.
 Describe sample of C programming.
 Explain compile and execute programs.
BACKGROUND OF C
PROGRAMMING
In the 1960s, Ritchie worked with several other
employees of Bell Labs (AT&T), on a project
called Multics. The goal of the project was to
develop an operating system for a large
computer that could be used by a thousand
users. In 1969, AT&T (Bell Labs) withdrew from
the project, because the project could not
produce an economically useful system. So the
employees of Bell Labs (AT&T) had to search
for another project to work on (mainly Dennis
M. Ritchie and Ken Thompson).
BACKGROUND OF C
PROGRAMMING
Ken Thompson began to work on the
development of a new file system (OS). He
wrote, a version of the new file system for the
DEC PDP-7 (minicomputer), in assembler.
Soon they began to make improvements and
add expansions. They used the knowledge from
the Multics project to add improvements. After a
while a complete system was born. Brian W.
Kernighan called the system UNIX, a sarcastic
reference to Multics. The whole system was still
written in assembly code.
BACKGROUND OF C
PROGRAMMING
The language B was developed in 1969 to 1970
by Ken Thompson. In the early days computer
code was written in assembly code. To perform
a specific task, you had to write many pages of
code. A language like B made it possible to
write the same task in just a few lines of code.
Because of the high-level of the B language,
code could be produced much faster than in
assembly language. UNIX also had an
interpreter for the programming language B.
BACKGROUND OF C
PROGRAMMING
• A drawback of the B language was that it did
not know data types. Everything was
expressed in machine words. Another
functionality that the B language did not
provide was the use of structures. The lag of
these things formed the reason for Dennis M.
Ritchie to develop the programming
language C.
BACKGROUND OF C
PROGRAMMING
So in 1971 until 1973 Dennis M. Ritchie turned
the B language into the C language, keeping
most of the language B syntax while adding
data types and many other changes. The C
language had a powerful mix of high-level
functionality and the detailed features required
to program an operating system. Therefore
many of the UNIX components were
eventually rewritten in C.
BACKGROUND OF C
PROGRAMMING
The programming language C was written
down, by Kernighan and Ritchie, in a now
classic book called “The C Programming
Language, 1st edition”. (Kernighan has said
that he had no part in the design of the C
language: “It’s entirely Dennis Ritchie’s work”.
But he is the author of the famous “Hello,
World” program and many other UNIX
programs).
BACKGROUND OF C
PROGRAMMING
For years the book “The C Programming
Language, 1st edition” was the standard on the
language C. In 1983 a committee was formed
by the American National Standards Institute
(ANSI) to develop a modern definition for the
programming language C (ANSI X3J11). In
1988, they delivered the final standard definition
ANSI C. (The standard was based on the book
from K&R 1st ed.).
BACKGROUND OF C
PROGRAMMING
The standard ANSI C made little changes on
the original design of the C language. (They
had to make sure that old programs still worked
with the new standard). Later on, the ANSI C
standard was adopted by the International
Standards Organization (ISO). The correct
term should therefore be ISO C, but everybody
still calls it ANSI C.
REFLECTION
• What value you learn from history of C
language?
Learning Outcomes

Subtopic 1.1 REMEMBER PROGRAMMING


LANGUAGE

By the end of this subtopic, student should be able to:


 Describe C programming.
 Explain background of C programming.
 Describe sample of C programming.
 Explain compile and execute programs.
SAMPLE OF C PROGRAM
SAMPLE OF C PROGRAM
Begin block Preprocessor /
header file
Comment

Function name
Comment

Function body
End block
Comment statement

Standard Input Output Header (Library)

Function for printing text End of statement

End of function Insert a new line


Function starts

Begin of program
Learning Outcomes

Subtopic 1.1 REMEMBER PROGRAMMING


LANGUAGE

By the end of this subtopic, student should be able to:


 Describe C programming.
 Explain background of C programming.
 Describe sample of C programming.
 Explain compile and execute programs.
COMPILE
When programmers create software programs, they
first write the program in source code, which is written
in a specific programming language, such as C or Java.
These source code files are saved in a text-based,
human-readable format, which can be opened and
edited by programmers.

However, the source code cannot be run directly by


the computer. In order for the code to be recognized by
the computer's CPU, it must be converted from source
code (a high-level language) into machine code (a
low-level language). This process is referred to as
"compiling" the code.
COMPILE
Compile refers to the act of converting programs
written in high level programming language, which is
understandable and written by humans, into a low level
binary language understood only by the computer.

To compile, you need a compiler, which is a software


program that converts high level programming
language code into machine code.
EXECUTE
In computers, to execute a program is to run the
program in the computer, and, by implication, to start it
to run. A computer processor executes an instruction,
meaning that it performs the operations called for by
that instruction. Typically, we don't say that a program
is executing; we say that it is running.

An executable file is a file that contains a program -


that is, a particular kind of file that is capable of being
executed or run as a program in the computer.
Usually has a file name extension of .bat, .com, or .exe.
Learning Outcomes

Subtopic 1.2 REMEMBER definition and types of


programming

By the end of this subtopic, student should be able to:


 Define programme, programmer and programming
language.
 Describe various types of programming languages.
PROGRAMME
A set of instructions that tells the computer what to do.
For example, a word processor is a program written in
computer language like C, which tells the computer
what to do when you type in a letter.
PROGRAMMER
• A person who writes a program so that data may be
processed by a computer.
PROGRAMMING LANGUAGE
• A programming language is an artificial language
designed to express computations that can be
performed by a machine, particularly a computer.
Programming languages can be used to create
programs that control the behaviour of a machine.
Learning Outcomes

Subtopic 1.2 REMEMBER definition and types of


programming

By the end of this subtopic, student should be able to:


 Define programme, programmer and programming
language.
 Describe various types of programming languages.
TYPES OF PROGRAMMING
LANGUAGES

MACHINE ASSEMBLY
LANGUAGE LANGUAGE

HIGH LEVEL
LANGUAGE
MACHINE LANGUAGE
Machine language as the lowest-level programming
language is the only language understood by
computer. While easily understood by computer,
machine language is the almost impossible for
humans to use because they consist entirely of
numbers (comprised of only two characters: 0 and 1).
MACHINE LANGUAGE
Different for each type of CPU, it is the native binary
language of the computer and is difficult to be read
and understood by humans. Programs written in high-
level languages are translated into assembly language
or machine language by a compiler. Assembly
language programs are translated into machine
language by a program called an assembler.
MACHINE LANGUAGE
Every CPU has its own unique machine language.
Programs must be rewritten or recompiled, therefore, to
run on different types of computers. For example, a
program written in Apple PC cannot be run in IBM PC.
ASSEMBLY LANGUAGE
An assembly language is a low-level programming
language for a computer. Assembly languages have
the same structure and set of commands as machine
languages, but they enable a programmer to use
names instead of numbers.
ASSEMBLY LANGUAGE
Each type of CPU has its own machine language and
assembly language, so an assembly language program
written for one type of CPU won't run on another.

In the early days of programming, all programs were


written in assembly language. Now, most programs are
written in a high-level language such as C language.

Programmers still use assembly language when speed


is essential or when they need to perform an
operation that isn't possible in a high-level language.
HIGH LEVEL LANGUAGE
A programming language such as C, FORTRAN, or
Pascal that enables a programmer to write programs
that are more or less independent of a particular type
of computer.

Such languages are considered high-level because


they are closer to human languages and further from
machine language. In contrast, assembly language is
considered low-level because they are very close to
machine languages.
HIGH LEVEL LANGUAGE
The main advantage of high-level languages over low-
level languages is that they are easier to read, write,
and maintain. Ultimately, programs written in a high-
level language must be translated into machine
language by a compiler or interpreter.

The first high-level programming languages were


designed in the 1950s. Now there are dozens of
different languages, including BASIC, C, C++, Pascal,
FORTRAN, COBOL and Java.
Learning Outcomes

Subtopic 1.3 UNDERSTAND TYPES OF


PROGRAMMING AND STRUCTURE
PROGRAMMING METHODOLOGY

By the end of this subtopic, student should be able to:


 Explain structured programming, modular
programming, object-oriented programming.
STRUCTURED
PROGRAMMING
A technique for organizing and coding computer
programs in a hierarchy concept, each having a single
entry and a single exit point, and in which control is
passed downward through the structure without
unconditional branches to higher levels of the structure.

Three types of control flow are used: sequential, test,


and iteration. The most popular structured
programming languages include C, C++, Ada and
Pascal.
STRUCTURED
PROGRAMMING
MODULAR PROGRAMMING
Modular programming is the process of subdividing a
computer program into separate sub-programs.
MODULAR PROGRAMMING
Similar functions are grouped in the same unit of
programming code and separate functions are
developed as separate units of code so that the code
can be reused by other applications.

Modular programming enables multiple programmers


to divide up the work and debug pieces of the program
independently.
MODULAR PROGRAMMING
Languages that support the module concept are IBM
Assembler, COBOL, RPG, FORTRAN, Morpho, Zonnon
and Erlang, among others.
The benefits of using modular programming include:
– A single procedure can be developed for reuse, eliminating
the need to retype the code many times.
– Programs can be designed more easily because a small team
deals with only a small part of the entire code.
– The code is stored across multiple files.
– Code is short, simple and easy to understand.
– Errors can easily be identified, as they are localized to a
subroutine or function.
– The same code can be used in many applications.
OBJECT-ORIENTED
PROGRAMMING
Object-oriented programming (OOP) is a programming
paradigm that uses "objects" as data structures that
consist of data fields and methods together with their
interactions.
OBJECT-ORIENTED
PROGRAMMING
Simulation was the first object-oriented programming
language. Java, Python, C++, Visual Basic .NET and
Ruby are the most popular OOP languages today.

The Java programming language is designed


especially for use in distributed applications on
corporate networks and the Internet.

Ruby is used in many Web applications.

Curl, Smalltalk, Delphi and Eiffel are also examples of


object-oriented programming languages.
REFLECTION
1. Download Moodle app
2. Search DEC20012. Click Access.
enrollment key:
DET2A@azhani
enrollment key:
DET2D@azhani
3. Click
Programming language

algorithm flowchart

pseudocode
Learning Outcomes

Subtopic 1.4 REMEMBER algorithm, flowchart and


pseudocode

By the end of this subtopic, student should be able to:


 Define algorithm in programming.
 Identify flowchart in programming.
 Identify pseudocode in programming.
ALGORITHM
Definition
– Techniques of selecting program statements
and their logical sequencing which
emphasize the translating of each step
program outline into one or equivalent C++
instruction.
Types
– Flowchart
– Pseudocode
FLOWCHART
Definition
Represent algorithm in
graphic from comprising
of geometrical symbols
which in interrelated by
line of flow. It give a step
by step solution to a given
problem.
flowchart
Graphic representation of algorithm is known as
flowchart which consist of geometric symbols.

These symbols are connected by line of arrows called


flowlines which indicate the direction of flow of
processes or activities.

The shape of the symbol indicates the type of


operation that is to occur.

Flowchart should flow from the top of the page to the


bottom.
pseudocode
Program: Determine the price of discount item on sale.

Get price (Input)


Calculate : discount value = rate of discount * price (Process)
Calculate : price after discount = price – discount value (Process)
Display the price after discount (Output)

Merely writing down the steps to solve the problem in


the correct and logical order.
Uses the structural conventions but intended for
human reading rather than machine.
Purpose: it easier for people to understand and it
efficient an environmental-independent description of
an algorithm.
Learning Outcomes

Subtopic 1.5 UNDERSTAND algorithm, flowchart and


pseudocode

By the end of this subtopic, student should be able to:


 Explain flowchart symbols.
 Compare advantages and disadvantages of
flowcharts.
GEOMETRICAL SYMBOL FOR
FLOWCHART
Symbol Name Meaning
Used to connect symbols and
Flowline
indicate the flow of logic.
Used to represent the beginning
Terminal
(start) or the end (end) of a task.

Used for input and output


operations, such as reading
Input / Output
and printing. The data to be read
or printed are describe inside.

Used for arithmetic and data-


manipulation operations. The
Process
instruction are listed inside the
GEOMETRICAL SYMBOL FOR
FLOWCHART
Symbol Name Meaning

Used for any logic or comparison


operations. Has one entry and two
Decision exit paths. The path chosen
depends on whether the answer to
a question is “yes” or “no”

Connector Used to join different flowline.

Offpage Used to indicate that the flow chart


connecter continues to a second page.
Example
flowchart
Example
flowchart
Example
flowchart
Example
flowchart
Page 1

Page 2

Example
flowchart
START

terminal Display “How many


hours did you work?”

The terminator shows Read input hour.


where your process
begins or ends. Display “How much
do you get paid per
Use words like ‘Start’, hour?”

'End' inside the Read input rate.


terminator shape to
make things more Multiply hour by rate.
Store result in gross_pay.
obvious.
Display output
gross_pay.

END
START

Input output Display “How many


hours did you work?”

Input Output or Data Read input hour.


shows the inputs to and
outputs from a process. Display “How much
do you get paid per
This takes the shape of hour?”

a parallelogram. Read input rate.

Indicate input and


output operation. Multiply hour by rate.
Store result in gross_pay.

Display output
gross_pay.

END
START

process Display “How many


hours did you work?”

Process shape is used Read input hour.


to represent a process,
action step or an Display “How much
do you get paid per
operation. hour?”

Represented using Read input rate.


rectangles
Indicates a process Multiply hour by rate.
Store result in gross_pay.
such as a mathematical
computation or variable Display output
gross_pay.
assignment.
END
Stepping Through the START

Flowchart Display “How many


hours did you work?”

How many hours did you work? Read input hour.

Display “How much


do you get paid per
hour?”

Read input rate.

Multiply hour by rate.


Store result in gross_pay.

Variable contents:
Display output
hour: ? gross_pay.

rate: ?
END
gross_pay: ?
Stepping Through the START

Flowchart Display “How many


hours did you work?”

How many hours did you work? Read input hour.


8
Display “How much
do you get paid per
hour?”

Read input rate.

Multiply hour by rate.


Store result in gross_pay.

Variable contents:
Display output
hour: 8 gross_pay.

rate: ?
END
gross_pay: ?
Stepping Through the START

Flowchart Display “How many


hours did you work?”

How many hours did you work? Read input hour.


8
How much do you get paid per Display “How much
hour? do you get paid per
hour?”

Read input rate.

Multiply hour by rate.


Store result in gross_pay.

Variable contents:
Display output
hour: 8 gross_pay.

rate: ?
END
gross_pay: ?
Stepping Through the START

Flowchart Display “How many


hours did you work?”

How many hours did you work? Read input hour.


8
How much do you get paid per Display “How much
hour? do you get paid per
hour?”
20

Read input rate.

Multiply hour by rate.


Store result in gross_pay.

Variable contents:
Display output
hour: 8 gross_pay.

rate: 20
END
gross_pay: ?
Stepping Through the START

Flowchart Display “How many


hours did you work?”

How many hours did you work? Read input hour.


8
How much do you get paid per Display “How much
hour? do you get paid per
hour?”
20

Read input rate.

Multiply hour by rate.


Store result in gross_pay.

Variable contents:
Display output
hour: 8 gross_pay.

rate: 20
END
gross_pay: 160
Stepping Through the START

Flowchart Display “How many


hours did you work?”

How many hours did you work? Read input hour.


8
How much do you get paid per Display “How much
hour? do you get paid per
hour?”
20
160
Read input rate.

Multiply hour by rate.


Store result in gross_pay.

Variable contents:
Display output
hour: 8 gross_pay.

rate: 20
END
gross_pay: 160
Pseudocode TO FLOWCHART
Program: Determine the price of discount item on sale.

Read price (Input)


Calculate : discount value = rate of discount * price (Process) START
Calculate : price after discount = price – discount value (Process)
Display the price after discount (Output)
Read input price

discount_value = rate_of_discount *
price

price_after_discount = price –
discount_value

Display
price_after_discount.

END
Learning Outcomes

Subtopic 1.5 UNDERSTAND algorithm, flowchart and


pseudocode

By the end of this subtopic, student should be able to:


 Explain flowchart symbols.
 Compare advantages and disadvantages of
flowcharts.
Advantages of flowchart
Communicat
ion
• Flowcharts are better way of communicating the logic of a
system to all concerned or involved.
Effective
analysis
• With the help of flowchart, problem can be analysed in more
effective way therefore reducing cost and wastage of time.
Proper
documentati
on flowcharts serve as a good program documentation,
• Program
which is needed for various purposes, making things more
efficient.
Advantages of flowchart
Efficient
Coding
•The flowcharts act as a guide or blueprint during the
systems analysis and program development phase.
Proper
Debugging
•The flowchart helps in debugging process.
Program
Maintenance
•The maintenance of operating program becomes easy
with the help of flowchart.
Advantages of flowchart
Blueprint
• The flowchart plays the role of a guide or a blueprint. Which
makes program development process easier.
Convert
easily
• It is easy to convert the flowchart into any programming
language code as it does not use any specific programming
language concept.
Coding
• It helps the programmer to write the program code.
DISADVANTAGES OF
FLOWCHART
Complex
logic
• Sometimes, the program logic is quite complicated. Flowchart
becomes complex and clumsy, resulting in a waste of time and
money trying to correct the problem.
Modification
s
• If modification or alterations are required, the flowchart may
need to re-drawing completely. This will usually waste valuable
time.
Reproductio
n
• Flowchart symbols cannot be typed, reproduction of flowchart
becomes a problem. It is just a visualization of a program, it
cannot function like an actual program.
SCL activity
FLOWCHART ARTICLE
Form a group of three person. Discuss an
article about flowchart given by lecturer
in group.

After discussion, log on to CIDOS, give


your feedback at
Learning Outcomes

Subtopic 1.6 algorithm, flowchart, pseudocode and


analyze problems

By the end of this subtopic, student should be able to:


 Construct flowchart for the given problem.
 Apply flowchart for sequence structure, selection
structure and looping structure.
Construct flowchart
Question: Construct a flowchart that will multiply two
number enter by user.

Answer:
1. Identify input, process and output.
Input : number1, number2
Process : Calculate product = number1 x
number2
Output : product
2. Pseudocode
3. Flowchart
Construct flowchart

Program A : Find the sum of two numbers.

Read first number (Input)


Read second number (Input)
Calculate : sum = first number * second number (Process)
Display the price after discount (Output)

Program B : Convert temperature from Celsius to Fahrenheit.

Read temperature _C (Input)


Calculate : temperature _F = (9.0/5.0 x temperature _C) + 32
(Process)
Display temperature _F (Output)
Construct flowchart

Program C : Find Area and Perimeter of square.

Read length (Input)


Calculate : area = length * length (Process)
Calculate : perimeter = 4 * length (Process)
Display area and perimeter (Output)

Program D : Find Area and Perimeter of rectangle.


Program E : Find Area and Perimeter of circle.
Construct flowchart

Program F : Swap two number using temporary variable.

Read number_one (Input)


Read number_two (Input)
temp = number_one (Process)
number_one = number_two (Process)
number_two = temp (Process)
Display number_one and number two (Output)
Construct flowchart
Program G : Find the smallest of two numbers.

Read Num1 (Input)


Read Num2 (Input)
If Num1 < Num2 then (Decision)
smallest = Num1 (Process)
Else
smallest = Num2 (Process)
Display smallest (Output)

Program H : Find the largest of two numbers.


CONSTRUCT FLOWCHART
//This program is to display 4 inputs using
#include<stdio.h>
void main( )
{
int s1, s2, s3, s4;
printf("Please key in your BM mark for SPM :”);
scanf(“%d”, &s1);
printf("\nPlease key in your Math mark for SPM :”);
scanf(“%d”, &s2);
printf("\nPlease key in your Science mark for SPM :”);
scanf(“%d”, &s3);
printf("\nPlease key in your Moral/Pendidikan Islam for
SPM :”);
scanf(“%d”, &s4);
}
CONSTRUCT FLOWCHART
/*This program is to calculate and display your age now*/
#include<stdio.h>
int main( )
{
int x, y, age;
printf("\tPlease key in the year you borned:");
scanf("%d", &x);
printf("\n\tPlease key in the current years:");
scanf("%d", &y);
age=y – x;
printf("\n\t************************************");
printf("\n\tYour age now is: %d", age);
printf("\n\t************************************");
return 0;
}
CONSTRUCT FLOWCHART
/*Addition program*/
#include<stdio.h>
void main( )
{
int integer1, integer2, sum; /*declaration*/

printf("Enter first integer :"); /*prompt user for the


first integer*/
scanf("%d", &integer1); /*read user input*/
printf("Enter second integer :"); /*prompt user for the second

integer*/
scanf("%d", &integer2); /*read user input*/
sum=integer1 + integer2; //addition between
integer1 and
integer2
/syntax errors
QUIZ 1
 Define programme, programmer,
programming language.
 Describe various types of programming
languages.
 Explain the flowchart symbols.
 Compared the advantages and
disadvantages of flowcharts.
 Construct flowcharts for the given problem.
 Apply flowchart for sequence, selection and
looping structure.
92

You might also like