Lecture2.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Introducing C++ Elements. CSCE 1062 Outline Main algorithms’ constructs General form of a C++ program {section 2.5} C++ language elements {section 2.1}
Computer Programming w/ Eng. Applications
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Computer Science Department FTSM Variables and Constants Knowledge: Understand the concept of storage location representation as identifiers Skill: Identify.
1 CS 201 Introduction to C (1) Debzani Deb. 2 Outline Overview of C General form of a C program C Language Elements.
Software Development Method & C Language Elements H&K Chapter 1-2
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Structure of a C program
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.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
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.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
King Saud University College of applied studies and community services CSC 1101 Computer Programming I Lecture 2.
Lecture #5 Introduction to C++
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Introduction to Programming
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
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.
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.
9/29/99B-1 CSE / ENGR 142 Programming I Variables, Values, and Types © 1998 UW CSE.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 1: Introduction to Computers and Programming.
C Language Elements Preprocessor Directives # (sign for preprocessor directive commands) #include Standard header file (.h) Library.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Lecture2.
Numbers in ‘C’ Two general categories: Integers Floats
Chapter # 2 Part 2 Programs And data
CSCE 206 Structured Programming in C
Chapter Topics The Basics of a C++ Program Data Types
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chapter 2 - Introduction to C Programming
Topic: Python’s building blocks -> Variables, Values, and Types
Basic Elements of C++.
What's a Computer? Monitor Disk Main mouse Memory Keyboard Network
Revision Lecture
Chapter 2 Overview of C.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Chapter 2 - Introduction to C Programming
Choice of Programming Language
Basic Elements of C++ Chapter 2.
IDENTIFIERS CSC 111.
Chapter 2 - Introduction to C Programming
CC213 Programming Applications
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
CS150 Introduction to Computer Science 1
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter 2 - Introduction to C Programming
Lecture3.
Chapter # 2 Part 2 Programs And data
WEEK-2.
Review of C++ Language Basics
Chapter 2 - Introduction to C Programming
DATA TYPES There are four basic data types associated with variables:
Getting Started With Coding
Presentation transcript:

Lecture2

Lecture Outline The Software Development Method Exercise C Language Elements Preprocessor Directives Function Main Declarations Executable Statements Reserved Words, Standard Identifiers & User-Defined Identifier User-Defined Identifier Rules Reading: Chapter 2

The Software Development Method 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. 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 (60 - 84), the number of cold days (less than 60). It should also display the category of each temperature. C Language Elements

Exercise 1. Specify the problem requirements A program is required to process daily temperatures and provide the total number of hot, pleasant, and cold days. 2. Analyze the problem Input: Output: temperature 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. C Language Elements

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

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

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

#include Preprocessor Directive Syntax #include <library> Examples #include <stdio.h> #include <math.h> C Language Elements

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

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

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

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

Data Types 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 C Language Elements

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

Float 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: 3.643 0.325 123.532 3.4 C Language Elements

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

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

User-Defined Identifier Rules 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. C Language Elements

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

C Language Elements #include <stdio.h> #define KMS_PER_MILE 1.609 int main(void) { float miles, kms; } (Executable statements) C Language Elements