Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Topics l Program Language l Steps To Build a Program l Arithmetic Operation Priorities Program Errors Types l Sample Program."— Presentation transcript:

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

2 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 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: +1300042774 +1400593419 +1200274027

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

15 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 16 Flowchart

17 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 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 19 المتغيرات والثوابت (Variables & Constant): المتغيرات Variables / هي عبارة عن مواقع في الذاكرة تخزن فيها البيانات بشكل مؤقت ويمكن تغيير قيمتها أثناء تنفيذ البرنامج الثوابت Constant / هي عبارة عن مواقع في الذاكرة تخزن فيها البيانات بشكل مؤقت ولا يمكن تغيير قيمتها أثناء تنفيذ البرنامج

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

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

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

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

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

25 25 Sample program

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

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

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

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

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

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


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

Similar presentations


Ads by Google