Chapter 2 – Getting Started

Slides:



Advertisements
Similar presentations
CSE202: Lecture 1The Ohio State University1 Introduction to C++
Advertisements

Objectives You should be able to describe: Introduction to Programming
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
 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.
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.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Chapter 2: Introduction to C++.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
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.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Syntax and Semantics, and the Program Development Process ROBERT REAVES.
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
Chapter 2 part #1 C++ Program Structure
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 2: Introduction to C++. Outline Basic “Hello World!!” Variables Data Types Illustration.
Operating System Using setw and setprecision functions Using setiosflags function Using cin function Programming 1 DCT
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 to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
CSE1222: Lecture 1The Ohio State University1. Computing Basics  Computers CPU, Memory & Input/Output (IO)  Program Sequence of instructions for the.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 17/4/1435 h Monday Lecture 3 The Parts of a C++ Program.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Lecture 4 Computer Programming // sample C++ program #include using namespace std; int main() { cout
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.
Basic concepts of C++ Presented by Prof. Satyajit De
C++ First Steps.
Programming what is C++
C++ Programming: Presentation 1
Chapter Topics The Basics of a C++ Program Data Types
Topic Pre-processor cout To output a message.
CMPT 201.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
ANNOUNCEMENT The missed lecture will be made up this Monday evening in the Tech PC classroom (MG51). A tentative time interval is 6:30-8:00. The exact.
CSC201: Computer Programming
Chapter 2: Introduction to C++
Completing the Problem-Solving Process
Chapter 2, Part I Introduction to C Programming
Computing Fundamentals
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
CHAPTER 3: Introduction to C Programming
Chapter 2 part #3 C++ Input / Output
Basic Elements of C++ Chapter 2.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Chapter 3: Input/Output
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Chapter 2 part #3 C++ Input / Output
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Introduction to Programming - 1
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Chapter 2 – Getting Started

Basic Program Structure #include <iostream> using namespace std; int main( ) { cout << “This is C++!”; } Header Location of header files Primary function Marks beginning of function body object insertion operator used to print to screen string – characters within double quotes semicolon: statement terminator C++ statement Marks end of function body Lesson 2.1

C++ Syntax Rules for writing statements Semicolon serve as statement terminator Case sensitivity Blank spaces Spacing Accepted modifications Lesson 2.1

Comments Notes in program describing what code does Perform no action in program Single line comment structure Begin with two slashes (no space between) // Line by itself or following statement Multiline comment structure Uses delimiters /* comments */ starts comment ends comment Lesson 2.2

Creating a Banner Set of comments at beginning of program name parameters used history author purpose date of program //*********************** // Name: Sally Student // Purpose: Assignment 2 // Date: 11/22/2003 // Reference: Chapter 2, #3 #include <iostream> . Lesson 2.2

Creating New Lines in Output Programmer must specify new line Line feeding \n in string constant cout << “\nwe can jump\n\ntwo lines.”; endl manipulator cout << endl<<“we can jump “; cout << endl<< endl <<“two lines.”; we can jump two lines. Lesson 2.3

Connecting Strings Can use backslash at end of line to indicate string constant to continue with next line cout << “This will \ continue on same line.” ; is equivalent to cout << “This will continue on same line.”; Lesson 2.3

Character Escape Sequences Other escape sequences exist for formatting Full listing in Table 2.1 Examples: \t horizontal tab \v vertical tab \% displays percent character \” displays double quote Lesson 2.3

Debugging Error in program called bug Process of looking for and correcting bugs Three types of errors Syntax Run-time Logic Lesson 2.4

Syntax Errors Mistakes by violating “grammar” rules Diagnosed by C++ compiler Must fix before compiler will translate code spelling cout coot << endl; int main ( ( ) mismatched parentheses Lesson 2.4

Run-Time Errors Violation of rules during execution of program Computer displays message during execution and execution is terminated Error message may help locating error Lesson 2.4

Logic Errors Computer does not recognize Difficult to find Execution is complete but output is incorrect Programmer checks for reasonable and correct output Lesson 2.4

Debugging Example #<include iostream> using namespace std; int main ( ); ( cout << ‘Hello world!’ cout << “Hello again”, endl; // Next line will output a name! ccut << “Sally Student”; /* Next line will output another name /* cout << John Senior; } # include <iostream> OK using namespace std; int main ( ) { cout << “Hello world!”; cout << “Hello again”<< endl; // Next line will output a name! cout << “Sally Student”; /* Next line will output another name */ cout << “John Senior” ; }

Summary Learned about: General program structure Rules of C++ syntax Creating comments and program banners Using escape sequences to format output Debugging programs Three types of errors: syntax, run-time, logic Chapter 2