CHAPTER 1 INTRODUCTION 2 nd Semester 1432-1433 H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.

Slides:



Advertisements
Similar presentations
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Advertisements

Lecture 1: Overview of Computers & Programming
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Chapter 1 Pseudocode & Flowcharts
Chapter 2- Visual Basic Schneider
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
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:
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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.
Programming Logic and Design Fourth Edition, Introductory
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Chapter 1 Pseudocode & Flowcharts
 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.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Chapter 1 An Overview of Computers and Programming Languages.
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
CSC141 Introduction to Computer Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
What is a Computer? An, electrical machine, that can be programmed to accept data (input), process it into useful information (output) and store it away.
EKT 120/4 C Programming (Additional note). Computer Fundamentals Computer is a machine that can receive, store, transform an output data of all kinds.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
C++ Programming Language Lecture 1 Introduction By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
King Saud University College of applied studies and community services CSC 1101 Computer Programming I Lecture 2.
Chapter 1: An Overview of Computers and Programming Languages
Overview of Programming and Problem Solving Textbook Chapter 1 1.
Software Life Cycle What Requirements Gathering, Problem definition
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.
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 Pseudocode & Flowcharts
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
CS2301:Computer Programming 2
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
Chapter 1 An Overview of Computers and Programming Languages.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Chapter 1 Introduction 2nd Semester H
Chapter 1 – Introduction to Computers, the Internet, and the Web
Chapter 1: An Overview of Computers and Programming Languages
Lecture 1: Introduction to JAVA
DDC 1023 – Programming Technique
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: Introduction to Computers and Programming
Chapter 1 Pseudocode & Flowcharts
(Course Introduction)
Pseudocode & Flowcharts
Introduction CSC 111.
Chapter 1 Pseudocode & Flowcharts
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 1 Introduction(1.1)
Chapter 2- Visual Basic Schneider
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Computer Programming-1 CSC 111
Chapter 1 Introduction to Programming
Chapter 1 Pseudocode & Flowcharts
ICS103 Programming in C 1: Overview of Computers And Programming
Programming Logic and Design Eighth Edition
Presentation transcript:

CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel

What Is a Computer?  Computer  Executes statements (computations/logical decisions)  Hardware : Physical devices of computer system  Software: Programs that run on computers Asma Alosaimi 2

Computer Organization Asma Alosaimi 3  Six logical units of computer system  Input unit Mouse, keyboard  Output unit Printer, monitor, audio speakers  Memory unit Retains input and processed information  Arithmetic and logic unit (ALU) Performs calculations  Control unit Supervises operation of other devices  Secondary storage unit Hard drives, floppy drives

What a computer program is? Asma Alosaimi 4  For a computer to be able to perform specific tasks (i.e. print what grade a student got on an exam), it must be given instructions to do the task.  The set of instructions that tells the computer to perform specific tasks is known as a computer program

Machine Languages, Assembly Languages and High-Level Languages  Machine language  “Natural language” of computer component  Machine dependent  Assembly language  English-like abbreviations represent computer operations  Translator programs convert to machine language  High-level language  Allows for writing more “English-like” instructions Contains commonly used mathematical operations  Compiler convert to machine language

An Overview Of Computer Languages Asma Alosaimi 6 1-Machine language2-Assembly language 3-High-level language representation Collection of binary numbers Symbolic form of machine language (I.e. symbolic names are used to represent operations, registers & memory locations) combines algebraic expressions with symbols taken from English language(ex. C, Pascal, FORTRAN, …etc) examples MOV AX,A MOV A, AX ADD AX, A=A+4 *c how does the computer understand ? Directly understood by a computer Assembler  convert to machine language Compiler or (interpter )  convert to machine language Easier to use More powerful

Levels of Program Development Asma Alosaimi 7  Human thought  Pseudo-Natural Language (English, Arabic)  High Level Programming Language (C, C++, Java, …)  Machine Code

The Programmer’s Algorithm Asma Alosaimi 8  An algorithm is a finite sequence of instructions that produces a solution to a problem.  The programmer’s algorithm:  Define the problem.  Plan the problem solution.  Code the program.  Compile the program.  Run the program.  Test and debug the program.

9 1-Defining the Problem  The problem must be defined in terms of:  Input: Data to be processed.  Output: The expected result. Look for nouns in the problem statement that suggest output and input.  and processing: The statements to achieve. Look for verbs to suggest processing steps. KeyboardScreen Processing input data output data

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIR 10 Input and Output  Inputs  Can come from many sources, such as users, files, and other programs  Can take on many forms, such as text, graphics, and sound  Outputs  Can also take on many forms, such as numbers, text, graphics, sounds, or commands to other programs

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIR 11 Example 1 Area and Perimeter of a rectangle  Input  Length  width  Processing  Area = length*width  Perimeter = 2*( length + width)  Output  Area  Perimeter

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIR Page 12 Example 2 Sum and Average of 5 numbers  Input  five number x1, x2, x3, x4, x5  Processing  Sum = x1+x2+x3+x4+x5  Average = Sum/5  Output  Sum  Average

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIR Page 13 Example 3 Area and Perimeter of a circle  Input  Radius  PI  Processing  Area = PI * Radius * Radius  Perimeter = 2 * PI * Radius  Output  Area  Perimeter

2-Planning the Solution Asma Alosaimi 14  When planning, algorithms are used to outline the solution steps using English like statements, called pseudocode. A flowchart is useful for the graphical representation of an algorithm. They are drawn using rectangles, diamonds, ovals, and small circles.

Write a Program to Print the Sum of two integer Numbers 1. Start the program 2. Read the first number and save in the variable ( N1 ) 3. Read the second number and save in the variable ( N2 ) 4. Sum the both numbers and save the result in the variable ( Sum )  Sum = N1 + N2 5. Print the variable ( Sum ) 6. End the program Asma Alosaimi 15 start Read N1 Read N2 Sum = N1 + N2 Print Sum End

3-Coding the Program Asma Alosaimi 16  Coding is writing the program in a formal language called Programming Language. Programming Language : A set of rules, symbols and special words used to write statements.  The program is written by translating the algorithm steps into a programming language statements.  The written program is called Source code and it is saved in a file with “.cpp” extension. Program Coding AlgorithmPseudocode Source Code (The “.cpp”) Translating

Why Coding in Programming Languages Asma Alosaimi 17  We write computer programs (i.e. a set of instructions) in programming languages such as C, C++, and Java.  We use these programming languages because they are easily understood by humans  But then how does the computer understand the instructions that we write?

4-Compiling Computer Programs Asma Alosaimi 18  Computers do not understand programs written in programming languages such as C, C++ and Java  Programs must first be converted into machine code that the computer can run  A Software that translates a programming language statements into machine code is called a compiler  In C, Preprocessor program, execute automatically before the compiler translation phase begin  Preprocessor indicate that certain manipulations are to be performed on the program before compilation. Machine code ProgramSource code Machine Code Translating Compiling

Programming Language Compiler Asma Alosaimi 19  A compiler is a software that:  Checks the correctness of the source code according to the language rules. Syntax errors are raised if some rules were violated.  Translates the source code into a machine code if no errors were found.

5-Running The Program Asma Alosaimi 20  Before running..  links the object code with the code for the missing functions to produce an executable image (with no missing pieces), this is called link phase.  If the program compiles and links correctly, a file called a.out is produced.  Before a program can be executed, the program must first be placed in memory this called load phase.  the computer, under the control of its CPU, executes the program one instruction at a time

6-Testing and Debugging the Program Asma Alosaimi 21  Testing  Be sure that the output of the program conforms with the input.  There are two types of errors: Logical Errors: The program run but provides wrong output. Runtime errors: The program stop running suddenly when asking the OS executing a non accepted statement (divide by zero, etc).  Debugging  Find, Understand and correct the error

22 Basics of a Typical C++ Environment Phases of C++ Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Loader Primary Memory Program is created in the editor and stored on disk. Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk Editor Preprocessor Linker CPU Primary Memory Disk

Pseudocode & flowcharts 23 Asma Alosaimi

Pseudocode Example Asma Alosaimi 24  Write a Program to Print the Sum of two integer Numbers 1. Start the program 2. Read the first number and save in the variable ( N1 ) 3. Read the second number and save in the variable ( N2 ) 4. Sum the both numbers and save the result in the variable ( Sum )  Sum = N1 + N2 5. Print the variable ( Sum ) 6. End the program

Flow Charts Symbols Asma Alosaimi 25 Loops Start/End Read/Print Arithmetic Operations Decision Connectors arrows Start Read n1 N2 = 5 End Print n1 N2 = n1+3 n1 > 3

Example 1 Area and Perimeter of a rectangle Asma Alosaimi 26  Input  Length  width  Processing  Area = length*width  Perimeter = 2*( length + width)  Output  Area  Perimeter start Read L, W ٍSurface =2* ( L * W ) Print area End area = L * W Print perimeter

Exercise 1 Asma Alosaimi 27  Write a program that calculates and prints the sum of the even integers from 2 to 30.

Exercise 1- solution Asma Alosaimi 28  I/P:no input  Operations: sum=2+4+6+…..+30  O/p: the summation Start the program Create a variable to hold the sum. Initialize the sum to zero. Create a variable to hold a counter from 2 to 30. Initialize the counter to 2. Loop While the counter is less-than-or-equal to 30 add the counter to the sum add two to the counter. Now repeat Print the sum. End of program

Exercise 1- solution Asma Alosaimi 29 Start End Sum=0,counter=2 Counter≤30 Sum=sum+counter Counter=counter+2 Print sum yes no

Exercise 2  Draw the flow chart for a program that calculates the total salary for an employee using this equation: Total_Sal = Salary +Overtime Asma Alosaimi 30

Exercise 3  Write a program to process a collection of daily temperatures. Your program should count and print the number of hot days (85 or higher), the number of pleasant days ( ), the number of cold days (less than 60). It should also display the category of each temperature. Asma Alosaimi 31

32 Temp >=85? End Hot=Hot+1 Yes Cold=Cold+1 Yes Temp<=60? No Pleasant= Pleasant+1 No Get Temp Start Print Hot, Cold, Pleasant

Homework Asma Alosaimi 33  Write a program that calculates the Zakat, where the user enter the amount of money then the program show the zakat. Zakat =2.5 * amount.  Zakat is not calculated if the amount is less than 1000 S.R