Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.

Slides:



Advertisements
Similar presentations
IT151: Introduction to Programming
Advertisements

Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
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.
INTRODUCTION T.Najah Al_Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System CS240.
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 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
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.
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.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
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.
Chapter 2: Java Fundamentals
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
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++
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
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
Chapter 2: Introduction to C++. Outline Basic “Hello World!!” Variables Data Types Illustration.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
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.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use simple Output statements Understand the different types and uses of comments.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
CSC 110 – Intro to Computing - Programming
1 Structure of Simple C++ Program Chapter 1 09/09/13.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
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.
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.
C++ First Steps.
Chapter 1.2 Introduction to C++ Programming
Programming what is C++
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 2 Introduction to C++ Programming
Chapter 1.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
Completing the Problem-Solving Process
Programming Fundamental
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Beginning C++ Programming
Intro to Java.
Chapter 2 – Getting Started
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Chapter 2: Introduction to C++.
Programs written in C and C++ can run on many different computers
Introduction to Programming - 1
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types

A Simple C++ Program Programming is great fun! // my first program in C++ #include #include void main ( ) { cout << “Programming is great fun!”; cout << “Programming is great fun!”; }

// my first program in C++ This is a comment line. All lines beginning with two slash signs (//) are considered comments do not have any effect on the behavior of the program programmer can use them to include short explanations or observations within the source code itself.

#include Lines beginning with a sign (#) are directives for the preprocessor. They are not regular code lines directive #include tells the preprocessor to include the iostream standard file This specific file (iostream.h) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program.

void main () The main function is the point where all C++ programs start their execution, independently of its location within the source code it is essential that all C++ programs have a main function The word main is followed in the code by a pair of parentheses (). That is because it is a function declaration Optionally, these parentheses may enclose a list of parameters within them Right after these parentheses we can find the body of the main function enclosed in braces{}

cout <<“programming is great fun” This line is a C++ statement A statement is a simple or compound expression that can actually produce some effect cout represents the standard output stream in C++ meaning of the entire statement is to insert a sequence of characters into the standard output stream (which usually is the screen). (;). This character is used to mark the end of the statement and in fact it must be included at the end of all expression statements in all C++ programs

Special Characters CharacterUse // Double slash # Pound sign Open / close brackets Open / close brackets Marks the beginning of a comment Marks the beginning of a preprocessor directive Encloses a filename when used with the #include directive

Special Characters CharacterUse { } Open / close braces Encloses a group of statements, such as the contents of a function ( ) Open / close parentheses Used in naming a function as in void main (void)

Special Characters CharacterUse “ ” Open / close quotation marks Encloses a string of characters, such as a message that is to printed on the screen. ; Semicolon Marks the end of a complete programming statement.

C++ Statement cnt’d For each C++ statement there are grammatical rules (called syntax rules); For each C++ statement there are grammatical rules (called syntax rules); To write any C++ statement correctly we MUST follow the statements syntax rules; To write any C++ statement correctly we MUST follow the statements syntax rules; A violation of the syntax rules of a statement causes the the compiler to report a syntax error. A violation of the syntax rules of a statement causes the the compiler to report a syntax error.

A sequence of C++ statements; A sequence of C++ statements; There are grammatical rules (syntax rules) that determine the structure of a correct C++ program; There are grammatical rules (syntax rules) that determine the structure of a correct C++ program; In general any C++ program consists of one or more mini programs called functions; In general any C++ program consists of one or more mini programs called functions; The simplest c++ program contains one function called main, that has the following structure: The simplest c++ program contains one function called main, that has the following structure: void main() {statementstatement…} Terms we Must Know C++ program

comments A comment is text that is written by the programmer to explain in English the logic of program statements; A comment is text that is written by the programmer to explain in English the logic of program statements; Comments are ignored by the compiler (not translated), since they are not C++ statements; Comments are ignored by the compiler (not translated), since they are not C++ statements; Comments can be written in two ways in a C++ program: Comments can be written in two ways in a C++ program: 1.2 forward slashes followed by text; these comments cannot span more than one line e.g. // this is a comment // this is a comment 2.Enclose text between /* and */ ; in this case the comment cab span multiple lines, e.g.: /* compute the area /* compute the area of the circle of the circle */ */

A Simple C++ Program Programming is _great fun!_ // A simple C++ program #include #include void main() { cout << “Programming is ”; cout << “great fun!”; cout << “great fun!”; }

A Simple C++ Program #include #include void main ( ) { cout <<“Following items were top ” <<“sellers” << endl; <<“sellers” << endl; cout <<“during the month of June:” << endl; cout <<“Computer games” << endl; cout <<“Coffee” << endl; cout <<“Aspirin” << endl; }

A Simple C++ Program Following items were top sellers _ during the month of June: _ Computer games _ Coffee _ Aspirin _

#include void main () { cout << “Following items were top ” << “sellers\n”; << “sellers\n”; cout << “during the month of June: \n”; cout << “during the month of June: \n”; cout << “Computer games\nCoffee”; cout << “Computer games\nCoffee”; cout << “\nAspirin\n”; cout << “\nAspirin\n”;}

A Simple C++ Program Following items were top sellers _ during the month of June: _ Computer games Coffee Aspirin _

Common Escape Sequences EscapeSequence Description \n Newline \t Horizontal tab \a Alarm Causes the cursor to the next line for subsequent printing Causes the cursor to skip over to the next tab stop Causes the computer to beep

Common Escape Sequences \r Return Causes the cursor to go to the beginning of the current line, not the next line. \b Backspace Causes the cursor to backup, or move left one position EscapeSequence Description

Common Escape Sequences \\ Backslash \’ Single quote \” Double quote Causes a backslash to be printed Causes a single quotation mark to be printed Causes a double quotation mark to be printed EscapeSequence Description