Fundamentals of Computer Programming PDF
Document Details
Uploaded by ToughExtraterrestrial
Prince Sattam Bin Abdulaziz University
2020
Tags
Summary
This document is a set of lecture notes for a course in Fundamentals of Computer Programming and Problem Solving. It covers topics including algorithms, flowcharts, control structures, pseudocode, databases, database management systems, and programming languages. The target audience is preparatory year students at Prince Sattam bin Abdulaziz University.
Full Transcript
Prince Sattam bin Abdulaziz University Preparatory Year Deanship Fundamentals of Computer Programming and Problem Solving [Information Technology] 1...
Prince Sattam bin Abdulaziz University Preparatory Year Deanship Fundamentals of Computer Programming and Problem Solving [Information Technology] 1st Semester September 2020 Fundamentals of Computer Programming and Problem Solving Table of contents Page 1. Introduction 2 2. Algorithm 2 3. Flow chart 2 4. Control structures 4 5. Pseudo code 6 6. Database and database management system 8 7. Programming languages 8 8. Compiler and interpreter 8 Content Recommended For Preparatory Year Deanship Students PSAU |Page1 Introduction: To solve any programming problem, use the following: 1. Algorithms 2. Flowcharts 3. Pseudo code 1. ALGORITHM A sequence of steps to be performed in order to solve a problem by the computer Example 1.1 Algorithm for addition of two numbers Step1: Start Step 2: Input A, B Step 3: Calculate C=A+B Step 4: Output C Step 5: Stop 2. FLOW CHART The symbolic representation of an algorithm is called a flow chart. Symbols used in a flow chart: Symbol Name Functions Oval Start/Stop Parallelogram Input/output Rectangle Processing Diamond Decision Making Circle Connector Flow lines Control Flow Content Recommended For Preparatory Year Deanship Students PSAU |Page2 Example 2.1 Flow chart for addition of two numbers Start Input A, B C=A+B Print C Stop Example 2.2 Algorithm and flow chart for the average of two numbers a. ALGORITHM: Step1: Start Step2: Input A, B Step3: Calculate C= (A+B) / 2 Step4: Output C Step5: Stop Content Recommended For Preparatory Year Deanship Students PSAU |Page3 b. FLOW CHART: Start Input A, B C= (A+B) / 2 Print C Stop 3. CONTROL STRUCTURES A control structure is a block of programming that analyzes variables and chooses a direction in which to go based on given parameters. It has two type 1. Branching (Branching is a decision - what actions to take.) 2. Looping (Looping is a decision - how many times to take a certain action.) 3.1 Example of Branching: Algorithm and flow chart for greatest of two numbers. a. ALGORITHM: Step1: Start Step 2: Input A, B Step 3: IF A > B Step 4: Output A Step 5: else Step 6: Output B Step 7: Stop Content Recommended For Preparatory Year Deanship Students PSAU |Page4 b. FLOW CHART: Start Input A, B True False A>B Print B Print A bA Stop. 3.2 Example of Looping: Algorithm and flow chart for display of first 5 natural numbers using control structure while. a. ALGORITHM: Step 1: Start Step 2: Set i= 0 Step 3: While i is less than 5 Step 4: Output i Step 5: Increment i // i=i+1 Step 6: Stop Content Recommended For Preparatory Year Deanship Students PSAU |Page5 b. FLOW CHART: Start i= 0 False i 37oc Step 4: Output “a Person with Fever” Step 5: Else Step 6: Output “a Person without Fever” Step 7: Stop Example 4.2 a. PSEUDO CODE: If student's grade is greater than or equal to 60 Then Print "Pass" Else Print "Fail" b. ALGORITHM: Step 1: Start Step 2: Input grade Value Step 3: If grade ≥ 60 Step 4: Output “Pass” Step 5: Else Step 6: Output “Fail" Step 7: Stop Content Recommended For Preparatory Year Deanship Students PSAU |Page7 5. DATABASE AND DATABASE MANAGEMENT SYSTEM 5.1 Database: A database is any collection of related data. Example: Student database 5.2 Database Management System: A database management system is a software designed to help in maintaining and utilizing large collection of data. 6. PROGRAMMING LANGUAGE A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. Examples of programming languages: C, C++, JAVA, COBAL, FORTRAN, etc. Use Language Business Application COBOL (Common Business Oriented Language) Scientific applications FORTRAN (FORmula TRANslation) General purpose use and education C, C++, JAVA, Pascal, Visual BASIC. 7. COMPILER AND INTERPRETER 7.1 Compiler: Compiler is a program that translates a high-level language into machine level language. 7.2 Interpreter: Interpreter is a program that translates a high-level language into machine level language line by line. 7.3 Comparison between Compiler and interpreter # Compiler Interpreter 1 Compiler Takes Entire program as input Interpreter Takes Single instruction as input. 2 Program execution is fast Program execution is relatively slow 3 Example: C Compiler Example: BASIC Content Recommended For Preparatory Year Deanship Students PSAU |Page8