Introduction to Programming Lecture Notes PDF
Document Details
Uploaded by GorgeousTuring7669
Delta University Egypt
Yehia EL Mashad
Tags
Summary
These lecture notes provide an introduction to computer programming. The topics covered include program and programming, algorithms and programs, software life cycle, and computer language generations. Examples, like calculating the area of a rectangle and finding the roots of a quadratic equation, are presented to illustrate the concepts.
Full Transcript
Chapter 9-12 Computer Programming Objectives Program and Programming Algorithms & Programs Software Life Cycle Computer Language Generations Flowchart Program and Programming Program: A set of instruction written in a programming language that a computer can execute so that the mach...
Chapter 9-12 Computer Programming Objectives Program and Programming Algorithms & Programs Software Life Cycle Computer Language Generations Flowchart Program and Programming Program: A set of instruction written in a programming language that a computer can execute so that the machine acts in a predetermined way. Program solves a problem البرنامج يحل مشكلة معينة Before writing a program: – Have a thorough understanding of the problem – Carefully plan an approach for solving it. Programming: The Process of providing instructions to the computer that tells the processor what to do. 3 Algorithms and Programs An Algorithm is a solution to a problem that is independent of any programming language. While A program is an algorithm expressed using a specific set of instructions from any programming language. 4 Algorithm Example Maximum of two numbers Steps: 1.Read/input two numbers 2.Compare two numbers 3.Print the Greater number Average of three numbers Steps: 1.Read/input three numbers 2.Add three numbers 3. divide the sum by 3. 4.Print the result of divison 5 Software Life Cycle Software Life Cycle What Requirements Gathering, Problem definition How Analysis and Design (Programming techniques) Do it Coding Test Testing Use Implementation and Maintenance 7 Computer Language generations Machine language لغة اآللة Assembly languages لغة التجميع High-level languages لغة المستوى العالي Very high-level languages لغة المستوى العالي جدا Natural languages اللغات الطبيعية 8 Machine Language Programs and memory locations are written in strings of 0s and 1s أصفار وآحاد Problems with machine languages ◼ Programs are difficult to write and debug ◼ Each computer has its own machine language Only option available to early programmers كانت تستخدم في برمجة حاسبات الجيل األول 9 Assembly Languages : ◼ For example, A for add, C for compare, etc. ◼ Use names rather than binary addresses for memory locations Require an assembler to translate the program into machine language Still used for programming chips and writing utility programs 10 High-Level Languages Transformed programming ◼ Programmers could focus on solving problems rather than manipulating hardware ◼ Programs could be written and debugged much more quickly Requires a compiler to convert the statements into machine language ◼ Each computer has its own version of a compiler for each language. 11 Very High-Level Languages Also called fourth-generation languages (4GLs) Considered nonprocedural languages ◼ The programmer specifies the desired results, and the language develops the solution ◼ Programmers can be about 10 times more productive using a fourth-generation language than a third-generation language 12 Natural Languages Resemble written or spoken English ◼ Programs can be written in a natural syntax, rather than in the syntax rules of a programming language The language translates the instructions into code the computer can execute 13 Major Programming Languages FORTRAN COBOL BASIC RPG Visual Basic C Java 14 Object-Oriented Languages C++ Java C# Visual Basic 15 Basic Translation Process Source program Link object file Process Check with standard preprocessor translation object files directives to unit for legal and other produce a syntax and object files to translation compile it into produce an unit an object file executable unit Executable Unit A First Program - Greeting.cpp // Program: Display greetings Preprocessor // Author(s): Yehia EL Mashad directives // Date: 1/24/2012 Comments #include #include Provides simple access using namespace std; Function int main() { named cout y Less than < x< y Greater/equals >= x >= y Less than/equals > Width; Definition with initialization // Compute and insert the area float Area = Length * Width; Visual C++ IDE with Area.cpp Area.cpp Output #include #include using namespace std; int main() { Library header files cout > a >> b >> c; if ( (a != 0) && (b*b - 4*a*c > 0) ) { double radical = sqrt(b*b - 4*a*c); Invocation double root1 = (-b + radical) / (2*a); double root2 = (-b - radical) / (2*a); cout