Computer Programming 1 Lecture-2 Instructor: Nasir Khan

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 1 Engineering Problem Solving.
Advertisements

EC-111 Algorithms & Computing Lecture #1 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Senem Kumova Metin Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Lecture 1: Overview of Computers & Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
COSC 120 Computer Programming
Three types of computer languages
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
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.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Computer Programming Lecture Slides Politehnica Timisoara International- Computer Engineering Study Program.
CS102 Introduction to Computer Programming
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
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.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
1 Lecture 2 : Computer System and Programming. Computer? a programmable machine that  Receives input  Stores and manipulates data  Provides output.
Topics Introduction Hardware and Software How Computers Store Data
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
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.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
CISC105 General Computer Science Class 1 – 6/5/2006.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
C++ Programming Language Lecture 1 Introduction By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Introduction Lecture 01.
Introduction to Computer Programming in c
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.
1 Lecture 2 : Computer System and Programming. Computer? a programmable machine that  Receives input  Stores and manipulates data  Provides output.
Computer Programming Politehnica International- Computer Engineering Lecture Slides.
Introduction to Computer Programming in c
Computing Systems & Programming ECE Fundamental Concepts Chapter 1 Engineering Problem Solving.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Chapter 1: Introduction to Computers and Programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Chapter 1: Introduction to Computers and Programming
CSC201: Computer Programming
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Java programming lecture one
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Chapter 1: Introduction to Computers and Programming
CS190/295 Programming in Python for Life Sciences: Lecture 1
Computer Science I CSC 135.
Royal University of Phnom Penh Department of Computer Science
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Computer Programming
Computer Programming-1 CSC 111
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Computer Programming 1 Lecture-2 Instructor: Nasir Khan

Learning Objectives First course in Computer Science No previous knowledge is assumed ! By the end of the course, students will: Understand fundamental concepts of computer programming/imperative structured programming languages Design algorithms to solve (simple) problems Use the C programming language 2

Textbooks C The Complete Reference, 4 th Edition The C Programming Language by DENNIS M.RITCHIE and BRIAN W.KERNIGHAN C How to Program, 5/E (Harvey & Paul) Deitel & Deitel, Prentice Hall Copyright: 2007 Robert Lafore,The Waite Group’s Turbo C, Programming for the PC and Turbo C++ 3

The course will consist of : 32 lectures 4-5 assignments 4-5 Quiz's 2exams (1 midterm and 1 final) Grading Criteria: Midterm: 30 % Final Exam: 50% Quiz's/Assignments: 15% Class Participation: 5% Course Outline 4

Fundamentals – Chapter outline: Classical model for computing machines Programming Programming languages Compiling Operating system Setting the basic concepts and terminology … 5

Model of a computing machine Computing machine (Computer): “a machine that stores and manipulates information under the control of a changeable program that is stored in its memory.” Pocket calculator: not a computer ! Manipulates information, but is built to do a specific task (no changeable stored program) This model is named the “von Neumann architecture” (John von Neumann – 1945; EDVAC - Electronic Discrete Variable Automatic Computer – the first stored-program computer) Stored-program concept: earlier ideas in theoretical articles of: Alan Turing (1936), Konrad Zuse (1936) 6

Model of a computing machine Optional reading: History of computing – IEEE Computer Society – timeline of occasions in computing history 7

Input Unit Output Unit Memory Unit Arithmetic & Logic Unit (ALU) Central Processing Unit (CPU) Secondary Storage Unit 8 Computer Organization

The von Neumann architecture Input DeviceOutput Device ALUCU CPU Main memory (RAM) Secondary storage 9

The von Neumann architecture Central Processing Unit (CPU): the “brain” of the machine. CU: Control Unit ALU: Arithmetic and Logic Unit Carries out all basic operations of the computer Examples of basic operation: adding two numbers, testing to see if two numbers are equal. Main memory (called RAM for Random Access Memory): stores programs and data Fast but volatile Secondary memory: provides permanent storage Human-computer interaction: through input and output devices. keyboard, mouse, monitor Information from input devices is processed by the CPU and may be sent to the main or secondary memory. When information needs to be displayed, the CPU sends it to the output device(s). 10

How it works How does a computer execute a program ? (example programs: a computer game, a word processor, etc) the instructions that comprise the program are copied from the permanent secondary memory into the main memory After the instructions are loaded, the CPU starts executing the program. For each instruction, the instruction is retrieved from memory, decoded to figure out what it represents, and the appropriate action carried out. (the fetch- execute cycle) Then the next instruction is fetched, decoded and executed. 11

High level languages Writing portable programs, using more abstract instructions High-level languages allow programmers to write instructions that look almost like everyday English and contain commonly used mathematical notations. A high level instruction (statement) is translated into many machine instructions Translation of high level language into machine instructions: done by special computer programs – compilers or interpreters 12

Compilers/Interpreters Compiler Source Code Machine Code Executable Program Input data Output data Interpreter Source Code Input data Output data Compiler: analyzes program and translates it into machine language Executable program: can be run independently from compiler as many times => fast execution Interpreter: analyzes and executes program statements at the same time Execution is slower Easier to debug program 13

Higher Level Languages Programming Paradigms: Imperative Programming: describes the exact sequences of commands to be executed Structured programming, procedural programming FORTRAN, C, PASCAL, … Object oriented programming C++, Java, C#, … Declarative programming: program describes what it should do, not how Functional programming Lisp, ML, … Logic Programming Prolog 14

Basic Terminologies Client-server architecture (client/server) is a network architecture in which each computer or process on the network is either a client or a server. Servers are powerful computers or processes dedicated to managing disk drives (file servers), printers (print servers), or network traffic (network servers ). Clients are PCs or workstations on which users run applications. Clients rely on servers for resources, such as files, devices, and even processing power.network architecturecomputerclientserverServersdedicateddisk drivesfile serversprintersprint serverstrafficnetworkservers PCsworkstationsapplicationsresources filesdevices Another type of network architecture is known as a peer-to- peer architecture because each node has equivalent responsibilities. Both client/server and peer-to-peer architectures are widely used, and each has unique advantages and disadvantages.nodepeer-to-peer architectures 15

Cont…. World Wide Web which allows computer users to locate and view multimedia-based documents on almost any subject over the Internet. The Internet has exploded into one of the world's premier communication mechanisms. 16

The C Programming Language Developed by Dennis Ritchie at AT&T Bell Laboratories in the early 1970s Growth of C tightly coupled with growth of Unix: Unix was written mostly in C Success of PCs: need of porting C on MS-DOS Many providers of C compilers for many different platforms => need for standardization of the C language 1990: ANSI C (American National Standards Institute) International Standard Organization: ISO/IEC 9899: : standard updated: C99, or ISO/IEC 9899:

The format in C Statements are terminated with semicolons Indentation is nice to be used for increased readability. Free format: white spaces and indentation is ignored by compiler C is case sensitive – pay attention to lower and upper case letters when typing ! All C keywords and standard functions are lower case Typing INT, Int, etc instead of int is a compiler error Strings are placed in double quotes New line is represented by \n (Escape sequence) 18

The first C program #include int main (void) { printf ("Programming is fun.\n"); return 0; } uses standard library input and output functions (printf) the program begin of program end of program statements main: a special name that indicates where the program must begin execution. It is a special function. first statement: calls a routine named printf, with argument the string of characters “Programming is fun \n” last statement: finishes execution of main and returns to the system a status value of 0 (conventional value for OK) 19

Compiling and running C programs Editor Compiler Linker Source code file.c Object code file.obj Executable code file.exe Libraries IDE (Integrated Development Environment) 20

C Compilers and IDE’s One can: use a text editor to edit source code, and then use independent command-line compilers and linkers use an IDE: everything together + facilities to debug, develop and organize large projects There are several C compilers and IDE’s that support various C compilers Lab: Dev-C++ IDE for C and C++, Free Software (under the GNU General Public License) Works with gcc (GNU C Compiler) supports the C99 standard available on Windows and Unix The GNU Project ( launched in 1984 in order to develop a complete Unix-like operating system which is free software - the GNU system. 21

Debugging program errors Editor Compiler Linker Source code file.c Object code file.obj Executable code file.exe Libraries Syntactic Errors Semantic Errors 22

Syntax and Semantics Syntax errors: violation of programming language rules (grammar) "Me speak English good." Use valid C symbols in wrong places Detected by the compiler Semantics errors: errors in meaning: "This sentence is excellent Italian." Programs are syntactically correct but don’t produce the expected output User observes output of running program 23

Second program #include int main (void) { printf ("Programming is fun.\n"); printf ("And programming in C is even more fun.\n"); return 0; } 24

Displaying multiple lines of text #include int main (void) { printf ("Testing...\n..1\n...2\n....3\n"); return 0; } Output: Testing It is not necessary to make a separate call to printf for each line of output ! 25

Variables Programs can use symbolic names for storing computation data and results Variable: a symbolic name for a memory location programmer doesn’t has to worry about specifying (or even knowing) the value of the location’s address In C, variables have to be declared before they are used 26

Using and Displaying Variables #include int main (void) { int sum; sum = ; printf ("The sum of 50 and 25 is %i\n", sum); return 0; } Variable sum declared of type int Variable sum assigned expression Value of variable sum is printed in place of %i The printf routine call has now 2 arguments: first argument a string containing also a format specifier (%i), that holds place for an integer value to be inserted here 27

Displaying multiple values #include int main (void) { int value1, value2, sum; value1 = 50; value2 = 25; sum = value1 + value2; printf ("The sum of %i and %i is %i\n",value1, value2, sum); return 0; } The format string must contain as many placeholders as expressions to be printed 28

Using comments in a program Comment statements are used in a program to document it and to enhance its readability. Useful for human readers of the program – compiler ignores comments Ways to insert comments in C: –When comments span several lines: start marked with /*, end marked with */ –Comments at the end of a line: start marked with // 29

Using comments in a program /* This program adds two integer values and displays the results */ #include int main (void) { // Declare variables int value1, value2, sum; // Assign values and calculate their sum value1 = 50; value2 = 25; sum = value1 + value2; // Display the result printf ("The sum of %i and %i is %i\n", value1, value2, sum); return 0; } 30