This document discusses fundamentals of computer programming. It defines problem analysis, decision making, and logic flowcharts. It explains symbols used in flowcharts for processing, input/output, conditions, and branching. The document also discusses principles of problem analysis and decision making. It provides examples of writing algorithms for given problems.
This document discusses fundamentals of computer programming. It defines problem analysis, decision making, and logic flowcharts. It explains symbols used in flowcharts for processing, input/output, conditions, and branching. The document also discusses principles of problem analysis and decision making. It provides examples of writing algorithms for given problems.
This document discusses fundamentals of computer programming. It defines problem analysis, decision making, and logic flowcharts. It explains symbols used in flowcharts for processing, input/output, conditions, and branching. The document also discusses principles of problem analysis and decision making. It provides examples of writing algorithms for given problems.
COMPUTER PROGRAMMING FUNDAMENTALS OF COMPUTER PROGRAMMING
Principles of Problem Analysis
Define problem analysis Define decision making Define logic flowchart Identify the symbol used to indicate processing that needs to be done - setting up a line, doing a calculation, opening files, closing files etc Identify the symbol used to indicate that a paragraph is to be performed and then control will return to the next sequential command. The double lines indicate perform Identify the symbol used to indicate the beginning or end of a module or paragraph Identify the symbol used to indicate input/output - specifically the reading of a record from a file, the writing of a record on a file, or the writing of a line on a printed report FUNDAMENTALS OF COMPUTER PROGRAMMING
Identify the symbol used to indicate a condition - usually the
branch to the right means YES and the branch to the left or down indicates Identify the symbol used to branch when the bottom of the page has been reached - it is also used as an entry point to branch to Plan problem analysis and decision making Write logic flowchart Apply problem analysis Apply decision making Apply principles of logic flowcharts in relation to problem solving Draw a simple flow chart for a given problem Write suitable algorithms to produce a solution Write an algorithm for a given problem Introduction
Until now, we have worked with application software
that are mostly used for specific purposes like word processing, spreadsheets and databases. These applications provide predetermined functions and procedures that help the users to manipulate data and information based on their needs. In programming, we introduce computer programming which, in turn is the core component of computer science and software development. Software program and Computer programming
A software program (or simply ‘program’) is a set of
coded instructions that enables a computer to perform a sequence of tasks. Computer programming is the process of writing code or programs using a software programming language such as Java. Note: the coded instructions that a computer understands is called machine language, just like you understand the Samoan and the English language. In the next few slides you will learn basic programming concepts and apply your understanding by writing simple programs using the Java Programming language. 2 Types of Software Applications
1. COTS Software Application
Commercial off the shelf software Purchase without any modification being made. Examples: Microsoft Office Application 2. CSSA – Customer Specific Software Application Developed specifically for a certain customer
It has certain functionality that only specific customer can use.
E.g Bluesky, CSL and NUS
Programming Language Terminologies and Basic Concepts
Types of Computer Languages:
‘Language’ is the source of communication among human beings all over the world. Different countries/regions have their own language or a dialect that allow people to communicate and understand each other. Similarly, in order for communication to be possible between users and computers, a common language must be established. The computer only understands the machine language which is just a series of binary numbers. These binary numbers represent data, and instructions from the computer to manipulate and execute. Type of Computer Languages
For a typical user, reading and interpreting
binary numbers is not user friendly at all, this is why programming languages (high-level languages) were established. High-level languages are user-friendly and can be understood by users. Users write code using high-level languages, these codes represent instructions that are then interpreted and translated into machine language by interpreters and compilers. Types of Computer Languages
For this purpose, different languages are developed
for performing different types of work on the computer. Basically, languages are divided into three categories according to their interpretation. 1st Generation (Low-level or Machine Language) 2nd Generation (Assembly Language) 3rd Generation (High-level Language) 1st Generation (Low-level or Machine Language)
Is the lowest and most elementary level of computer
languages, and was the first type to be developed. Computers cannot understand instructions given in high level languages or in English. Machine language uses binary numbers to process and to store data. Instructions are made up of a series 1’s and 0’s making it look very primitive, and hard for humans to understand. 1st Generation (Low-level or Machine Language)
In fact, a manufacturer designs a computer to obey just
one language, its machine code, which is represented inside the computer by strings of binary digits (bits) 0 and 1. The binary 0 and 1 can have many interpretations by the computer circuit. One interpretation is that, the symbol 0 stands for the absence of electric pulse and 1 for the presence of an electric pulse. Since a computer is capable of recognizing electric signals, therefore, it understands machine language. Machine language makes fast and efficient use of computers and requires no translators to translate the code (i.e. directly understood by the computer). Example 01101010001011010100 010 0010 001 0010 0111 0010 1101 0000
Machine language makes fast and efficient use of
computers and requires no translators to translate the code (i.e. directly understood by the computer). 2nd Generation (Assembly language) Assembly language uses mnemonic symbols to represent instructions and data. It was developed to overcome some of the many inconveniences of machine language. This is another low level but a very important language in which operation codes and operands are given in the form of alphanumeric symbols instead of 0’s and 1’s. These alphanumeric symbols are known as mnemonic codes and can have up to 5 letter combination. e.g. ADD for addition, SUB for subtraction, LOAD, START, LABEL, etc. 2nd Generation (Assembly language) Because of this feature it is also known as ‘Symbolic Programming Language’. This language is also very difficult and needs a lot of practice to master it because very small English support is given to this language. The language mainly helps in compiler orientations. The instructions of the Assembly language will also be converted to machine codes by language translator to be executed by the computer. Example: load 10 r1 load 10 r2 mov edx, len move cx msg int 0x80 3rd Generation (High-level Language)
High level languages give formats close to the
English language. High-level languages are basically symbolic languages that use English words and/or mathematical symbols rather than mnemonic codes. Each instruction in the high level language is translated into machine language (compiling) for execution by the computer. Looks like Human Languages e.g. sum = 14 + 7; System.out.println(“Hi Samoa College!”); Compilers & Interpreters
A program written in high-level language is called a
source code. The source code needs to be translated into machine code in order for the computer to understand and to execute instructions. A compiler and interpreter, although they behave differently, both carry out the same purpose – they convert a high level language (like C++ and Java) instruction into the binary form which is understandable by the computer hardware. Therefore, they both act as translators between high- level languages and the machine languages. Main differences between a compiler and an interpreter
The interpreter translates and executes one
statement at a time, while the compiler translates the entire program in one go and then executes it. Compiler generates the error report after the translation of the entire page while an interpreter will stop the translation after it gets the first error. Overall execution time of code is faster for compiler relative to the interpreter. Problem Analysis in Programming
The process where we break down problems into its
components so that the problems can easily be understood. It is a way where problems are discussed for giving the solution. The way to do this is to write an Algorithm of the problem. Decision making in Programming
Decision making structures require that the
programmer specifies one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition determined to be false. What is an algorithm?
A set of precise instructions to perform a certain
task. If we take a task that we do everyday and express it in explicit discrete tasks line by line then in the end you have a list that you could give to nearly anyone and get the task done. Algorithm Example 1
Say you wanted to give someone an algorithm telling
them how to login to a computer in the labs: ➢ A solution can be: Find a vacant computer Sit down in front of it Turn the computer on Wait for the computer to boot up Press the Control-Alt-Delete keys Enter your username Press the Tab key Enter your password Press the OK button Algorithm Example 2
Making an easy Banana Cake:
This example is a typical simple algorithm for a banana cake recipe. Ingredients: 3 cups of self-rising flour, 2 cups sugar, 7/8 cup butter, 1 cup masked ripe banana, 1 cup milk, 2 eggs, 1 teaspoon vanilla extract, ½ tablespoon salt. Step 1: Preheat the oven (the oven should be preheated to 177˚C). Step 2: Melt butter, and beat it with eggs slightly. Step 3: Whisk together milk, sugar, banana and melted butter. Step 4: Add flour and the rest of the ingredients and mix them thoroughly. Step 5: Pour the mix into a greased baking pan. Step 6: Bake for 38 to 40 minutes. Step 7: Take the cake out of the oven when finished. Flow Charts
An algorithm can be written as a list of steps using
precise statements, or in pictorial form using shapes and arrows called a flowchart. A flowchart is a visual representation of the sequence of steps and decisions needed to perform a process. Each step in the sequence is noted within a diagram shape. Steps are linked by connecting lines and directional arrows. This allows anyone to view the flowchart and logically follow the process from the beginning to the end. Flow Chart Symbols
Flowcharts use special shapes to represent different types of actions or steps
in a process. Lines and arrows show the sequence of the steps, and the relationships among them. These are known as flowchart symbols.
Symbol Name Function
1 Start/End An oval represents a start or end point
2 Arrows A line is a connector that shows
relationships between the representative shapes. 3 Input/Output A parallelogram represents input or output 4 Process A rectangle represents a process
5 Decision A diamond represents a decision
Example Flow Chart: Finding the average of three integers The following flowchart represents an algorithm of finding the average of three integers. This example shows one input, two processes, and one output. The program start with prompting the user to input three integers, then sum up the three integers, calculate the average, and finally output the value of the average. Exercise: Algorithm & Flowcharts
Provide algorithms and flowcharts for each of the
following scenarios. Make your algorithm statements precise, and try to include a decision making in one of your flow charts. 1. Withdrawing money from an ATM 2. Fixing a broken tyre 3. Finding the area of a rectangle Note: Everyone has their own different algorithms in solving the above problems, hence there are more than one way of solving the problems at hand. Just remember, no matter how different the algorithms are, at some stage, they should all accomplish the main or the common objectives. Example of Decision making