Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.

Slides:



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

Lecture 2 Introduction to C Programming
Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Structure of a C program
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
Basic Elements of C++ Chapter 2.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Chapter 01: Introduction to Computer Programming
COMPUTER SCIENCE I C++ INTRODUCTION
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Lecture #5 Introduction to C++
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Week 1 Algorithmization and Programming Languages.
C++ Programming: Basic Elements of C++.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 2 Variables.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
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.
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Data types Data types Basic types
BASIC ELEMENTS OF A COMPUTER PROGRAM
Basic Elements of C++.
Revision Lecture
Java Programming: From Problem Analysis to Program Design, 4e
Introduction to C Programming
Basic Elements of C++ Chapter 2.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to C++ Programming
Chapter 2: Basic Elements of Java
Introduction to C Programming
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter 2: Introduction to C++.
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1

An Introduction to Programming with C, Fifth Edition 2 Creating a C Program source code Object code Executable code: exe file created using an IDE

Processing a C Program (cont'd.) C Programming: From Problem Analysis to Program Design, Fifth Edition 3

The Problem Analysis–Coding– Execution Cycle (cont’d.) C++ Programming: From Problem Analysis to Program Design, Fifth Edition 4

Structure of C Program #include void main( ) { printf(“Welcome to Computer Scientists”); getch(); } Program Body main function Starting point of program execution Preprocessor Directives Header File To include header files in our program Contains built-in-functions. These are also called pre-defined or already developed functions File name(standard input output ) h stands for header file Function Name Return type of main function. It is used to determines whether the program is executed successfully or not. Void means nothing Parenthesis shows function. It is used to pass parameters/arguments Body Begin Body End Printtf satns for print funtion. It us used to print the output on the monitor/console. Angle or pointed brackets String or message to be displayed on monitor. It must be enclosed in double quotes(“ “) Each statement must end with semicolon. A statement without semicolon generates syntax error Get character function. It get a character at runtime. But we use it to stay screen to see output 5

Memory Concepts Variable names Correspond to actual locations in computer's memory Every variable has name, type, size and value When new value placed into variable, overwrites previous value 6

Alphabets from A to Z or a to z The digits from 0 to 9 Underscore(_) can be used The first character of an identifier can not be a digit The name of an identifier can not be a reserve word No space allowed in the name of identifier Rules to Declare an Identifier (variable) Valid Name: A Student_Name _Fname Pi Inalid Name: $Sum //special ch. 6StName // 1 st letter digit F name // no space allowed int // reserve word 7 Variable: Location in memory where value can be stored An identifier is a name for a variable, constant, function, etc.

Syntax Data-Type Space Variable-Name(Indentifier); e.g. int frstNumber; char choice; float divide; long output; Identifier (variable) Declaration Data-Type Space Variable-Name(Indentifier) = Value; e.g. int frstNumber=10; char choice=‘y’; float divide=0.0; Syntax Identifier (variable) Initialization 8

Memory Concepts scanf(“%d”,& first); Assume user entered 45 scanf(“%d”,& second); Assume user entered 72 sum = first + second; first 45 first 45 second 72 first 45 second 72 sum 117 Identifier Variable 9

Assignment Operator (=) = (assignment operator) Assigns value to variable Binary operator (two operands) Example: sum = variable1 + variable2; 10

How many bytes I am eating? integer data short2 bytes int2 bytes(16 bit system) 4 bytes (32 bit system) long4 bytes Floating point data float4 bytes double8 bytes long double10 bytes Characterchar 1 byte Booleanbool 1 byte 11

12 Memory Allocation for Arithmetic Data Types Size (bytes)Range of Values Name (alternate)Description AVR GCCMSVC++AVR GCCMSVC++ charCharacter or small integer11 Signed: -128 to 127 (-2 (8-1) to 2 (8-1) -1) Unsigned: 0 to 255 (0 to ) Signed: -128 to 127 Unsigned: 0 to 255 short int (short)Short integer22 Signed: to Unsigned: 0 to Signed: -32,768 to 32,767 Unsigned: 0 to intInteger24 Signed: to Unsigned: 0 to Signed: -2,147,483,648 to 2,147,483,647 Unsigned: 0 to 4,294,967,295 long int (long)Long integer44 Signed: -2,147,483,648 to 2,147,483,647 Unsigned: 0 to 4,294,967,295 Signed: -2,147,483,648 to 2,147,483,647 Unsigned: 0 to 4,294,967,295 long long int (long long)Really long integer88 Signed:  -9.2E+18 to  9.2E+18 Unsigned: 0 to  1.8E+19 Signed:  -9.2E+18 to  9.2E+18 Unsigned: 0 to  1.8E+19 float'Single-precision' floating point number44   1E  38 (7 decimal digits of precision) double'Double-precision' floating point number48   1E  38 (7 decimal digits of precision)   1E  308 (15 decimal digits of precision) long double Long double-precision floating point number8   1E  308 (15 decimal digits of precision)

13

Arithmetic Rules of operator precedence Operators in parentheses evaluated first Nested/embedded parentheses  Operators in innermost pair first Multiplication, division, modulus applied next Operators applied from left to right Addition, subtraction applied last Operators applied from left to right 14

Comments Non - executable statements Comments are used for program documentation Two formats Single Line CommentsMulti Lines Comments // This program is used to show the Welcome Message. /* This program is used to show the square of even numbers from 10 to 100. */ 15

Tokens Tokens are individual words and punctuation marks in passage of text. In C++, program the smallest individual units are known as C Tokens. C++ has Six types of Tokens. The Tokens are shown in figure. C++ programs are written using these tokens and the syntax of the language. 16

17

C++ keywords Each keyword has a predefined purpose in the language. Do not use keywords as variable and constant names!! Exmples: bool, break, case, char, const, continue, do, default, double, else, extern, false, float, for, if, int, long, namespace, return, short, static, struct, switch, typedef, true, unsigned, void, while etc etc.. 18

19 Thank You New Computer Scientists