Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout << “Welcome to C++! \n”; return.

Slides:



Advertisements
Similar presentations
IT151: Introduction to Programming
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
 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.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
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.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
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.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
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.
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++
Chapter 2 part #1 C++ Program Structure
Introduction to Computing Concepts Note Set 12. Writing a Program from Scratch public class SampleProgram1 { public static void main (String [] args)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
CSC 110 – Intro to Computing - Programming
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
 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.
1 17/4/1435 h Monday Lecture 3 The Parts of a C++ Program.
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.
Lecture 4 Computer Programming // 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 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter-01 A Sample C++ Program.
Chapter 1.2 Introduction to C++ Programming
Topic Pre-processor cout To output a message.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Chapter 1: Introduction to computers and C++ Programming
What Actions Do We Have Part 1
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CSC201: Computer Programming
Introduction to C Language
Chapter 2 - Introduction to C Programming
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Beginning C++ Programming
Chapter 2 - Introduction to C Programming
Intro to Java.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Programming Fundamentals Lecture #3 Overview of Computer Programming
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
Chapter 2 - Introduction to C Programming
Introduction to Programming - 1
Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Introduction to C++ Programming

A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout << “Welcome to C++! \n”; return 0; // indicate that program ended successfully }

Let’s look at your program: // - indicates that the remainder of each line is a comment! It is also called a single-line comment because the comment terminates at the end of the line. Note: Programmers insert comments to document programs and improve program readability. They also help other people read and understand your program.

If your comment contain more than one line you can use the following: begin with / * and end with */ Example: /* Your Name Computer Science Exercise 1 September 7, 2005 */

The line #include is called a preprocessor directive. What does it do? It tells the computer to include the contents of the input/output files in the program! It outputs to the screen and allows the user to input data into the computer using the keyboard.

The line int main ( ) is a part of every C++ program. Note: Every C++ contains one or more functions and main is one function that appears in every program.

The left and right braces - { } The left brace indicates the beginning of the body of the function main ( ). The right brace indicates the ending of the body of the function main ( ).

The line cout << “Welcome to C++! \n”; Tells the computer to print the line of text between the quotation marks. Another name for this line of code is called a statement. This statement consists of cout, << operator, the string “Welcome to C++!”, and a semi-colon.

The backslash \ is called an escape character. It indicates that a “special” character is to be output. The next character following the backslash is called an escape sequence as in the \n.

The line return 0; // indicate that program ended successfully is used to exit a function! When a return is used at the end of a function it means the value 0 indicates that the program has terminated successfully.

Escape SequenceDescription \nNewline. Position the screen cursor to the beginning of the next line. \tHorizontal tab. Move the screen cursor to the tab stop. \rCarriage return. \aAlert. Sound the system bell. \\Backslash. Used to print a backslash character. \*Double quote. Use to print a double quote character.

Another Program! //Program #2 #include int main ( ) { cout << “Welcome “; cout << “to C++! \n”; return 0; //indicate that program ended successfully }

Program 3! //Program #3 #include int main ( ) { cout << “Welcome\nto\n\nC++! \n “; return 0; //indicate that program ended successfully }

Do we have time for another Program? #include // This is a C++ program that will print a // message to the screen. main( ) { cout << “Programming in C++ is fun!”; }

Last one! When the following program is compiled and executed, what will the program cause to be displayed on the screen? #include main ( ) { cout << “// This is a C++ program. \n”; }

Homework! Read pages 5 to 21 and take notes!