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

Chapter 1 Intro

This document provides an overview of a computer programming and applications course. It includes the instructor's contact information and outlines the course contents. The contents include basic programming concepts, the program development process, and program control structures. Under basic concepts, it defines terms like computer programming, programs, languages, compilers, and algorithms. It also explains the program development process of problem analysis, design, coding, testing and documentation.

Uploaded by

Haizmeer Bonzie
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
579 views

Chapter 1 Intro

This document provides an overview of a computer programming and applications course. It includes the instructor's contact information and outlines the course contents. The contents include basic programming concepts, the program development process, and program control structures. Under basic concepts, it defines terms like computer programming, programs, languages, compilers, and algorithms. It also explains the program development process of problem analysis, design, coding, testing and documentation.

Uploaded by

Haizmeer Bonzie
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 52

COMPUTER

PROGRAMMING AND
APPLICATIONS
(CSC430)

Assoc. Prof. Zaidah Ibrahim


Office: CS2-T1-28
[email protected]
INTRODUCTION
Chapter One
CONTENTS
 Basic Concept
 Program Development Process

 Program Control Structure

3
BASIC CONCEPT
 Computer Programming
 Program

 Programmer

 Programming Language
 Compiler

 Interpreter

 Interactive Programming Environment


 Algorithm

4
BASIC CONCEPT

Reasons for studying Concepts of Programming


Languages :

1. Increased capacity to express ideas and solve problems.


 Studying programming languages may increase the
capacity and ability of students to express their ideas in a
formal, computational form.

2. Increased ability to automate process


 Programs are built mainly so that simple, or even
complicated processes to be executed automatically.
5
BASIC CONCEPT
 Computer programming
 Craft of developing a computer program.
 Require knowledge, skill and creativity.
 Both skill and knowledge in problem solving and
programming language.

6
BASIC CONCEPT
 Computer program
 Hanly [2001], “List of instructions that direct the
computer to transform information from one form to
another.”
 Information refers to the contains of specific memory
location.
 It is written using programming language.

7
BASIC CONCEPT
 Computer program
 Turn data (input) into useful information (output).
 Program uses variables to store data

Input Program Output

Storage
8
EXAMPLE 1
(INPUT – PROCESS – OUTPUT)

Number1 (40) Calculate Total (70)


Number2 (30) total

Number1 [ 40 ]

Number2 [ 30 ]
Total [70 ]

9
BASIC CONCEPT
 Programming Language
 A set of rules, words and symbols are used to write a
computer program.
 Generation of Programming language
 Machine language
 Assembly language

 High Level language (Pascal, C, C++, Java etc)

10
BASIC CONCEPT
 Machine Language
 Binary number codes understood by a specific CPU.
 Assembly Language
 Mnemonic codes that correspond to machine
language instructions

11
BASIC CONCEPT
 A Machine-language Program Fragment and Its
Assembly-Language Equivalent
Memory Address Machine-Language Assembly-Language
Instructions Instructions

00000000 00000000 CLA

00000001 00010101 ADD A

00000010 00010110 ADD B

00000011 00110101 STA A

12
BASIC CONCEPT
 Type of High-level languages
Language Application Area Origin Name
FORTRAN Scientific Programming Formula Translation

COBOL Business data Processing Common Business-Oriented


Language
Lisp Artificial Intelligent List processing

C System Programming Predecessor Language was named B

Prolog Artificial Intelligent Logic Programming

C++ Support objects and object Incremental modification of C (++ is


oriented programming the C incremental operator)

Java Supports Web Programming Originally name “Oak” 13


BASIC CONCEPT
 Compiler
 A program that translates a high-level language
program into machine language as a complete unit
 Interpreter
 A set of program that executes the instructions as
they were translated. Interpreter executes a
program from its high-level form.
 Interactive Development Environment
(IDE)
 A program that provides user with an environment
for editing, debugging and compiling the source
code the program on- line.
14
BASIC CONCEPT
 Source file
 A file containing a program written in a high-level
language; the input for the compiler
 Syntax
 Grammar rules of programming language
 Object file
 File of machine-language instructions that is the
output of a compiler
 Algorithm
 A precise step-by-step action to perform overall
task of the program.

15
BASIC CONCEPT
 Compilation Process

Source File Compiler Object File

(Input) (Output)

16
PROGRAM DEVELOPMENT PROCESS
 Computer programming is a process to develop
a computer program.
 5 steps:
1. Problem analysis,
2. Program design,
3. Coding,
4. Testing, and
5. Documentation.

17
PROGRAM DEVELOPMENT PROCESS
 Problem Analysis
 A process of identifying the output, processes and input
of a program.
 How to identify output?
 Nouns and adjectives
 Keywords – print, display, produce

 How to identify input?


 Nouns and adjectives
 Keywords – accept, enter, receive, read

 Define the storage (variable) and data type to hold data


 Outline the process
 Arithmetic or logic operation
 Input-Process-Output (IPO) chart as tool

18
PROGRAM DEVELOPMENT PROCESS
 Problem Analysis
 Evaluate the following problem statement and identify the
input and output.

Nation’s Air force has asked you to write a program to label


supersonic aircraft as military or civilian. Your program is to be
given the plane’s observed speed in km/h and its estimated length
in meters. For planes traveling in excess of 1100km/h, you will
label those longer than 52 meters “civilian” and shorter aircraft
as “military”. For planes traveling at slower speeds, you will
issue an “aircraft type unknown” message.

19
PROGRAM DEVELOPMENT PROCESS
 Input-Process-Output (IPO) chart
INPUT PROCESSING OUTPUT
 speed  Validate the speed and  Classification
 length length Can be one if the
following values

• Speed >1100km/h AND Civilian


length > 52m
• Speed > 1100km/h AND Military
length <= 52m
• Speed <= 1100km/h Aircraft type unknown

20
PROGRAM DEVELOPMENT PROCESS
 Program Design
 Developing an algorithm
 Tools used for Program Design are:-
 Flow Chart
 Pseudo Code

21
PROGRAM DEVELOPMENT PROCESS
 Algorithm is a precise step-by-step action to
perform overall task of the program.
 Can be represented either using flowchart or
pseudo-code

22
PROGRAM DEVELOPMENT PROCESS

 A set of symbols and edges used in flow chart:

Terminal (Begin and End) Condition/Evaluation

To represent the process

Direction
Input/Output Operation

Example
23
EXAMPLE 2 (FLOW CHART)

Begin

Read two
numbers

Calculate Total

Print Total

End 24
PROGRAM DEVELOPMENT PROCESS
 Flow chart
Begin

Read Speed

Read Length

False
Speed > 1100

True
False
Length > 52
Classification = “Aircraft Type Unknown”
True Classification = “Military”

Classification = “Civilian”

Display classification

End 25
PROGRAM DEVELOPMENT PROCESS
 Desk-Check the algorithm
Speed Length Classification
1170 35 ?
1180 56 ?
900 66 ?
800 34 ?

26
PROGRAM DEVELOPMENT PROCESS
 Coding
 Implement the flowchart or pseudo code into specific
programming language rules (syntax)
 Identify the storage requirement
 Compilation
 Error correction
 Syntax Error,
 Logic Error or

 Runtime Error

27
SOURCE CODE
#include <iostream.h>
#include <string.h>
//program to classify the type of aircraft
main()
{
int speed, length;
char classfication[30];

cout << “Enter Observed speed : ”;


cin >> length;
cout << “Enter estimated length : ”;
cin >> length;

if (speed > 1100)


if (length > 52)
strcpy(classification,“civilian”);
else
strcpy(classification,“Military”);
else
strcpy(classification,“Aircraft type unknown”);

cout << “Classification is ” << classification << endl;

return 0;
}//end main()
28
PROGRAM DEVELOPMENT PROCESS
 Testing
 Program must be freed from syntax error
 Use a set of test data to validate the output.
 Program must produce receive valid input and produce
correct output.
 Program must handle invalid input efficiently.

 Does the program accept out of range value?

29
PROGRAM DEVELOPMENT PROCESS
 Documentation
 User manual
 Program description
 capability, limitation, user guide

30
PROGRAM CONTROL STRUCTURE
 There are SIX basic operation:
1. Accept Input through keyboard or files
2. Produce Output and displayed it on screen of file
3. Assign value to a storage
4. Perform arithmetic and logic
5. Make decision using selection statement
6. Repeat the same action

31
PROGRAM CONTROL STRUCTURE
 THREE types of control structure:
 Sequential Structure
 Selection Structure
 Iteration Structure (Repetition or loop)

32
PROGRAM CONTROL STRUCTURE
 Sequential Structure
 ALL statement(s) will be executed from top to bottom.
 Statement can be an input/output statement or a
processing statement.

33
PROGRAM CONTROL STRUCTURE

 Sequential Structure

Begin

Statement 1

Statement 2

Statement n

End
34
PROGRAM CONTROL STRUCTURE
 Sequential Structure (Flow Chart)

Begin

Read Number1,
Number2

Compute Total

Compute Average

Print Total
and Average

End 35
PROGRAM CONTROL STRUCTURE
 Selection Structure
 Provides alternative actions
 Only one action will be executed

 Three types:
 One-way Selection
 Two-way Selection
 Multi-way Selection

36
PROGRAM CONTROL STRUCTURE
 One-way Selection
 A set of statements will be executed if and only the
condition is TRUE.
 Two-way Selection
 Either one of two set of statements will be
executed if the condition is TRUE.
 Multi-way Selection
 Has more than one conditions and alternative set
statements.

37
PROGRAM CONTROL STRUCTURE

 One-way Selection (Flow Chart)


Begin

FALSE
Condition

TRUE

Statement (s)

End
38
PROGRAM CONTROL STRUCTURE

 One-way Selection (Example)


Begin

Read Score

FALSE
Score >= 50

TRUE

Status is “Passed”

End 39
PROGRAM CONTROL STRUCTURE

 Two-way Selection (Flow Chart)


Begin

FALSE
Condition

TRUE

Statement (s) Statement (s)

End
40
PROGRAM CONTROL STRUCTURE

 Two-way Selection (Example)


Begin

Read Score

FALSE
Score >= 50

TRUE

Status is “Passed” Status is “Failed”

End 41
PROGRAM CONTROL STRUCTURE

 Two-way Selection (Example)


Begin

Read Score

FALSE
Score >= 50

TRUE

Status is “Passed” Status is “Failed”

End 42
PROGRAM CONTROL STRUCTURE

 Multi-way Selection (Flow Chart)


Begin

FALSE
Condition 1

TRUE FALSE
Condition 2
Statement (s)
TRUE FALSE
Condition n
Statement (s)
TRUE

Statement (s) Statement (s)

End
43
PROGRAM CONTROL STRUCTURE

 Multi-way Selection (Example)


Begin

FALSE
code = ‘M’

TRUE FALSE
code = ‘F’
gender is “Male”
TRUE

gender is “Female” Status is “Unknown”

End 44
PROGRAM CONTROL STRUCTURE
 Iteration or loops
 Perform the same operation more than once
 A set of statements will be executed more than once
 Example – Read 40 students’ score and compute the
total.
 Can be controlled either by counter or sentinel
value.

45
PROGRAM CONTROL STRUCTURE
 Counter Controlled loop flowchart:

Initialize counter

False
Test

True Exit loop


Statement(s)

update counter

46
PROGRAM CONTROL STRUCTURE
 The following flowchart illustrate the process of
reading five (5) numbers and calculate the total

count = 0

False
count < 5
True
exit loop
Read a
number

Add number to total

Count + 1 47
PROGRAM CONTROL STRUCTURE
 Sentinel Controlled loop flowchart:

False
Test
Sentinel value

True

Statement(s)

Exit loop

48
PROGRAM CONTROL STRUCTURE
 The following flowchart illustrate the process of reading a
series of students’ scores and compute the total score. The
process will stop if the value of score read is equal to 999.

Read score

False
Score <> 999?

True Exit loop

Add score to total

Read Score

49
PROGRAM CONTROL STRUCTURE
 What are the differences between counter
controlled loop and sentinel controlled loop?

50
SELF EXERCISE

1. Write a flow chart to calculate and display an average of


three numbers using sequential design
2. Rewrite the above design, determine whether the average
is higher than 50 or not. Display the appropriate message
for each case.
3. Rewrite problem 1 using iteration any iteration approach.
4. Write a flow chart to calculate an average score of 20
students.
5. Write a flow chart to calculate an average of a series
positive numbers. The process will stop if number entered
has a negative value.
6. The cost to send a telegram to UK is RM15.50 for the first
15 letters and RM0.50 for the subsequent letters. Draw a
flowchart to calculate the cost of sending the telegram.
51
REFERENCES
 Jeri R. hanly, Essential C++ for Engineers and
Scientists, 2nd Edition, Addison Wesley
 J. Glenn Brookshear, Computer Science An
Overview, 8th Edition, Pearson Addison Wesley

52

You might also like