Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.

Slides:



Advertisements
Similar presentations
C++ Introduction.
Advertisements

Copyright © 2003 Pearson Education, Inc. Slide 1.
Introduction to Programming in C++ John Galletly.
COSC 120 Computer Programming
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Chapter 1 Introduction to Computers and C++ Programming.
Three types of computer languages
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
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.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and 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.
Chapter Introduction to Computers and Programming 1.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Introduction to Computers and C++ Programming.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Chapter 2 Overview of C++ Lecture Notes Prepared By: Blaise W. Liffick, PhD Department of Computer Science Millersville University Millersville, PA
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using.
Instructor: Tina Tian. About me Office: RLC 203A Office Hours: Wednesday 1:30 - 4:30 PM or .
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright © 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Introduction to Computers and C++ Programming.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Chapter 02 (Part III) Introduction to C++ Programming.
Chapter 1 Introduction to Computer and C++ Programming.
Copyright © 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Mohamed Iqbal Pallipurath Slide 1. Mohamed Iqbal Pallipurath Slide 2 Basics Introduction to Computers and C++ Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
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.
Fundamental Programming: Fundamental Programming Introduction to C++
Chapter 2 Overview of C++. 2 Overview  2.1 Language Elements  2.2 Reserved Words & Identifiers  2.3 Data Types & Declarations  2.4 Input/Output 
1 Program Planning and Design Important stages before actual program is written.
Copyright © 2012 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
12/18/2015 CSI Chapter 1 1 Compiler + Linker = Ready to run code Compiler translates high-level language source code into an intermediate object.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Agenda Computer Languages How to Write a Simple C Program
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Chapter 1: Introduction to Computers and Programming.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Introduction to Computers and C++ Programming
Introduction to Computers and C++ Programming
Introduction to Computers and C++ Programming
CMPT 201.
Completing the Problem-Solving Process
Chapter 2 Assignment and Interactive Input
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
Chapter 2 – Getting Started
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Overview 2.1 Introduction to C Testing & Debugging 2.3 Variables and Assignments 2.3 Input and Output 2.4 Data Types and Expressions 2.5 Simple Flow of Control 2.6 Program Style

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 2.1 Introduction to C++

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Introduction to C++ Where did C++ come from? Derived from the C language C was derived from the B language B was derived from the BCPL language Why the ‘++’? ++ is an operator in C++ and results in a cute pun

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. C++ History C developed by Dennis Ritchie at AT&T Bell Labs in the 1970s. Used to maintain UNIX systems Many commercial applications written in c C++ developed by Bjarne Stroustrup at AT&T Bell Labs in the 1980s. Overcame several shortcomings of C Incorporated object oriented programming C remains a subset of C++

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. A Sample C++ Program A simple C++ program begins this way #include using namespace std; int main() { And ends this way return 0; } Display 1.8

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Explanation of code (1/5) Variable declaration line int number_of_pods, peas_per_pod, total_peas; Identifies names of three variables to name numbers int means that the variables represent integers

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Explanation of code (2/5) Program statement cout << “Press return after entering a number.\n”; cout (see-out) used for output to the monitor “<<“ inserts “Press…a number.\n” in the data bound for the monitor Think of cout as a name for the monitor “<<“ points to where the data is to end up ‘\n’ causes a new line to be started on the monitor

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Explanation of code (3/5) Program statement cin >> number_of_pods; cin (see-in) used for input from the keyboard “>>” extracts data from the keyboard Think of cin as a name for the keyboard “>>” points from the keyboard to a variable where the data is stored

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Explanation of code (4/5) Program statement total_peas = number_of_pods * peas_per_pod; Performs a computation ‘*’ is used for multiplication ‘=‘ causes total_peas to get a new value based on the calculation shown on the right of the equal sign

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Explanation of code (5/5) Program statement cout << number_of_pods; Sends the value of variable number_of_pods to the monitor

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Program Layout (1/3) Compiler accepts almost any pattern of line breaks and indentation Programmers format programs so they are easy to read Place opening brace ‘{‘ and closing brace ‘}’ on a line by themselves Indent statements Use only one statement per line

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Program Layout (2/3) Variables are declared before they are used Typically variables are declared at the beginning of the program Statements (not always lines) end with a semi-colon Include Directives #include Tells compiler where to find information about items used in the program iostream is a library containing definitions of cin and cout

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Program Layout (3/3) using namespace std; Tells the compiler to use names in iostream in a “standard” way To begin the main function of the program int main() { To end the main function return 0; } Main function ends with a return statement

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Running a C++ Program C++ source code is written with a text editor The compiler on your system converts source code to object code. The linker combines all the object code into an executable program.

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. C++11 C++11 (formerly known as C++0x) is the most recent version of the standard of the C++ programming language. Approved on August 12, 2011 by the International Organization for Standardization. C++11 language features are not supported by older compilers Check the documentation with your compiler to determine if special steps are needed to compile C++11 programs e.g. with g++, use extra flags of –std=c++11

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Run a Program Obtain code in Display 1.10 Compile the code Fix any errors the compiler indicates and re-compile the code Run the program Now you know how to run a program on your system Display 1.10

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Section 1.3 Conclusion Can you… Describe the output of this line? cout << “C++ is easy to understand.”; Explain what this line does? cin >> peas_per_pod; Explain this? #include

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 2.2 Testing and Debugging

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Testing and Debugging Bug A mistake in a program Debugging Eliminating mistakes in programs Term used when a moth caused a failed relay on the Harvard Mark 1 computer. Grace Hopper and other programmers taped the moth in logbook stating: “First actual case of a bug being found.”

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Program Errors Syntax errors Violation of the grammar rules of the language Discovered by the compiler Error messages may not always show correct location of errors Run-time errors Error conditions detected by the computer at run-time Logic errors Errors in the program’s algorithm Most difficult to diagnose Computer does not recognize an error

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Conclusion Can you… Describe the three kinds of program errors? Tell what kind of errors the compiler catches? What kind of error is produced if you forget a punctuation symbol such as a semi-colon? Tell what type of error is produced when a program runs but produces incorrect results?

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.1 Back Next

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.2 Back Next

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.3 Back Next

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.4 Back Next

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.5 Back Next

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.6 Back Next

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.7 Back Next

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.8 Next Back

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.9 Back Next

Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Display 1.10 Next Back