Chapter-01 A Sample C++ Program.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C 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.
Dale/Weems/Headington
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Chapter 9: Arrays and Strings
Chapter 2: Introduction to C++.
Chapter 8 Arrays and Strings
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
Programming Languages
C-Language Keywords(C99)
Constants in C A Presentation On Department of Computer & Information Technology, M.S.P.V.L. Polytechnic College, Pavoorchatram.
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.
Chapter 8 Arrays and Strings
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
1 C++ Syntax and Semantics, and the Program Development Process.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
Week 1 Algorithmization and Programming Languages.
C++ Programming: Basic Elements of C++.
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 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Chapter 2 part #1 C++ Program Structure
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
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
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 of C++ How to Program, 10/e © by Pearson Education, Inc. All Rights Reserved.
The Second C++ Program Variables, Types, I/O Animation!
Chapter 1.2 Introduction to C++ Programming
Programming what is C++
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
Chapter 1.2 Introduction to C++ 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
Chapter 2 Topics Programs Composed of Several Functions
BASIC ELEMENTS OF A COMPUTER PROGRAM
Beginning C++ Programming
Introduction to C++.
Chapter 2 - Introduction to C Programming
C++ Simple Data Types Simple types Integral Floating
Chapter 2 – Getting Started
Chapter 2 - Introduction to C Programming
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
2.1 Parts of a C++ Program.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Programs written in C and C++ can run on many different computers
Chapter 2 - Introduction to C Programming
Introduction to Programming - 1
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Chapter-01 A Sample C++ Program

// Fig. 1.2: fig1_02.cpp // A first program in C++ #include <iostream.h> int main() { cout << "Welcome to C++!\n"; return 0; // indicate that program ended successfully }

C++ Comments Multiline comments: /* -------------------------------------- can not be nested. -------------------------------------- */ Single line comment: // can be nested in multiline comments. // --------------------------------------- Conditional Compile: #if 0 can be nested. --------------------------------------- #endif

Multifile C++ Programs C++ programs often consist of several different files with extensions such as .h and .cpp related typedef statements, const values, enum type declarations, and similar items are often placed in user-written header files by using the #include preprocessor directive the contents of these header files are inserted into any program file that uses them Bazlur Rasheed

Inserting Header Files #include <iostream.h> #include “school.h” int main ( ) { enum SchoolType { PRE_SCHOOL, . ELEM_SCHOOL, . MIDDLE_SCHOOL, . HIGH_SCHOOL, COLLEGE } ; } include contents of I/O stream header file needed to use the objects cout and cin Bazlur Rasheed

A C++ program is a collection of one or more functions there must be a function called main( ) execution always begins with the first statement in function main( ) any other functions in your program are subprograms and are not executed until they are called

Program With Several Functions main function square function cube function

Shortest C++ Program int main ( ) { return 0; } type of returned value name of function

What is in a heading? int main ( ) type of returned value name of function says no parameters int main ( ) Bazlur Rasheed

Every C++ function has 2 parts int main ( ) heading { body block return 0; } Bazlur Rasheed

Block (Compound Statement) a block is a sequence of zero or more statements enclosed by a pair of curly braces { } SYNTAX { Statement (optional) ; . }

cout << "Welcome to C++!\n"; The entire line is a C++ statement. Output and input in C++ is accomplished with streams of characters. When this statement is executed: the stream of characters Welcome to C++! goes to the standard output stream object cout, which is the screen. << is the stream insertion operator. \n escape sequence means newline

Some Escape Sequences \n Newline (Line feed in ASCII) \t Horizontal tab \b Backspace \a Alert (bell or beep) \\ Backslash \’ Single quote (apostrophe) \” Double quote (quotation mark) \0 Null character (all zero bits) \ddd Octal equivalent (3 octal digits) \xddd Hexadecimal equivalent (1 or more hex digits for integer value of character) Bazlur Rasheed

Output of program Welcome to C++!

return 0; When this statement is executed: the value 0 is returned to the operating system, indicating that the program has terminated successfully.