CS2301:Computer Programming 2

Slides:



Advertisements
Similar presentations
Senem Kumova Metin Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.
Advertisements

Exercise (1).
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Lecture 1: Overview of Computers & Programming
 Computer hardware components are the physical pieces of the computer.  The major hardware components of a computer are: – The central processing.
Chapter 1 - An Introduction to Computers and Problem Solving
ICS103 P ROGRAMMING IN C L ECTURE 1: O VERVIEW OF C OMPUTERS & P ROGRAMMING.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
CS 201 Overview of Computers & Programming Debzani Deb.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
 2000 Prentice Hall, Inc. All rights reserved. 1 Introduction to Computers and C Programming Outline Introduction What Is a Computer? Computer Organization.
CS102 Introduction to Computer Programming
 2003 Prentice Hall, Inc. All rights reserved. Chapter 1 – Introduction to Computers, the Internet, and the Web Outline 1.1 Introduction 1.2 What Is a.
Introduction to Computers and Python. What is a Computer? Computer- a device capable of performing computations and making logical decisions at speeds.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
Chapter 1 An Overview of Computers and Programming Languages.
 2008 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
Lecture 1 Introduction to computers & VB.Net. What is a Computer? Examples? A device capable of  Performing computation  Making logical decisions 
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
An Introduction to Computers August 12, 2008 Mrs. C. Furman.
C++ Programming Language Lecture 1 Introduction By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Overview of Programming and Problem Solving. Objectives In this chapter you will: Learn about different types of computers Explore the hardware and software.
Chapter 1: An Overview of Computers and Programming Languages
 2006 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
1 MIS 131 Introduction to Algorithms and Programming 2015/2016 Fall - Chapter 1 -
1 Programming Fundamentals How to Program in C++ How to Program in C++
COMPUTER PROGRAMMING. Computer programming the objective of the module to gain the necessary skills to develop a computer program using one of the high.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 1 st semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Chapter 1 : Overview of Computer and Programming By Suraya Alias
 2001 Prentice Hall, Inc. All rights reserved. Chapter 1 – Introduction to Computers, the Internet and the World Wide Web Outline 1.1Introduction 1.2What.
A.Abhari CPS1251 Topic 1: Introduction to Computers Computer Hardware Computer components Connecting Computers Computer Software Operating System (OS)
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
CHAPTER 1.1 INTRODUCTION TO COMPUTERS AND C++ Dr. Shady Yehia Elmashad.
Chapter 1 An Overview of Computers and Programming Languages.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming Dr. Halla Abdel Hameed.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. Introduction to Computers and Computing.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Chapter 1 Introduction 2nd Semester H
Chapter 1 – Introduction to Computers, the Internet, and the Web
Computer Programming.
Chapter 1: An Overview of Computers and Programming Languages
Lecture 1: Introduction to JAVA
Chapter 1: An Overview of Computers and Programming Languages
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Chapter 1: An Overview of Computers and Programming Languages
Introduction CSC 111.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
ICS103 Programming in C 1: Overview of Computers And Programming
Presentation transcript:

CS2301:Computer Programming 2

Programming Languages and Introduction to Computers Programming Languages and Algorithms

OBJECTIVES In this Chapter we will learn: 1.1 Introduction 1.2 Computers: What is a Computer? 1.3 Computers: Hardware and Software? 1.4 Computer Organization 1.5 Classification of programming languages 1.6 Machine Languages, Assembly Languages and High-Level Languages 1.7 Programming Language, computer program and Computer Programmer 1.8 Program developing life cycle? 1.9 What do we mean by algorithm? 1.10 Examples of algorithms

1.2 Computers: What is a Computer? Computer Is a device capable of performing computations and making logical decisions. Another definition: (often referred to as hardware) are controlled by software (i.e., the instructions you write to command the computer to perform actions and make decisions).

1.3 Computers: Hardware and Software (cont.) Set of instructions that tells the computer to perform specific tasks. Computers process data under the control of sets of instructions called computer programs. These programs guide the computer through orderly sets of actions specified by people called computer programmers. Software may be divided into: Operating systems e.g. (Windows 7) Application programs e.g. (Microsoft word)

1.3 Computers: Hardware and Software? Computer hardware is the collection of physical elements that constitutes a computer system and assist to the input, process, storage, output …. Various devices comprising computer Keyboard, screen, mouse, disks, memory, CD-ROM, processing units, etc.

1.4 Computer Organization Five logical units of computer system Input unit (Mouse, keyboard) Output unit (Printer, monitor, audio speakers) Memory unit (Retains input and processed information) Central processing unit (CPU) which consists of: Control unit (Supervises operation of other devices) Arithmetic and logic unit (ALU):Performs arithmetic calculations and logic decisions. Secondary storage unit (Hard drives, floppy drives)

1.4 Computer Organization (Cont.) Hardware Components

1.4 Computer Organization (Cont.) Hardware Components

1.4 Computer Organization (Cont.) Hardware Components in Actions Execution of an Instruction

1.5 The Internet and the World Wide Web A collection of interconnected networks, all freely exchanging information. Or Global network of computers. Internet has become one of the world’s premier communication mechanisms. World Wide Web Also called the Web, WWW, or W3 Organizes Internet resources throughout the world into a series of menu pages, or screens, that appear on your computer.

1.6 Classification of programming languages

1.7 Programming Languages Three types of computer languages 1- Machine language Language of Computer. Only language computer directly understands “Natural language” of computer Defined by hardware design Binary digit (bit): The digit 0 or 1 Binary code: A sequence of 0s and 1s Byte: A sequence of eight bits.

1.7 Programming Languages(cont) Early computers were programmed in machine language. To calculate wages= rates * hours in machine language 100100 010001 //load 100110 010010 // multiply 100010 010011 // store

1.7 Programming Languages(cont) 2- Assembly language English-like abbreviations representing elementary computer operations. Clearer to humans Incomprehensible to computers Example load basepay add overpay store grosspay Assembler: Translates a program written in assembly language in to machine language.

Example of instructions in Assembly Language and Machine Language 1.7 Programming Languages(cont) Example of instructions in Assembly Language and Machine Language Machine language Assembly Language 100100 LOAD 100010 STOR 100110 MULT 100101 ADD 100011 SUB

1.7 Programming Languages(cont) 3- High-level languages Include Basic, FORTRAN, COBOL, Pascal, C, C++, C# and Java Similar to everyday English Uses common mathematical notations The equation: wages = rate* hours can be written in java as: Wages = rate * hours; Another Example: grossPay = basePay + overTimePay Compiler: translates a program written in a high-level language in to machine language.

1.8 Programming Language, Computer Program, and Computer Programmer Is a process of problem solving by using a programming language. Programming Language: A set of rules, symbols and special words used to write computer program. Computer program:  is a list of instructions, written to perform a specified task on a computer Syntax: Rules that specify which statements (instructions) are legal. Algorithm - Step–by–step problem solving processes using informal language.

1.8 Programming Language, Computer Program, and Computer Programmer Examples of Programming Languages: Fortran COBOL Pascal Ada Basic C C++ Objective-C Visual Basic Visual C# PHP Python JavaScript Java

Computer Programmer A programmer, computer programmer, developer, coder, or software engineer: is a person who design, writes and maintains computer software.

1.9 What is program developing life cycle?

1.9 What is program developing life cycle? step1: Analyze the problem. - Outline the problem and its requirements. - Design steps (algorithm) to solve the problem. Step 2: Implement the algorithm(coding). - Implement the algorithm code. - Verify that the algorithm works. Step 3: Maintenance (when errors occurs) - Use and Modify the program if the problem domain changes.

How Problem Analysis could be done Understand the overall problem. Understand problem requirements. - Does program require user interaction? Example: When you calculate the area of ​​a rectangle What do we require from the user? Enter the length of the rectangle, width of the rectangle - Does program manipulate data? Example: Equation calculating the area of ​​a rectangle Area= length * Width - What is output? Note If the problem is complex, divide into sub problems. Analyze each sub problem as above.

1.9.1 Defining the Problem Keyboard Screen Processing input data The problem must be defined in terms of: Input: raw data to be processed. Output: production of useful information. processing: converting or transforming data into useful outputs. Keyboard Screen Processing input data output data

1.9.2 Input and Output Inputs Outputs Can come from many sources, such as users, files, and other programs Can take on many forms, such as text, numbers, graphics, and sound Outputs Can also take on many forms, such as numbers, text, graphics, sounds, or commands to other programs

1.9.3 The Problem Analysis-Coding-Execution Cycle Stages of programming

1.9.3 The Problem Analysis-Coding-Execution Cycle

Typical Java development environment.

representing algorithms 1.10.1 The Algorithm Methods for representing algorithms Pseudo code Flow Chart Note: Before use any two methods, you must specify the input, processing, and output

1.10.2 The Algorithm- Pseudo Code An informal language similar to English Is not considered programming language. Helps programmers develop algorithms Does not run on computers Should contain input, output and calculation actions Can be easily converted for different programming languages ​​such as Pascal, Java, C++.

Example 1: Calculate Area = length*width Using pseudo code ,write suitable algorithm that calculate the area and perimeter of rectangle and print them. Area=length * width Perimeter=2(length * width) Prompt the user Input Length and width Calculate Area = length*width Calculate Perimeter = 2*( length + width) Output Area Output Perimeter End

Calculate Average = Sum/5 Example 2: Using pseudo code write suitable algorithm that calculate and output Sum and Average of 5 numbers Input five number x1, x2, x3, x4, x5 Calculate Sum = x1+x2+x3+x4+x5 Calculate Average = Sum/5 Output Sum Output Average end

Using pseudo code ,write suitable algorithm: Example 3: Using pseudo code ,write suitable algorithm: If the student's degree is greater than or equal 60, print “pass” else print “fail”. Input grade Check if (grade > 60) then Print "passed" Else Print "failed“ End

Example4: Using Pseudo code, Write suitable algorithm: Calculate and print the average of temperature degrees for the following readings T1, T2, T3. Answer: Input T1, T2, T3 Calculate avg= (T1 + T2 + T3)/3 Output avg End

1.10.3 The Algorithm-Flow chart Is a graphical way that explain the steps to solve problem and how they relate to each other (it is a symbolic representation of the algorithm).

Flow chart Start or Stop Program Input or Output Process, Calculate, Storage Used to express logical operations or operations report (Condition) Arrows determine the direction of the program's progress Connection

Condition Branching No yes Compare

Condition Rotation

start Input : stop Sum = T1+T2+T3 Avg = sum/3 Example 5: claculation: Using flow chart, Write suitable algorithm: Calculate and print the average of temperature degrees for the following readings T1, T2, T3. start Input T1, T2, T3 Input : T1, T2, T3 claculation: Sum = T1+T2+T3 Avg = sum/3 Output: Print Avg Sum = T1+T2+T3 Avg = sum/3 Print avg stop

Example 6: Using pseudo code and flow chart to write suitable algorithm: Calculate the average for temperature for the following readings T1, T2, T3. IF the average is greater than 15 print the average, else print the weather is cold. start input T1, T2, T3 Sum= T1+T2+T3 Start Input : T1,T2,T3 Process and output Sum = T1+T2+T3 Avg = sum/3 If avg > 15 then Print avg Else Print “cold” End if end Avg = sum/3 No Yes avg > 15 Print “cold” Print avg Stop

Flow chart Example7: End Using flow chart to write an algorithm. Enter number (X) and find the value (F), as shown in the following equations: F= { x + 1 x >=0 x-1 x< 0 start Input x Yes No X <= 0 F = x-1 F= x+1 Print F , x End

Note: (if X=0 enter value of X again) Pseudo code input: X process: Example 8: Using pseudo code and flow chart to write an algorithm. Enter number (X) and then find and print the value (Y), as shown in the following equation: Y=(X-2)/X Note: (if X=0 enter value of X again) Pseudo code input: X process: if x=0 Re-enter the new value of x because you can not divide by 0 output: Y Flow Chart start Input X If X=0 yes No Y=(X-2)/X Print Y stop

Discuss Using pseudo code and flow chart to write an algorithm that : Accept 3 readings of temperature degrees and find the average then check the average if avg less than 15 : print the “cool air” if avg between 15 and 25: Print “moderate air” And if the avg is not verify the previous conditions: print “hot air”

Home Work (1) Using pseudo code and flow chart to write an algorithm that calculate the area of ​​a rectangle print it. Note: area of ​​the rectangle = length × width. Using pseudo code and flow chart to write an algorithm that find the area of ​​a circle which its radius (R) and print it. Note: The area of ​​a circle is equal to π * R2, where π is a constant value of approximately 3.14. Using the methods (pseudo code and flow chart), we need to find and print the vicinity of the football stadium, and determine whether if vicinity is greater than or equal to 600 m then print (international stadium) , and if vicinity is less than 600 then print (local stadium ), Note: The perimeter of the rectangle is equal to (length + width)×2 .

End