Chapter 3 Getting Started with C++

Slides:



Advertisements
Similar presentations
Pemrograman C Risanuri Hidayat. Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is.
Advertisements

Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
 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.
Chapter 2: Introduction to C++.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
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.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Comments are for people Header comments supply basic information about the artifact.
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.
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.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
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.
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++
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
C++ How to Program, Late Objects Version, 7/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Basic Program Construction
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
Chapter 2 part #1 C++ Program Structure
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Chapter 2: Introduction to C++. Outline Basic “Hello World!!” Variables Data Types Illustration.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Functions Skill Area 314 Part B. Lecture Overview Functions Function Prototypes Function Definitions Local Variables Global Variables Default Parameters.
 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 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
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.
Chapter 2 of C++ How to Program, 10/e © by Pearson Education, Inc. All Rights Reserved.
Bill Tucker Austin Community College COSC 1315
C++ Lesson 1.
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Basic Elements of C++
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Topic Pre-processor cout To output a message.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
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.
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
2.1 Parts of a C++ Program.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C++ Programming
Chapter 2: Introduction to C++.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to Programming - 1
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Chapter 3 Getting Started with C++ C++: An Active Learning Approach Todd Breedlove & Randal Albert Copyright © 2008 Jones and Bartlett Publishers All rights reserved.

3.1 C++ Basics C++ is case sensitive Average is different than average and AVERAGE All C++ reserved words are in lowercase Reserved words - identifiers that have special meaning and are a part of the language

3.1 C++ Basics Most statements terminated by a semicolon except: Function headers Preprocessor directives Control statements Preprocessor directives - commands executed by the preprocessor Preprocessor directives require the first character on the line to be a number sign (#)

3.2 Whitespace Whitespace - empty or non-visible character (i.e., space or tab), including blank lines Aids readability Readability allows a program to be more easily modified and maintained Most whitespace is ignored by the compiler

3.3 Comments Comments - lines of C++ code that are ignored by the compiler Used to document the source code for you or for other programmers Aid in the readability and maintainability of source code

3.3 Comments Two forms A block comment can span multiple lines // inline comment /* block comment */ A block comment can span multiple lines

3.4 The main Function Function - a group of related statements that perform a specific task or job The main function (commonly referred to as “main”) is the starting point of a C/C++ program Every C/C++ program will have exactly one main

3.4 The main Function Function header - first line in a function definition Function definition - combination of the function header and a function body - the statements enclosed in curly braces int main() // Function header, no semicolon {// Start of function body return 0; // C++ statement, requires semicolon }// End of function body

3.4 The main Function Curly braces and parentheses always come in pairs Curly braces: Group statements together Define the beginning and ending of the function body

3.5 The #include Preprocessor Directive Predefined routine - not part of the core language but an extension to the language Part of the C++ standard Accessed through header files Preprocessor directive #include allows access to predefined routines in external or separate files - called header files

3.5 The #include Preprocessor Directive Two forms of the #include: #include <header_file> #include “header_file” First example - looks in the “include” directory specified by the compiler Used with predefined header files

3.5 The #include Preprocessor Directive Two forms of the #include: #include <header_file> #include “header_file” Example 2 - looks for the header file in a user specified location Used with user defined header files

3.5 The #include Preprocessor Directive The <iostream> header file contains predefined input and output routines #include <iostream> // Allows access to I/O routines int main() { // Outputs "Hello World!" to the screen std::cout << "Hello World!"; return 0; }

3.5.1 Namespaces namespace - allows grouping or structuring related entities inside one category cout is located in “std” namespace

3.5.1 Namespaces Ways to access routines in namespaces: Explicitly std::cout << “Hello World”; Using directive using namespace std; Using declaration using std::cout;

3.5.1 Namespaces Explicit requires use of the namespace prefix every time a routine is used Using directive allows access to all routines within a namespace Using declaration allows access to only those routines specified

3.7 C – The Differences C programmers are limited to the block style comment (/* */) with older compilers Many new C compilers allow the use of the inline comment (//) which has become part of the latest C standard

3.7 C – The Differences C uses different header files and routines for I/O Namespaces are not required to access predefined functions #include <stdio.h> // Allows access to I/O routines int main( void ) { // Outputs "Hello World!" to the screen printf( "Hello World!" ); return 0; }