CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.

Slides:



Advertisements
Similar presentations
Chapter 2: Basic Elements of C++
Advertisements

An Introduction to Programming with C++ Fifth Edition Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
Lecture 2 Introduction to C Programming
Introduction Kingdom of Saudi Arabia Shaqra University
COSC 120 Computer Programming
An Introduction to Programming with C++ Fifth Edition
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Introducing Java.
A First Program Using C#
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
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.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
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.
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.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
© 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.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Syntax and Semantics, and the Program Development Process ROBERT REAVES.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Chapter 2: Introduction to C++. Language Elements Keywords Programmer-defined symbols (identifiers) Operators Punctuation Syntax Lines and Statements.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Structure of Simple C++ Program Chapter 1 09/09/13.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
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.
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Chapter 2: Basic Elements of C++
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
Completing the Problem-Solving Process
Chapter 2 - Introduction to C Programming
The Selection Structure
Chapter 2 - Introduction to C Programming
Chapter 2: Basic Elements of C++
Chapter 1: Introduction to Computers and Programming
Chapter 2 – Getting Started
Introduction to C++ Programming
Programming Funamental slides
Chapter 3: Input/Output
An Introduction to Programming with C++ Fifth Edition
Introduction to Programming - 1
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition

Objectives An Introduction to Programming with C++, Fifth Edition 2 Code an algorithm into a program Desk-check a program Evaluate and modify a program Understand the components of a C++ program Create a C++ program

Objectives (continued) An Introduction to Programming with C++, Fifth Edition 3 Save, build, and execute a C++ program Locate and fix an error in a C++ program Print a C++ program Make a backup copy of a solution

Concept Lesson An Introduction to Programming with C++, Fifth Edition 4 More on the Problem-Solving Process Coding the Algorithm into a Program Desk-Checking the Program Evaluating and Modifying the Program Creating a C++ Program

More on the Problem-Solving Process An Introduction to Programming with C++, Fifth Edition 5

Coding the Algorithm into a Program An Introduction to Programming with C++, Fifth Edition 6

7 rules to naming a variable An Introduction to Programming with C++, Fifth Edition 7 Must begin with a letter Can only contain letters, numbers and underscore No punctuation No special symbols No more than 32 characters Cannot be a keyword Are case sensitive

Assigning Names, Data Types, and Initial Values to the IPO Items An Introduction to Programming with C++, Fifth Edition 8 To code algorithm, first assign a name to each input, processing, and output item in IPO chart  Names can contain only letters, numbers, and _  Cannot contain punctuation characters or spaces  Examples:  raise  newPay  Each input/processing/output item must have a data type  You may initialize each item usually in lowercase letters use camel case if name contains multiple words

Assigning Names, Data Types, and Initial Values to the IPO Items (continued) An Introduction to Programming with C++, Fifth Edition 9 double is a keyword this is a statement all C++ statements must end with a semicolon

Translating the Algorithm Steps into C++ Code An Introduction to Programming with C++, Fifth Edition 10 cout : standard output stream cin : standard input stream << : insertion operator >> : extraction operator stream: sequence of characters, to perform standard I/O operations a stream manipulator

Quick Quiz An Introduction to Programming with C++, Fifth Edition 11 1.How many variables are there? 2.What type of variables are they? 3.What is the standard output stream? 4.What is the standard input stream? 5.Give me an example of a variable not used in this program.

Desk-Checking the Program An Introduction to Programming with C++, Fifth Edition 12

Desk-Checking the Program (continued) An Introduction to Programming with C++, Fifth Edition 13

An Introduction to Programming with C++, Fifth Edition 14 Desk-Checking the Program (continued)

Evaluating and Modifying the Program An Introduction to Programming with C++, Fifth Edition 15 Testing is running the program, with sample data  Results should agree with desk-check ones Debugging is locating/removing errors in program  Program errors are called bugs A syntax error occurs if an instruction violates the programming language’s syntax (set of rules)  E.g., cout < "Hello"; A logic error occurs if an instruction does not give the expected results  E.g., average = number1 + number2 / 2;

Creating a C++ Program An Introduction to Programming with C++, Fifth Edition 16 source file: Ch3Lab2.cpp object file: Ch3Lab2.obj executable file: Ch3Lab2.exe created using an IDE or a general-purpose editor

An Introduction to Programming with C++, Fifth Edition 17 Creating a C++ Program (continued)

Summary An Introduction to Programming with C++, Fifth Edition 18 Fourth step in the problem-solving process is to code the algorithm into a program In C++, you perform standard I/O operations using streams (sequences of characters)  cout and cin  Insertion operator (<<) sends data to output stream  Extraction operator (>>) gets data from input stream After coding the algorithm, you desk-check program Final step in the problem-solving process is to evaluate and modify (if necessary) the program

Summary (continued) An Introduction to Programming with C++, Fifth Edition 19 Some programs have errors, called bugs  Syntax error occurs when an instruction violates one of the rules of the programming language’s syntax  Logic error occurs when you enter an instruction that does not give you the expected results  You debug to locate and remove errors To create and execute a C++ program, you need to have a text editor and a C++ compiler  Compiler translates source code into object code  Linker produces executable file

Summary (continued) An Introduction to Programming with C++, Fifth Edition 20 Comments are internal documentation of programs C++ programs typically include at least one directive using statements tell compiler where it can find the definition of certain keywords A function is a block of code that performs a task  main() is where the execution of program begins The first line in a function is called the header  After the header comes the body, enclosed in braces

Application Lesson: Completing the Problem- Solving Process An Introduction to Programming with C++, Fifth Edition 21 Lab 3.1: Stop and Analyze Lab 3.2:  Use Microsoft Visual C Express Edition Lab 3.3:  Modify the program created in Lab 3.2 so that it doesn’t use a processing item Lab 3.4: Desk-Check Lab Lab 3.5: Debugging Lab

An Introduction to Programming with C++, Fifth Edition 22 Application Lesson: Completing the Problem-Solving Process (continued)