Objectives You should be able to describe: Introduction to Programming

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Chapter 1 Getting Started
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
 2005 Pearson Education, Inc. All rights reserved Introduction.
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Chapter 1: Introduction
Three types of computer languages
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Simplest program and Data Output Sen Zhang. The simplest program looks like a single person company! void main() { // this starts a comment line // here.
Introduction to Programming
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
Chapter 2: Introduction to C++.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Introduction to C Programming
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
COMPUTER SCIENCE I C++ INTRODUCTION
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
A First Book of ANSI C Fourth Edition
Chapter 1: Creating Java Programs
1Object-Oriented Program Development Using C++ Computer Science and Programming Languages Computers are ubiquitous Computer literacy is essential Computer.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Hello World 2 What does all that mean?.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
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.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Week 1 Algorithmization and Programming Languages.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Unix. Shell??? You will interact with UNIX through a special program called the shell. The shell prompts you for commands and hands these off to the operating.
Basic Program Construction
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
A First Book of C++ Chapter 1 Getting Started. Objectives In this chapter, you will learn about: –Introduction to Programming –Function and Class Names.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
C++ First Steps.
Programming what is C++
Chapter 1: Introduction to computers and C++ Programming
Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
CSC201: Computer Programming
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Chapter 2: Problem Solving Using C++
C++ for Engineers and Scientists Second Edition
Chapter 2 – Getting Started
2.1 Parts of a C++ Program.
Introduction to C++ Programming
1.2 Function and Class Names
Chapter 2: Introduction to C++.
Introduction to Programming - 1
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Objectives You should be able to describe: Introduction to Programming Function and Class Names The cout object Programming Style Common Programming Errors A First Book of C++: From Here To There, Third Edition

Introduction to Programming Computer program: Data and instructions used to operate a computer Programming: Writing computer program in a language that the computer can respond to and that other programmers can understand Programming language: Set of instructions, data, and rules used to construct a program High-level languages use human language type instructions Low-level languages use instructions tied to a computer type A First Book of C++: From Here To There, Third Edition

Procedural Programming Languages Instructions are used to create self-contained units (procedures) Procedures accept data as input and transform data to produce a specific result as an output Initially, high-level programming languages were predominately procedural A First Book of C++: From Here To There, Third Edition

Procedure-Oriented Programs Most high-level programs process data to produce one or more results Procedural programs are constructed from sets of instructions, with each set called a procedure Each procedure moves the data one step closer to the final desired output A First Book of C++: From Here To There, Third Edition

Procedure-Oriented Programs (continued) A First Book of C++: From Here To There, Third Edition

Object-Oriented Languages Allow for procedural instructions and for definitions of objects to be manipulated Such definitions include: The general characteristics of objects Specific operations to manipulate objects C++ is an object-oriented language Has procedures and objects Supports code reuse A First Book of C++: From Here To There, Third Edition

History of C++ C++ began as extension to C, which is procedural language developed in the 1970s at AT&T Bell Laboratories In early 1980s, Bjarne Stroustrup (also at AT&T) used his background in simulation languages to develop C++ Object-orientation and other procedural improvements were combined with existing C language features to form C++ A First Book of C++: From Here To There, Third Edition

Algorithms and Procedures Before writing a program, a programmer must clearly understand What data is to be used Desired result Procedure needed to produce this result The procedure is referred to as an algorithm Algorithm: Step-by-step sequence of instructions describing how to perform a computation A First Book of C++: From Here To There, Third Edition

Example of an Algorithm Assume that a program must calculate sum of all whole numbers from 1 through 100 A computer can not respond to heuristic command: “Add the numbers from 1 - 100” A computer is algorithm-responding machine and not intuition-responding machine Several methods or algorithms can be used to find the required sum A First Book of C++: From Here To There, Third Edition

Example of an Algorithm (continued) Sum = n(a + b)/2 Where n = number of terms to be added (100) a = first number added (1) b = last number to be added (100) Sum = 100(1 + 100)/2 = 5050 Figure 1.2: Summing the Numbers from 1 through 100 Method 3. Formula - Use the formula Sum = n(a + b)/2 = 5050 A First Book of C++: From Here To There, Third Edition

Flowcharting A First Book of C++: From Here To There, Third Edition

Flowcharting A First Book of C++: From Here To There, Third Edition

Flowchart Example A First Book of C++: From Here To There, Third Edition

Classes and Objects Data Object: Set of values packaged as single unit Class: Set of objects with similar attributes General concept of object-oriented programming is difference between an object and the larger set of which it is a member (class) A red, Ford Taurus sedan is an instance, or object, of general class of automobiles A First Book of C++: From Here To There, Third Edition

Program Translation C++ source program: Set of instructions written in C++ language Machine language: Internal computer language Consists of a series of 1s and 0s Source program cannot be executed until it is translated into machine language Interpreted language translates one statement at a time Compiled language translates all statements together A First Book of C++: From Here To There, Third Edition

Program Translation (continued) A First Book of C++: From Here To There, Third Edition

Function and Class Names Modular programs: Segments arranged in logical order to form an integrated unit Module: Segments of modular program Function: Name of a C++ procedure Composed of sequence of C++ instructions Function interface is its inputs and outputs Method of converting input to results is encapsulated and hidden within function A First Book of C++: From Here To There, Third Edition

Function and Class Names (continued) A First Book of C++: From Here To There, Third Edition

Function and Class Names (continued) A First Book of C++: From Here To There, Third Edition

Function and Class Naming Conventions Identifiers: Names that convey an idea of the purpose of function or class Identifier composition rules: First character must be a letter or underscore Only letter, digit or underscore may follow Blank spaces allowed Identify component words with initial capitalization Cannot be C++ keyword Should be a mnemonic A First Book of C++: From Here To There, Third Edition

C++ Keywords A First Book of C++: From Here To There, Third Edition

C++ Identifiers Examples of valid identifiers: grosspay taxCalc addNums degToRad multByTwo salesTax netPay bessel A First Book of C++: From Here To There, Third Edition

C++ Identifiers (continued) Examples of invalid identifiers: 4ab3 (begins with a number) e*6 (contains a special character) while (is a keyword) A First Book of C++: From Here To There, Third Edition

The main Function Each C+ program must have one and only one function named main Called a driver function because it drives the other modules A First Book of C++: From Here To There, Third Edition

The main Function (continued) A First Book of C++: From Here To There, Third Edition

The main Function (continued) First line of function is called header line What type of data, if any, is returned from function The name of function What type of data, if any, is sent into function Data transmitted into function at run time are referred to as arguments of function A First Book of C++: From Here To There, Third Edition

main Function Composition A First Book of C++: From Here To There, Third Edition

The cout Object The cout object sends data to the standard output display device The display device is usually a video screen Name derived from Console OUTput and pronounced “see out” Data is passed to cout by the insertion symbol cout << “Hello there, World!”; A First Book of C++: From Here To There, Third Edition

C++ Sample Code using cout A First Book of C++: From Here To There, Third Edition

Newline Escape Sequence Instructs the display device to move to a new line A newline caused when the characters backslash \ and n are used together Backslash provides an “escape” from the normal interpretation of the character that follows Newline escape sequences can be placed anywhere within a message to cout A First Book of C++: From Here To There, Third Edition

Preprocessor Command Performs an action before the compiler translates source code to machine code An example is: #include <iostream> Causes the iostream file to be inserted wherever the #include command appears iostream is part of the C++ standard library Included in iostream are two important classes: istream: Declarations and methods for data input ostream: Declarations and methods for data output A First Book of C++: From Here To There, Third Edition

Namespaces Files accessed by compiler when looking for prewritten classes or functions Sample namespace statement: using namespace std; iostream contained in a namespace called std Compiler uses iostream’s cout object from std whenever cout is referenced A First Book of C++: From Here To There, Third Edition

More C++ Sample Code A First Book of C++: From Here To There, Third Edition

More C++ Sample Code (continued) A First Book of C++: From Here To There, Third Edition

Syntax The set of rules for formulating grammatically correct C++ language statements Compiler accepts statements with correct syntax without generating error message A program statement can syntactically correct and logically incorrect Compiler will accept statement Program will produce incorrect results A First Book of C++: From Here To There, Third Edition

Programming Style Every C++ program must contain one and only one main() function Statements included within braces { } C++ allows flexibility in format for the word main, the parentheses ( ), and braces { } More than one statement can be put on line One statement can be written across lines Use formatting for clarity and ease of program reading A First Book of C++: From Here To There, Third Edition

Standard C++ Program Form Function name starts in column 1 Name and parentheses on their own line Opening brace of function body on next line Aligned with first letter of function name Closing brace is last line of function Aligned with opening brace Standard form highlights the function as a unit A First Book of C++: From Here To There, Third Edition

Standard C++ Program Form (continued) Within function, indent statements 2-3 spaces Creates uniform look for similar statement groups Good programming practice Final program form should be consistent Proper format improves program readability and understandability A First Book of C++: From Here To There, Third Edition

Poor Program Format A First Book of C++: From Here To There, Third Edition

Proper Program Format A First Book of C++: From Here To There, Third Edition

Comments Explanatory remarks written within program Clarify purpose of the program Describe objective of a group of statements Explain function of a single line of code Computer ignores all comments Comments exist only for convenience of reader A well-constructed program should be readable and understandable Comments help explain unclear components A First Book of C++: From Here To There, Third Edition

Comment structure Line comment: Begins with 2 slashes(//) and continues to the end of the line Can be written on line by itself or at the end of line that contains program code // this is a line comment Block comment: Multiple line comment begins with the symbols /* and ends with the symbols */ /* This is a block comment that spans across three lines */ A First Book of C++: From Here To There, Third Edition

Common Programming Errors Omitting parentheses after main Omitting or incorrectly typing the opening brace { Opening brace signifies start of function body Omitting or incorrectly typing the closing brace } Closing brace signifies end of function Misspelling the name of an object or function Example: Typing cot instead of cout A First Book of C++: From Here To There, Third Edition

Common Programming Errors (continued) Forgetting to close a string sent to cout with a double-quote symbol Omitting the semicolon at the end of each statement Forgetting \n to indicate a new line A First Book of C++: From Here To There, Third Edition

Summary A C++ program consists of one or more modules One module must be the function main() main() is starting point of C++ program The simplest C++ program has the form: #include <iostream> using namespaces std; int main() { program statements; return 0; } A First Book of C++: From Here To There, Third Edition

Summary (continued) C++ statements are terminated by a semicolon Standard library contains many functions and classes Standard Library provided with C++ compiler Includes <iostream> for input and output cout object displays text or numeric results Stream of characters is sent to cout by: Enclosing characters in double quotes Using the insertion (“put to”) operator, << A First Book of C++: From Here To There, Third Edition