King Saud University College of applied studies and community services CSC 1101 Computer Programming I Lecture 2.

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.
King Saud University College of applied studies and community services CSC 206 Programming with Basic Lecture 1.
1 CS 201 Introduction to C (1) Debzani Deb. 2 Outline Overview of C General form of a C program C Language Elements.
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
Three types of computer languages
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
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?
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
C programming Language and Data Structure For DIT Students.
Chapter 1 Introduction to Programming. Computer Hardware CPU Memory –Main or primary –Secondary or auxiliary Input device(s) Output device(s)
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CS102 Introduction to Computer Programming
Chapter Introduction to Computers and Programming 1.
COMPUTER SCIENCE I C++ INTRODUCTION
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.
 2008 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
CIS Computer Programming Logic
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.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
EKT 120/4 C Programming (Additional note). Computer Fundamentals Computer is a machine that can receive, store, transform an output data of all kinds.
Input, Output, and Processing
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
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.
CC112 Structured Programming Lecture 2 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.
CHAPTER # 2 Part 2 PROGRAMS AND DATA 1 st semster King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
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.
1 12/4/1435 h Lecture 2 Programs and Programming Languages.
FOUNDATION IN INFORMATION TECHNOLOGY (CS-T-101) TOPIC : INFORMATION SYSTEM – SOFTWARE.
Overview of C. C—a high-level programming language developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories. We will discuss: –the elements of a.
CS-303 Introduction to Programming
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
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.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 1: Introduction to Computers and Programming.
CHAPTER 1 OVERVIEW OF COMPUTER AND PROGRAMMING 1.1 Electronic Computer Then and Now 1.2 Computer Hardware 1.3 Computer Software 1.4 The Software Development.
Chapter 1 Introduction 2nd Semester H
Chapter # 2 Part 2 Programs And data
Algorithm: procedure in terms of
CSCI-235 Micro-Computer Applications
Computer Programming.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Revision Lecture
ICS103 Programming in C Lecture 3: Introduction to C (2)
Lecture2.
Choice of Programming Language
(Course Introduction)
Structured Program
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.
C programming Language
Presentation transcript:

King Saud University College of applied studies and community services CSC 1101 Computer Programming I Lecture 2

Course Introduction1 Lecture Outline What Is A Computer Program? Software? Why Program? What Makes A Good Programmer? An Overview of Computer Languages History Of C Why C? Flow of Information During Program Execution The Software Development Method An Example of Meter to Yard Conversion Algorithm Pseudocode Flowcharts

What Is A Computer Program? Software? Program = set of instructions that a computer will follow to perform a specific task. Software = collection of programs. Course Introduction2 Two types of software: System software: used to manage computer hardware to enable us to execute & write application programs/software. Ex. Operating System, Compilers, …etc. Application Software: are meant for solving users own problems. Ex. Word processors, database management…etc.

Course Introduction3 Why Program? A tailor-made program is required. Programmers are in high demand. Programming is an intellectual challenge.

Course Introduction4 What Makes A Good Programmer? Two main factors: Knowledge: data structures, algorithms, tools, when and how to use those tools, & experience. Maturity: patience, humility, & time management. Only the first one can be taught. Good programmers are more than 10 times productive as average ones (does not mean they write 10 times as many lines of code per day).

An Overview Of Computer Languages Course Introduction5 Machine Language Assembly Language High-Level Language Ex.Ex. Ex MOV AX,A A = A ADD AX, MOV A,AX Collection of binarySymbolic form of machine Combines algebraic numberslanguage (I.e. symbolic expressions & symbols taken names are used to represent from English language operations, registers & (ex. C, Pascal, memory locations FORTRAN, …etc) Directly understood by aAssembler Compiler (or interpreter) computerconverts to machine converts to machine language Easier to use More powerful

An Overview Of Computer Languages (Continue) Course Introduction7 C is sometimes called a middle-level language. This is not a reflection on its lack of programming power. It’s a reflection on its capability to access the system’s low-level functions.

History Of C Course Introduction8 Created by Dennis Ritchie at the Bell Telephone laboratories in Evolved from a language called B.

Why Use C? Course Introduction9 C is a powerful and flexible language. C is used for projects as diverse as operating systems, word processors, graphics, spreadsheets, and even compilers for other languages. C is a popular language preferred by professional programmers. As a result, a wide variety of C compilers and helpful accessories are available. C is a portable language. Portable means that a C program written for one computer system can be compiled and run on another system with little or no modification (hardware independent). Portability is enhanced by the ANSI standard for C, the set of rules for C compilers.

Why Use C? Course Introduction10 C is a language of few words, containing only a handful of terms called keywords, which serve as the base on which the language’s functionality is built. C is modular, C code should be written in routines called functions. These functions can be reused in other applications or programs. By passing pieces of information to the functions, you can create useful, reusable code.

Software Development Method

The Software Development Method Course Introduction7 1. Specify the problem requirements. 2. Analyze the problem. 3. Design the algorithm to solve the problem. 4. Implement the algorithm. 5. Test and verify the completed program. 6. Maintain and update the program.

An Example of Meter to Yard Conversion Course Introduction8 1. Specify the problem requirements 2. Analyze the problem Problem Input: Problem Output: Formulas: size in square meters (decimal) A program is required to convert square meters to square yards. size in square yards (decimal) square yards = * square meters 3. Design the algorithm to solve the problem 1. Read the fabric size in square meters. 2. Convert the fabric size to square yards using the formula. 3. Display the fabric size in square yards.

Course Introduction9 4. Implement the algorithm (i.e. write the program) 5. Test and verify the completed program. 6. Maintain and update the program. An Example of Meter to Yard Conversion

Algorithm Course Introduction10 An Algorithm is a procedure for solving a problem in terms of: 1. the actions to be executed 2- the order in which these actions are executed

Pseudocode Course Introduction11 Pseudocode is an artificial and informal language that helps programmer develop algorithms. It is similar to everyday English. It is not a computer programming language. Example Get out of Bed Take a shower Get dressed Eat breakfast Drive to work

Flowcharts Course Introduction12 A flowchart is a graphical representation of an algorithm. They are drawn using rectangles, diamonds, ovals, and small circles.

Flowcharts (Continue) Course Introduction13 Start or End Input or Output Process or Calculation Decision

C Language Elements Exercise 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. 19

C Language Elements Exercise 1. Specify the problem requirements 2. Analyze the problem Input: Output: temperature A program is required to process daily temperatures and provide the total number of hot, pleasant, and cold days. total number of days in each category 3. Design the algorithm to solve the problem 1. Get the temperature. 2. Determine category of that temperature and increment counter for that particular category. 3. Display categories and total number of days that fell under the category. 20

C Language Elements >=85? Print Hot, Cold, and Pleasant End Add 1 to Hot Yes Add 1 to Cold Yes <=60? No Add 1 to Pleasant No Get Temp Exercise Start 21

C Language Elements

Lecture Outline C Language Elements Preprocessor Directives Function Main Declarations Executable Statements Reserved Words, Standard Identifiers & User- Defined Identifier User-Defined Identifier Rules 23

C Language Elements Preprocessor Directive A C program line beginning with # that provides an instruction to the preprocessor. Preprocessor A system program that modifies a C program prior to its compilation. Two important preprocessor directives are: #include #define C Language Elements 24

#include Preprocessor Directive C Language Elements Syntax #include Examples #include 25

C Language Elements #define Preprocessor Directive Syntax #define NAME value Examples #define PI 3.14 #define section

C Language Elements Syntax int main(void) { } (declarations) (Executable statements) It marks the beginning of any C program. Function Main 27

C Language Elements The part of a program that tells the compiler the names of memory cells in a program Declarations Executable Statements Program commands that are converted to machine code by the compiler. 28

Declarations C Language Elements Syntax Data type variable; Examples int count, large; float area; char first; int count, large; 29

Data Types C Language Elements It is a set of values. It defines operations that can be performed on those values. The most used data types are: int float char 30

int C Language Elements The int data type represents integers in C. Integers are whole numbers. ANSI defined the range of integers as being between and Examples:

Float C Language Elements The float data type represents real numbers in C. A real number has an integral part and a fractional part separated by a decimal point. Examples:

char C Language Elements The char represents one individual character in C. Examples: 'D' 'd' '5' '*' 33

Reserved Words, Standard Identifiers & User-Defined Identifier C Language Elements A reserved word is a word that has a special meaning in C and cannot be used for other purposes. Example: int, double, char, void. A standard identifier is a word that has a special meaning in C but can be used for other purposes or redefined. Example: printf, scanf. A user-defined identifier is a name given to a variable. Does not have a special meaning in C and needs to be declared. Example: PI, large, hot. 34

User-Defined Identifier Rules C Language Elements An identifier must consist only of letters, digits, and underscores. An Identifier cannot begin with a digit. A C reserved word cannot be used as an identifier. A standard identifier should not de redefined. 35

User-Defined Identifier Rules C Language Elements Examples: letter2 21etter letter_2 int joe's variable cent_per_inch Begins with a digit Reserved word Character ’ not allowed 36

C Language Elements #include #define KMS_PER_MILE int main(void) { float miles, kms; } (Executable statements) 37