1 CSE 324 - Computer Programming “Using C-Language” Lectures 1.

Slides:



Advertisements
Similar presentations
Intro to Computer Programming Algorithms Lecture # 01 01/21/05
Advertisements

ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Lecture 1: Overview of Computers & Programming
Overview of Programming and Problem Solving ROBERT REAVES.
Copyright © 2002 W. A. Tucker1 Chapter 1 Lecture Notes Bill Tucker Austin Community College COSC 1315.
CSCE 145: Algorithmic Design I Chapter 1 Intro to Computers and Java Muhammad Nazmus Sakib.
Chapter 1 - An Introduction to Computers and Problem Solving
Algorithm –History Muhammad ibn Musa Al-Khwarizmi www -groups.dcs.st-andrews.ac.uk/~history/Mathematicians/Al- Khwarizmi.html Book on arithmetic:
1 CSE1301 Computer Programming Lecture 3: Introduction to Algorithms.
Computer Programming Lecture 23. Summary of Previous Lecture In the previous lecture, we have learnt  Intellectual Property Types of Intellectual Property.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
1 CSE1301 Computer Programming Lecture 2: Introduction to Algorithms.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
Lecture 1: Intro to Computers Yoni Fridman 6/28/01 6/28/01.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
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.
Introduction to Computers and Programming
1 Introduction to Computing Lecture 02: Introduction to Algorithms Dr. Bekir KARLIK Yasar University Department of Computer Engineering
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
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.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
Introduction to Programming Dr Masitah Ghazali Programming Techniques I SCJ1013.
Algorithms 1 (Lecture 2 of CSE1301)
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Introduction COMP104: Fundamentals and Methodology.
CIS Computer Programming Logic
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.
UniMAP Sem1-08/09EKT120: Computer Programming1 Week 1 – Lecture 1.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
1 BBG2 Algorithms Components of an Algorithm Instructor: M.Fatih AMASYALI
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
1 CSE1301 Computer Programming Lecture 3: Components of an Algorithm.
Al-Khwarizmi 2 (Lecture 3 of CSE1301) Dr Damian Conway Room 132, Building 26 (Consult hours on the door)
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.
1 CSE1301 Computer Programming Lecture 3: Components of an Algorithm.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Chapter 1 : Overview of Computer and Programming By Suraya Alias
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
1 CSE1301 Computer Programming Lecture 4: Components of an Algorithm.
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Introduction to C – Part 1.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
INTRODUCTION TO COMPUTER PROGRAMMING(IT-303) Basics.
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Software Engineering Algorithms, Compilers, & Lifecycle.
Chapter 1 Introduction 2nd Semester H
BASIC PROGRAMMING C SCP1103 (02)
Key Ideas from day 1 slides
Lecture 1: Introduction to JAVA
BASIC PROGRAMMING C SCP1103 (02)
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
DCP2073 Asas Pengaturcaraan C Lecture 3: Components of an Algorithm
Programming COMP104: Fundamentals and Methodology Introduction.
TRANSLATORS AND IDEs Key Revision Points.
Computer Science I CSC 135.
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.
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
ICS103 Programming in C 1: Overview of Computers And Programming
Presentation transcript:

1 CSE Computer Programming “Using C-Language” Lectures 1

Mohamed Shalan CSE Computer Programming 2 Logistics Grading Policy  Final : 75%  Mid-Term : 10%  Homework : 5%  Project : 10% General Rules  Attend 75% of tutorial sessions  Late submission -> No Credit!

Mohamed Shalan CSE Computer Programming 3 Logistics  Don’t send anything unrelated to the class  Don’t insert me into your address book  Make the subject line “CSE 324”  Don’t use any language other than English language  Make sure that your name is included in the

Mohamed Shalan CSE Computer Programming 4 Logistics

Mohamed Shalan CSE Computer Programming 5 Question Why do we write programs?

Mohamed Shalan CSE Computer Programming 6 Hardware vs. Software A computer is made up of hardware and software Hardware Software CPU -e.g. Intel Core 2 Duo Input/Output devices - keyboard - monitor - mouse main memory - e.g. 2GB RAM secondary memory - e.g. 120 GB hard drive operating systems - Windows XP - Mac OS X - Unix / Linux applications - games - Microsoft Word - Internet Explorer

Mohamed Shalan CSE Computer Programming 7 Programs A program is a set of instructions for a computer to follow Following the instructions is called running or executing the program.

Mohamed Shalan CSE Computer Programming 8 Running a Program Sometimes the computer and the program are considered to be one unit.  Programmers typically find this view to be more convenient.

Mohamed Shalan CSE Computer Programming 9 Low-level language (Machine language /assembly language) Programming Languages High-level Programming Languages (e.g. Java) human readable computer readable Compiler translated by

Mohamed Shalan CSE Computer Programming 10 Low-level language (Machine language /assembly language) Programming Languages High-level Programming Languages (e.g. Java) human readable computer readable Compiler translated by Source code Object code

Mohamed Shalan CSE Computer Programming 11 sterilize(saw,alcohol); raise_hammer(); lower hammer(fast); start(saw); /* etc. etc. */ Patient has elevated pressure in anterior parietal lobe The Problem-solving Process "Doctor, my head hurts" Problem specification Algorithm Program Executable ( solution ) Design Implementation Compilation Analysis

Mohamed Shalan CSE Computer Programming 12 The Problem-solving Process Problem specification Algorithm Program Executable (solution) Analysis Design Implementation Compilation

Mohamed Shalan CSE Computer Programming 13 A sequence of instructions specifying the steps required to accomplish some task Named after: Muhammad ibn Musa al-Khwarizmi of Khowarezm (now Khiva in Uzbekistan) Algorithm

Mohamed Shalan CSE Computer Programming 14 Algorithm –History Muhammad ibn Musa Al-Khwarizmi Book on arithmetic:  Hindu numeration, decimal numbers, use of zero, method for finding square root  Latin translation (c.1120 CE): “Algoritmi de numero Indorum” Book on algebra  Hisab al-jabr w’al-muqabala

Mohamed Shalan CSE Computer Programming 15 A sequence of instructions describing how to do a task Algorithm – Working Definition

Mohamed Shalan CSE Computer Programming 16 Algorithm -- Examples A cooking recipe Assembly instructions for a model The rules of how to play a game VCR instructions A car repair manual

Mohamed Shalan CSE Computer Programming 17 From Algorithms to Programs Problem C Program Algorithm Algorithm: A sequence of instructions describing how to do a task (or process)

Mohamed Shalan CSE Computer Programming 18 Components of an Aalgorithm Variables and values Instructions  Sequences  Procedures  Selections  Repetitions Also required: Documentation

Mohamed Shalan CSE Computer Programming 19 Values Represent quantities, amounts or measurements May be numerical or alphabetical (or other things) Often have a unit related to their purpose Example:  Recipe ingredients

Mohamed Shalan CSE Computer Programming 20 Variables This jar can contain 10 cookies 50 grams of sugar 3 slices of cake etc. ValuesVariable Are containers for values – places to store values Example:

Mohamed Shalan CSE Computer Programming 21 Restrictions on Variables Variables may be restricted to contain a specific type of value

Mohamed Shalan CSE Computer Programming 22 Components of an Algorithm Values and Variables Instruction (a.k.a. primitive)  Sequence (of instructions)  Procedure (involving instructions)  Selection (between instructions)  Repetition (of instructions) Documentation (beside instructions)

Mohamed Shalan CSE Computer Programming 23 Instructions (Primitives) Some action that is  simple  unambiguous  that the system knows about... ...and should be able to actually do

Mohamed Shalan CSE Computer Programming 24 Instructions -- Application Some instructions can only be applied to a specific type of values or variables Examples:

Mohamed Shalan CSE Computer Programming 25 Sequence A series of instructions...to be carried out one after the other......without hesitation or question Example:  How to cook a Gourmet Meal TM

Mohamed Shalan CSE Computer Programming 26 Sequence -- Example 1. Open freezer door 2. Take out Gourmet Meal™ 3. Close freezer door 4. Open microwave door 5. Put Gourmet Meal™ on carousel 6. Shut microwave door 7. Set microwave on high for 5 minutes 8. Start microwave 9. Wait 5 minutes 10. Open microwave door 11. Remove Gourmet Meal™ 12. Close microwave door

Mohamed Shalan CSE Computer Programming 27 Procedure A named sequence of instructions So that you can  Refer to it collectively (by name) ...instead of individually (by each instruction in the sequence) Example:  Drive_To_Uni

Mohamed Shalan CSE Computer Programming 28 Procedure -- Example procedure Drive_To_Uni { 1. find car keys 2. disable car alarm 3. open car door 4. get in car 5. shut car door 6. put keys in ignition 7. start car 8. back car out of driveway 9. drive to end of street 10. turn right 11. drive to end of street 12. turn left...etc...etc...etc...etc...etc...etc find parking space 53. pull into parking space 54. turn off engine 55. remove keys from ignition 56. open car door 57. get out 58. shut car door 59. lock car door 60. enable alarm }

Mohamed Shalan CSE Computer Programming 29 Procedure – Example (cont) procedure Do_Wednesday { Wake_up Have_Shower Eat_Breakfast Drive_To_Uni Sit_1301_Lecture...etc...etc...etc... Drive_From_Uni...etc...etc...etc... } procedure Do_Week { Do_Monday Do_Tuesday Do_Wednesday Do_Thursday...etc...etc...etc... }

Mohamed Shalan CSE Computer Programming 30 Selection An instruction that decides which of two possible sequences is executed The decision is based on a single true/false condition Examples:  Car repair

Mohamed Shalan CSE Computer Programming 31 Selection Example -- Car Repair if (motor turns) then { CheckFuel CheckSparkPlugs CheckCarburettor } else { CheckDistributor CheckIgnitionCoil }

Mohamed Shalan CSE Computer Programming 32 Selection Example – Car Repair (cont) if (motor turns) then { CheckFuel CheckSparkPlugs CheckCarburettor } else { CheckDistributor CheckIgnitionCoil } Should be a true or false condition.

Mohamed Shalan CSE Computer Programming 33 Selection Example – Car Repair (cont) if (motor turns) then { CheckFuel CheckSparkPlugs CheckCarburettor } else { CheckDistributor CheckIgnitionCoil } Sequence if the condition is true.

Mohamed Shalan CSE Computer Programming 34 Selection Example – Car Repair (cont) if (motor turns) then { CheckFuel CheckSparkPlugs CheckCarburettor } else { CheckDistributor CheckIgnitionCoil } Sequence if the condition is false.

Mohamed Shalan CSE Computer Programming 35 Repetition Repeat an instruction... ...while (or maybe until) some true or false condition occurs  Test the condition each time before repeating the instruction Also known as iteration or loop Example:  Algorithm used by a kid to convince his mom to buy a toy

Mohamed Shalan CSE Computer Programming 36 Repetition -- Example procedure Ask ( toy ) { Say("Hey mom; I want to buy a“, toy) ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say("Oh please!") add 1 to begging count ListenToReply ( ) } }

Mohamed Shalan CSE Computer Programming 37 Repetition – Example (cont) procedure Ask ( toy ) { Say("Hey mom; I want to buy a“, toy) ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say("Oh please!") add 1 to begging count ListenToReply ( ) } } Condition is tested before sequence

Mohamed Shalan CSE Computer Programming 38 Repetition – Example (cont) procedure Ask ( toy ) { Say("Hey mom; I want to buy a“, toy) ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say("Oh please!") add 1 to begging count ListenToReply ( ) } } Sequence may not get executed at all

Mohamed Shalan CSE Computer Programming 39 Repetition – Example (cont) procedure Ask ( toy ) { Say("Hey mom; I want to buy a“, toy) ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say("Oh please!") add 1 to begging count ListenToReply ( ) } } Ensure initial values of variables used in the conditions are set correctly

Mohamed Shalan CSE Computer Programming 40 Repetition – Example (cont) procedure Ask ( toy ) { Say("Hey mom; I want to buy a“, toy) ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say("Oh please!") add 1 to begging count ListenToReply ( ) } } Ensure the variables used in the conditions are updated in each iteration

Mohamed Shalan CSE Computer Programming 41 Repetition – Example (cont) procedure Ask ( toy ) { Say("Hey mom; I want to buy a“, toy) ListenToReply ( ) start begging count at zero while (reply is "No" and begging count < 100) { Say("Oh please!") add 1 to begging count ListenToReply ( ) } } Infinite loop What if we don’t increment the begging count?

Mohamed Shalan CSE Computer Programming 42 Documentation Records what the algorithm does Describes how it does it Explains the purpose of each component of the algorithm Notes restrictions or expectations

Mohamed Shalan CSE Computer Programming 43 From Algorithms to Programs Both are sets of instructions on how to do a task  Algorithm: talking to humans, easy to understand in plain (English) language  Program: talking to computer (compiler) can be regarded as a “formal expression” of an algorithm

Mohamed Shalan CSE Computer Programming 44 High-Level Language Compilers and linkers translate a high level program into executable machine code. #include int main() { printf(“Hello World”); return 0; } Source code Executable code etc...

Mohamed Shalan CSE Computer Programming 45 Developing a C Program Use Text Editor to edit the “source file” (.c). Editor + Compiler + Linker + Debugger = IDE Debugging: Finding logical error (bugs) and eliminate them.