Programming Fundamentals

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
Advertisements

Chapter 2: Problem Solving
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Chapter 1 - An Introduction to Computers and Problem Solving
ITEC113 Algorithms and Programming Techniques
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
The Program Design Phases
PRE-PROGRAMMING PHASE
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Fundamentals of C programming
The University of Texas – Pan American
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
CSC141 Introduction to Computer Programming
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Flowcharts. Problem Solving Computer programs are written to solve problems or perform tasks Programmers translate the solutions or tasks into a language.
Flowcharts and Algorithms. Review of Terms  A computer is a machine that can represent and manipulate data –Ultimately the data and the instructions.
Introduction to Computer Application (IC) MH Room 517 Time : 7:00-9:30pm.
Algorithms & Flowchart
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Program Design BUILDING A HOUSE. Steps to Designing a Program 1. Define the Output 2. Develop the logic to get that output 3. Write the program.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CS 100 Introduction to Computing Seminar September 21, 2015.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Chapter 1 Introduction 2nd Semester H
Component 1.6.
ALGORITHMS AND FLOWCHARTS
Understand Problem Solving Tools to Design Programming Solutions
CSCI-235 Micro-Computer Applications
Computer Programming.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Understand Problem Solving Tools to Design Programming Solutions
Algorithms An algorithm is a sequence of steps written in the form of English phrases that specific the tasks that are performed while solving the problem.It.
Introduction To Flowcharting
Introduction to Computer Programming
Programming Fundamentals
Algorithm and Ambiguity
CS 240 – Lecture 11 Pseudocode.
Computer Programming.
Unit# 9: Computer Program Development
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
Introduction to Algorithms and Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 1 Introduction(1.1)
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 2- Visual Basic Schneider
Algorithm and Ambiguity
Flowcharting & Algorithms
Understanding Problems and how to Solve them by using Computers
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Flowcharts and Pseudo Code
Tonga Institute of Higher Education IT 141: Information Systems
An Introduction to Programming with C++ Fifth Edition
Tonga Institute of Higher Education IT 141: Information Systems
Chapter 2 – part a Brent M. Dingle Texas A&M University
Basic Concepts of Algorithm
1.3.7 High- and low-level languages and their translators
ICS103 Programming in C 1: Overview of Computers And Programming
Programming Logic and Design Eighth Edition
Introduction to Programming
Presentation transcript:

Programming Fundamentals Chapter 2 To be discussed in this chapter: Programs and Programming Languages The programming process (Complie Link and Run process) Source code , Object code, and Executable code The integrated development environment (IDE) Program Design Algorithms Flowcharting (Starting out with C++, appendix O) A brief look at the program development cycle

Overview of Programming 2.1 Overview of Programming

The Basics Program: a list of instructions that tells the computer how to solve a problem or perform a task. Programming: the act of defining these instructions. Programmer: the person doing the defining. User: the person who ultimately makes use of the program. (Examples??) These are just basic definitions to get started. Note: an alternate definition of Program also includes data (fixed data) together with the instructions Example– Students Teachers and Computers We learn to compute at a young age. At first we just add and subtract numbers. One plus one equals two. Five minus two is three. As we grow older we learn about additional mathematical operations, like exponentiation and sine, but we also learn to describe rules of computation. Given a circle of radius r, its circumference is r times two times pi. The truth is, our teachers turn us into computers and program us to execute simple computer programs. Computer programs are just very fast students, and we are their teachers

Remember Computers are digital devices that simply do what they are told. We must speak their language to tell them what to do. Does this mean, we should speak binary? ( 0’s and 1’s)?? ? ? Computers don’t understand English, Amharic, etc. The person teaching computers must speak a computer language. Instructions and data are all placed in the main memory Option A Place the 0’s and 1’s directly in memory ourselves => Extremely difficult This is programming at the machine language level Option B Represent meaningful groups of 1’s and 0’s with words and use that instead => Still difficult This is programming at the assembly language level Example: ADD A, B, C => (001101 0000 0001 0010) Machine language and assembly language are general referred to as Low Level Programming Languages Option C Use something that looks like English but is structured and logical enough to be converted into machine language by another program This is programming at the High Level Programming Languages level Example: A = B+C; (C++ is a High Level Language) Option D Use something very much like English and let the computer do the hard work of translation. This is programming at the Very High Level Programming Languages level Examples: SELECT telephone FROM users WHERE name LIKE “abebe” SQL, Prolog, etc… Very Domain Specific

Programming Languages Very High Level Languages (SQL, Prolog, …) High Level Languages (C++) As we go down, programming becomes more difficult In this course, we will speak to the computer in C++. It is a good compromise between a human language and what the computer understands Low Level Languages (Assembly, Machine Code)

Features of High Level Languages Designed to make programming easier Emphasis on logic Aids in the design process Independence (relatively) from the Operating System and Hardware One HLL instruction gets translated to multiple machine level instructions * Programming Easier – it is to think in C++ than in assembly or machine level * Emphasis on logic – the programmer focuses more on how the logic of the program should be rather than on how it is to be placed in memory (and more) * Aids in the design process – it is much efficient to put down our ideas interms of C++: the language itself helps us in designing our programs * OS and HW independence – the programs we write with C++ can be made to work on any OS and any HW. (atleast theoretically). But those written in low level languages are specific to a certain OS AND HW combination. * To accomplish a simple task with a low level language requires us to write multiple instructions whereas with C++, we can write a single instruction for a task and it will be translated accordingly.

The Programming Process Machine Code #include Int main( { … Compile LINK 10101001010101 Object Code Source Code RUN Libraries, Other Object Code How exactly do we program? 1. Using a text editor, write the program 2. Save it as a file (.cpp extension) 3. Fix any errors that you might have Compile your program into object code. If there are errors, go back to step 3 Run the linker to generate executable code. If there are errors, go back to step 3 6. Run (execute) your program and test it. If there are errors, go back to step 3. Btw, this is an algorithm for programming with C++. Algorithms will be discussed later. Source Code: The instructions written in C++. This is the only part that we can understand. Compiler: Translates the source code into some intermediate form Linker: links our object code with other object codes (libraries) to create our executable program. Run: An executable program, once converted into machine code, is ready to run on our computer.

IDE IDE stands for Integrated Development Environment Includes the compiler and the linker Has tools to assist the programmer Automates and simplifies the programming process For this course, we will be using the visual studio IDE and Eclipse.

2.2 Program Design

The Basics PROGRAMS = ALGORITHMS + Data Structures Niklaus Wirth Algorithm?? An effective procedure for solving a problem in a finite number of steps. The proper pronunciation of Niklaus Wirth is (Knee Close Veert) Programs = Algorithms + Data Structures is the title of his book. He is one of the most influential Computer Scientists of our time – he invented the Pascal programming language.

Program Development Algorithm Using a text editor, write the program Save it as a file (.cpp extension) Fix any errors that you might have Compile your program into object code. If compilation is successful, continue to step 6. If it fails, go back to step 3. Run the linker to generate executable code. If linking is successful, continue to step 8. Otherwise, go back to step 3. Run (execute) your program and test it. If there are errors, go back to step 3. Otherwise finish. This is an algorithm for developing programs. It is the 9 step solution to the problem of writing a program! You can also define algorithms as A well defined computational procedure that takes some value or set of values as input and produces some value or set of values as output. The algorithm is thus a sequence of computational steps that transform the input into the output. Exercise Making tea Coming to school Etc…

The Blueprint You can think of an algorithm as the blueprint (plan) of your program. Before you begin writing a program, you first have to understand the problem and then develop a step-by-step solution (the algorithm). Developing an algorithm to solve a problem is usually more difficult than writing the code. Emphasize on the importance of an algorithm. It is the lifeline of the program, etc. Trying to write a program without an algorithm is like trying to build a house without a plan, and so forth…

Characteristics of Algorithms An algorithm for a computer program must Have precisely defined steps Not be ambiguous Terminate after a finite number of steps An algorithm exhibits Sequence (Process) Decision (Selection) Repetition (Iteration/Looping) The first three characteristics are crucial in computer programs. If an algorithm doesn’t fulfill them, then it can’t be implemented with a computer.

Sequence Each task follows the previous one without altering the order of the tasks. Each task is executed once.

Decision Allows only one of two tasks to be carried out, depending on a controlling logical condition. The selected task is executed only once. If…then…, If… then… else… If today is Sunday then don’t go to school If today is Saturday or today is Sunday then don’t go to school, else go to school The outcome of a decision is either true or false. The underlined parts are the conditions, the blue parts are the actions.

Repetition Enables a task to be repeated until a controlling condition no longer holds. Keep going to school until you graduate. Repeat this example until the students understand and go to the next example when they do. What if it loops infinitely??? The underlined parts are the conditions The blue parts are the actions The bold part is the word that signals repetition You can talk about infinite loops Also try Repeat this example Until (students understand) Go to next example For a cashier While (there is a line of customers) call next customer serve customer Rest

More Concepts – Input/Output Your algorithm usually needs a set of inputs from the user and may give outputs to the user. Examples The movie PG algorithm 1. Ask the user for their age {output} 2. Get the user’s age {Input} 3. If the user’s age is less than 18, then go to step 5, else go to step 4 {decision} 4. Watch movie 5. Exit cinema My Algorithm 1. Ask the students a question {output} 2. Get an answer {input} 3. If the answer is right, go to step 4, else go back to step 1. {steps 1, 2, and 3 make up a repetition} 4. Proceed to next topic

More Concepts - Variables Variables are a way of representing data in your programs. You can think of them as containers for a value. Examples For the movie PG algorithm 1… 2. Get a { a is now a variable} 3. If a<18, then … {here a represents the value obtained in step 2} Do the following exercise with the students. Tell them they can’t use paper and pen 1. Add 5 and 6 and remember the result 2. Subtract 4 from 7 and remember the result 3. Multiply result 1 with 6 and remember the result 4. Divide result 3 by result 2 and tell me the value If you were allowed to use paper and pen, you might have used variables like this 1. A = 5 + 6 = 11 2. B = 7 – 4 = 3 3. C = A*6 = 11*6 = 66 4. Final Answer = C/B = 66/3 = 22

Expressing Algorithms Plain English (the step-by-step way) Pseudocode (False code) Uses much restricted vocabulary Closer to a Programming Language Uses variables and symbols There are different types available Flowchart Graphical method Uses various symbols for various actions Very easy to draw Very easy to read and understand We have been using Plain English so far when talking about algorithms. That is straight forward and needs no explanation. We won’t go into pseudocode in this course because an understanding of a programming language is somehow necessary to use pseudocode. (Most books use Pascal as a pseudocode) Next we will be discussing flowcharts.

Flowchart Basics A flowchart represents an algorithm or process, showing the steps as various symbols and showing their order by connecting them with arrows. The basic symbols are used in flowcharts are discussed here There are a lot of symbols for flowchart but here we will see only the basic ones

Terminal Points Rounded rectangles, or terminal points, indicate the starting and ending points of the flowchart. This is their only purpose, starting and ending flowcharts (processes). The actual work gets done inside this

Input/Output Operations Parallelograms designate input or output operations.

Processing A rectangle depicts a process such as a mathematical computation or a variable assignment.

Connectors A connector symbol, which is a circle, is used to break flowchart into multiple parts. This is useful if the flowchart is bound to take more than one page.

Example Flowcharts Write the algorithms in plain English

The Decision Structure With decisions, the path to follow is determined by the outcome of a test. The diamond symbol is used to represent the test to be performed. In a decision structure the next action to be performed depends on the outcome of a true/false test. A statement that is either true or false is evaluated. In the simplest form of decision structure, if the result of the test is true, a set of instructions is executed and if the result of the test is false, these instructions are skipped

Exercises Prime or Composite Average of three numbers Even or Odd