Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

StatelySalmon

Uploaded by StatelySalmon

Taibah University

2022

Tags

java programming computer science programming concepts

Full Transcript

Programming 1 SEMESTER 2, 2022 Instructor  Dr. Peer Fatima  Assistant Professor at Department of Computer Science at Yanbu.  Email:[email protected]  Course: Programming 1 Course Information Course Web Site: BLACKBOARD https://lms.taibahu.edu.sa You can find the following information...

Programming 1 SEMESTER 2, 2022 Instructor  Dr. Peer Fatima  Assistant Professor at Department of Computer Science at Yanbu.  Email:[email protected]  Course: Programming 1 Course Information Course Web Site: BLACKBOARD https://lms.taibahu.edu.sa You can find the following information on Blackboard: Latest news Teaching materials  Lecture notes, practical specifications Links to additional information  Marking results PLEASE CHECK THE BLACKBORAD REGULARLY! Course Schedule Theoretical Lecture : GF 06 Lecture Practical Lecture : Same time as Schedule on lab. All Student Must Attend The Theoretical And Practical Lectures. References Main: Introduction to Java Programming, Ninth Edition by Y. Daniel Liang Suggested Readings: Java in a Nutshell, 6th Edition A Desktop Quick Reference by Benjamin J Evans, David Flanagan Java: The Complete Reference Ninth Edition by Herbert Schildt Java: A Beginner's Guide sixth Edition by Herbert Schildt Website: https://www.w3schools.com/java/default.asp Mark distribution Assessment Mark Lab attendance and exercises 10 Quiz 1 and 2 10 Midterm 30 Lab Exam 10 Final written exam 30 marks and lab exam 10 marks Total 100 Outlines Chapter 0: Overview Chapter 1: Flowchart Chapter 2: Introduction to computer programming Chapter 3: Variables and Data types Chapter 4: Operators Chapter 5: Condition statement Chapter 6: Loop Chapter 7: Arrays Chapter 8: Methods - functions Overview Objectives of this course Upon completing this course, you will be able to: Understand the main concepts of Programming languages. - Develop programs using Java. Solve problems algorithmically. - Write simple programs using primitive data types, control statements, loops and arrays. Trace and Tackle java errors. - ① What is programming ? A plan of action aimed at accomplishing a clear business objective, with details on what work is to be done, by whom, when, and what means or resources will be used. E.g, election program, trip program or a computer program. Referance: http://www.businessdictionary.com/definition/program.html What is programming ? A plan of action aimed at accomplishing a clear business objective, with details on what work is to be done, by whom, when, and what means or resources will be used. E.g, election program, trip program or a computer program. Referance: http://www.businessdictionary.com/definition/program.html What is programming ? A plan of action aimed at accomplishing a clear business objective, with details on what work is to be done, by whom, when, and what means or resources will be used. E.g, election program, trip program or a computer program. Referance: http://www.businessdictionary.com/definition/program.html What is computer programs? What is Computer programs : Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Without programs, a computer is an empty machine. Computers do not understand human languages, so you need to use computer languages to communicate with them. Example: Calculator program, BMI program, Grade program. Programs are written using programming languages. Programming Languages Machine Language Assembly Language High-Level Language -- Machine language is a set of primitive instructions built into every -- computer. The instructions are in the form of binary code, so you have - - to enter binary codes for various instructions. Program with native machine language is a tedious process. Moreover the programs are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this: 1101101010011010 - 10110 Programming Languages Machine Language Assembly Language High-Level Language Assembly languages were developed to make programming easy. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example, to add two numbers, you might write an instruction in assembly code like this: ADD R1, R2, R3 - 1010 Programming Languages Machine Language Assembly Language High-Level Language The high-level languages are English-like and easy to read, learn, understand and program. For example, the following is a high-level language statement that computes the area of a circle with radius 5: area = 5 * 5 * 3.1415; Too ↳ Compiler Popular High-Level Languages COBOL (COmmon Business Oriented Language) FORTRAN (FORmula TRANslation) BASIC (Beginner All-purpose Symbolic Instructional Code) Pascal (named for Blaise Pascal) Ada (named for Ada Lovelace) C (whose developer designed B first) Visual Basic (Basic-like visual language developed by Microsoft) Delphi (Pascal-like visual language developed by Borland) C++ (an object-oriented language, based on C) C# (a Java-like language developed by Microsoft) Java (We use it in the book) Note Compiler A compiler is a program that reads a program written in the high-level language (Source code) and converts it into the machine or low-level language (Target) and reports the errors present in the program. is i 5 : +S G GjE - - a - - https://medium.com/@rahul77349/difference-between-compiler-and-interpreter-with-respect-to-jvm-java-virtual-machine-and-pvm-22fc77ae0eb7 - Main Phases Of Compiler - - X 1. Lexical analyzer: it divides the input into valid tokens i.e smaller entities which make sense - and are well defined in the language: Example - "beautiful" is a valid token as it is a valid word in English. Whereas "dsefuewfiu" is not a valid token as it does not make any sense. -1s - 2. Syntax Analyzer: the tokens that are generated in the previous stage are checked against the - grammar of programming language, whether the expressions are syntactically correct or not. - Example - "My name is Ahmed" is a valid English sentence. Whereas "name my is Ahmed" makes no sense. 3. Semantic Analyzer: it checks whether or not the sentence has a valid meaning. - Example – X=5; Y=Ahmed; Z=X+Y? incorrect meaning. 514 What is an algorithms? An algorithm is a set of ordered steps for solving a problem. Examples: ◦ An algorithm for preparing breakfast. ◦ An algorithm for calculating moon phase. ◦ An algorithm for drawing a circle. Algorithm in Real Life Consider the following … Problem: Making a cup of tea How to solve: 1.Start 2. Fill kettle with water and boil. 3. Pour hot water into cup 4. Put teabag in I 5. Add sugar 6. Stir with spoon 7. Take out teabag 8. End Algorithm in Real Life Consider the following … Problem: Making a cup of tea How to solve: 1.Start 2. Fill kettle with water and boil. 3. Pour hot water into cup 4. Put teabag in 5. Add sugar 6. Stir with spoon 7. Take out teabag What o an algorithm? 8. End It is a set of instruction to achieve a particular task. https://newquayjunior.net/year-4-ict/flowchart-with-algorithm-for-making-tea/ Algorithms In Program Design A computer program is built to solve a certain problem. Examples: 1. An algorithm to calculate - the grade obtained given a mark. 2. An algorithm to calculate the average of three numbers. - 3. An algorithm to calculate area of rectangle. - Algorithm --T S Pseudocode Flowchart Definition 1 : An outline of a program, written in a form that can easily be converted into real programming statements. Definition 2: is an informal language that helps programmers develop algorithms to solve a specific task. Pseudocode normally codes the following actions: ◦ & Initialization of variables ◦ F Assignment of values to the variables ◦ & Arithmetic operations ◦ 6 Relational operations Pseudocode for making a cup of tea 1.Start 2. Fill kettle with water and boil. 3. Pour hot water into cup 4. Put teabag in 5. Add sugar 6. Stir with spoon 7. Take out teabag 8. End Example for Adding two numbers Problem: Adding two numbers x and y. Pseud ocode: input Process out Put 1. Start - - - - 2. Input A and B 3. Sum Total=A+B 4. Print Total 5. End Flowchart Symbols Flowcharts use special- shapes to represent different types of actions or steps in a process. Lines and arrows show the sequence of the steps, and the relationships among them. These are known as flowchart symbols. Flowcharts Symbols: Rectangle Shape - Represents a process Oval or Pill Shape - Represents the start or end Diamond Shape - Represents a decision Parallelogram - Represents input/output https://www.smartdraw.com/flowchart/flowchart-symbols.htm Flowchart Example 1 Flowchart for making a cup of tea: Flowchart Example 2 Draw a flowchart which represents the Pseudocode in slide 25. Beginning of code G Read number A Read number B Sum two numbers Print the result Ending of code Flowchart Example 2 Draw= --- a flowchart to calculate the area of a room. length, width and area are referred to as variables. - v & input Process output L, w Area-LXW Area - - - · Start · input L , w · Area-xw > - Print Area · Print · End Flowchart Example 3 · Start Start - in put height Input · height 1 6. true height Print "tall" false height > 1.6? true height) 1 6 False. Print Short Output Output “You are short!” E“You are tall!”3 · End End Pseudo Code Write the Pseudo Code For Previous Example.? 1. Start 2. Input height 3.1 height > 1.6= true ◦ Print “You are tall!” 3. 2 height > 1.6= false ◦ “You are short!” 4. End Any Questions what an algorithm is. when an algorithm should be developed when building a computer program. the basic steps in building a computer program to solve a problem. what flowcharts are. how to represent algorithms graphically using flowcharts.

Use Quizgecko on...
Browser
Browser