1 Topics l Program Language l Steps To Build a Program l Arithmetic Operation Priorities Program Errors Types l Sample Program.

Slides:



Advertisements
Similar presentations
More on Algorithms and Problem Solving
Advertisements

Prof. B. I. Khodanpur HOD – Dept. of CSE R. V. College of Engineering
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Reference :Understanding Computers
 Control structures  Algorithm & flowchart  If statements  While statements.
ITEC113 Algorithms and Programming Techniques
Chapter 2- Visual Basic Schneider
Chapter 3 - Structured Program Development
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Three types of computer languages
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Structured Program Development in C
Chapter 3 Planning Your Solution
The Program Design Phases
PRE-PROGRAMMING PHASE
Algorithm & Flowchart.
Fundamentals of C programming
ALGORITHMS AND FLOWCHARTS
COMPUTER SCIENCE I C++ INTRODUCTION
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.
 2008 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
Spring 2005, Gülcihan Özdemir Dağ Lecture 3, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 3 Outline 3.1 Introduction.
C++ If….Else Statements and Flowcharts October 10, 2007.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Computer Organization Six logical units in every.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
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.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Pseudocode When designing an ALGORITHM to solve a problem, Pseudocode, can be used. –Artificial, informal language used to develop algorithms –Similar.
INTRODUCTION Kingdom of Saudi Arabia Princess Nora bint Abdul Rahman University College of Computer Since and Information System CS240.
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.
C Lecture Notes 1 Structured Program Development.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
COMPUTER PROGRAMMING. Computer programming the objective of the module to gain the necessary skills to develop a computer program using one of the high.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
1 Lecture 3 Control Structures else/if and while.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
CS2301:Computer Programming 2
Chapter 3 Structured Program Development Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
The Hashemite University Computer Engineering Department
1 Lecture 2 Control Structures: Part 1 Selection: else / if and switch.
Chapter 3 Structured Program Development in C C How to Program, 8/e, GE © 2016 Pearson Education, Ltd. All rights reserved.1.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
Computer Programming.
Chapter 2.1 Control Structures (Selection)
CSC113: Computer Programming (Theory = 03, Lab = 01)
Programming Fundamentals
ALGORITHMS AND FLOWCHARTS
Lecture 2: Logical Problems with Choices
Structured Program
1) C program development 2) Selection structure
Chapter 3 - Structured Program Development
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 3 - Structured Program Development
Chapter 2- Visual Basic Schneider
Lecture 7 Algorithm Design & Implementation. All problems can be solved by employing any one of the following building blocks or their combinations 1.
Structural Program Development: If, If-Else
Presentation transcript:

1 Topics l Program Language l Steps To Build a Program l Arithmetic Operation Priorities Program Errors Types l Sample Program

2 Introduction l Software n Instructions to command computer to perform actions and make decisions l Hardware l Standardized version of C++ n United States –American National Standards Institute (ANSI) n Worldwide –International Organization for Standardization (ISO) l Structured programming l Object-oriented programming

3 Program Languages l Three types of computer languages 1. Machine language –Only language computer directly understands –“Natural language” of computer –Defined by hardware design l Machine-dependent –Generally consist of strings of numbers l Ultimately 0s and 1s –Instruct computers to perform elementary operations l One at a time –Cumbersome for humans –Example:

4 Program Languages l Three types of computer languages 2. Assembly language –English-like abbreviations representing elementary computer operations –Clearer to humans –Incomprehensible to computers l Translator programs (assemblers) n Convert to machine language –Example: LOADBASEPAY ADD OVERPAY STORE GROSSPAY

5 Program Languages l Three types of computer languages 3. High-level languages –Similar to everyday English, use common mathematical notations –Single statements accomplish substantial tasks l Assembly language requires many instructions to accomplish simple tasks –Translator programs (compilers) l Convert to machine language –Interpreter programs l Directly execute high-level language programs –Example: grossPay = basePay + overTimePay

6 Steps To Build a Program l Before writing a program n Have a thorough understanding of problem n Carefully plan your approach for solving it l While writing a program n Know what “building blocks” are available n Use good programming principles

7 Steps To Build a Program The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm. Flowchart is a graphical or symbolic representation of an algorithm. It is the diagrammatic representation of the step-by-step solution to a given problem. Program Design consists of the steps a programmer should do before they start coding the program in a specific language. Proper program design helps other programmers to maintain the program in the future

8 Algorithm Consider an example for finding the largest number in an unsorted list of numbers?. The solution for this problem requires looking at every number in the list, but only once at each. 1) Algorithm using natural language statements: a) Assume the first item is largest. b) Look at each of the remaining items in the list and if it is larger than the largest item so far, make a note of it. c) The last noted item is the largest item in the list when the process is complete. 2) Algorithm using pseudocode: largest = L0 for each item in the list (Length(L) >= 1), do if the item >= largest, then largest = the item return largest

9 Algorithms l Computing problems n Solved by executing a series of actions in a specific order l Algorithm a procedure determining n Actions to be executed n Order to be executed n Example: recipe l Program control l Specifies the order in which statements are executed

10 Pseudocode l Pseudocode n Artificial, informal language used to develop algorithms n Similar to everyday English l Not executed on computers n Used to think out program before coding –Easy to convert into C++ program n Only executable statements –No need to declare variables

11 if Selection Structure l Selection structure n Choose among alternative courses of action n Pseudocode example: If student’s grade is greater than or equal to 60 Print “Passed” If the condition is true –Print statement executed, program continues to next statement If the condition is false –Print statement ignored, program continues n Indenting makes programs easier to read –C++ ignores whitespace characters (tabs, spaces, etc.)

12 if Selection Structure l Translation into C++ If student’s grade is greater than or equal to 60 Print “Passed” if ( grade >= 60 ) cout << "Passed"; l Diamond symbol (decision symbol) n Indicates decision is to be made n Contains an expression that can be true or false –Test condition, follow path if structure n Single-entry/single-exit

13 Flowchart l Flowchart n Graphical representation of an algorithm n Special-purpose symbols connected by arrows (flowlines) n Rectangle symbol (action symbol) –Any type of action n Oval symbol –Beginning or end of a program, or a section of code (circles) l Single-entry/single-exit control structures n Connect exit point of one to entry point of the next n Control structure stacking

14 الشكل الهندسي المعني البداية - النهاية - التوقف Start - End - Stop المدخلات - المخرجات Input - Output العمليات Processes قرار أو شرط Decision نقط إتصال Connector Point حلفات التكرار For Or Loop إتجاة تدفق البيانات Data Flow Direction Flowchart

15 Example l For example, consider that we need to find the sum, average and product of 3 numbers given by the user. l Algorithm for the given problem is as follows: l Read X, Y, Z l Compute Sum (S) as X + Y + Z l Compute Average (A) as S / 3 l Compute Product (P) as X x Y x Z l Write (Display) the Sum, Average and Product

16 Flowchart

17 Advantages of Using Flowcharts Communication: Flowcharts are better way of communicating the logic of a system to all concerned. Effective analysis: With the help of flowchart, problem can be analysed in more effective way. Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes. 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. Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part

18 Limitations of Using Flowcharts Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy. Alterations and Modifications: If alterations are required the flowchart may require re- drawing completely

19 المتغيرات والثوابت (Variables & Constant): المتغيرات Variables / هي عبارة عن مواقع في الذاكرة تخزن فيها البيانات بشكل مؤقت ويمكن تغيير قيمتها أثناء تنفيذ البرنامج الثوابت Constant / هي عبارة عن مواقع في الذاكرة تخزن فيها البيانات بشكل مؤقت ولا يمكن تغيير قيمتها أثناء تنفيذ البرنامج

20 العمليات الحسابية(Arithmatic Operations) ● عملية الجمع Addition : يستخدم المعامل " + " لإجراء عمليات الجمع علي الأرقام ، مثال : Print ● عملية الطرح Subtraction : يستخدم المعامل " – " لإجراء عمليات الطرح علي الأرقام ، مثال : Print ● عملية الضرب Multiplication : يستخدم المعامل " * " ، مثال : Print 15 * 2

21 ● عملية القسمة Division : يستخدم المعامل " / " ، مثال : Print 10 / 2 ● عملية الأس Exponentiation : يستخدم المعامل " ^ " ، مثال : Print 3 ^ 2 ● عملية ناتج القسمة ، Integer Division : يستخدم الرمز " \ " ، عند إجراء عملية قسمة رقم ( 5 ) علي رقم ( 2 ) يقوم بعرض ( 2.5 ) ، فناتج القسمة يقوم بعرض الرقم ( 2 ) فقط لا غير ، مثال : Print 5 \ 2 Print 15 \ 3

22 ● عملية باقي القسمة ، Reminder : يستخدم الرمز " Mod " ، وتستخدم للحصول علي باقي القسمة الصحيح ، مثال : X = 18 / 5  إجراء عملية القسمة X = 3 * 5  ضرب ناتج القسمة في الرقم الثاني X =  طرح الرقم الأول من 15  ناتج القسمة النهائي ولكن الرمز " Mod " ، يوفر كل العمليات السابقة ، مثال : X = 18 Mod 5

23 أولويات تنفيذ العمليات الحسابية (Priorities Operations) : 1 - الأقواس ( ) من الداخل الي الخارج ، أنظر المثال التالي : X = 15 * (10 + (12 / 2))X = 15 * (10 + 6)X = 15 * 16X = الأس ( ^ ) ، مثال : X = 12 + (2 ^ (5 + 1))X = 12 + (2 ^ 6)X = X = الضرب والقسمة ، وما يأتي أولاً ينفذ أولاً ، مثال : X = 2 * 3 / 2X = 6 / 2X = الجمع والطرح وجمع السلاسل.

24 EX:1 Y = * 2 Y = Y = 17 EX:2 Y = (5 + 6) * 2 Y = 11 * 2 Y = 22

25 Sample program

26 أكتب برنامج لحساب محيط ومساحة الدائرة باستخدام Q Basic Rem circle program Input r Pi = 3.14 P = 2 * pi * r A = pi * r ^ 2 Print P, A End

27 برنامج / جمع ثلاثة ارقام Rem three numbers program Input a, b, c D = a + b + c Print d End

28 برنامج / حساب مساحة المثلث Rem triangle program Input a, b D = 0.5 * a * b Print d End

29 برنامج / حساب محيط و مساحة المربع Rem square program Input x P = 4 * x A = x ^ 2 Print P, A End

30 Errors Types l Syntax Errors l Logic Errors l Executable Errors

31 The End Lecture 0 C/C++ programming 2014