SlideShare a Scribd company logo
1 of 49
A First Book of C++ 4th Edition 1
Du`a for StudyDu`a for Study
A First Book of C++A First Book of C++
Chapter 1Chapter 1
Getting StartedGetting Started
∗ In this chapter, you will learn about:
∗ Introduction to Programming
∗ Function and Class Names
∗ The cout Object
∗ Programming Style
∗ Common Programming Errors
A First Book of C++ 4th Edition 3
ObjectivesObjectives
∗ Computer program (software)
∗ Data and instructions used to operate a computer
∗ Programming
∗ Writing computer program in a language that the
computer can respond to and that other programmers can
understand
∗ Programming language
∗ Set of instructions, data, and rules used to construct a
program
A First Book of C++ 4th Edition 4
Introduction to ProgrammingIntroduction to Programming
∗ Categories of Programming Language
∗ Level
∗ High-level languages (e.g., C, C++, C#, Visual Basic, Java,
Python)
∗ Low-level languages (e.g., Assembly language)
A First Book of C++ 4th Edition 5
Introduction to ProgrammingIntroduction to Programming
(cont’d.)(cont’d.)
Assembly vs Machine LanguageAssembly vs Machine Language
A First Book of C++ 4th Edition 6
• Early computers were programmed in assembly language
• To calculate wages = rates * hours in assembly language:
1) Load 2) Multiply 3) Store
010001
010011
010010
∗ Categories of Programming Language (cont)
∗ Orientation
∗ Procedural language
∗ Instructions are used to create self-contained units
(procedures)
∗ Procedures accept data as input and transform data to
produce a specific result as an output
∗ Initially, high-level programming languages were
predominately procedural
A First Book of C++ 4th Edition 7
Introduction to ProgrammingIntroduction to Programming
(cont’d.)(cont’d.)
Introduction to ProgrammingIntroduction to Programming
(cont’d.)(cont’d.)
A First Book of C++ 4th Edition 8
a + b = ?
a = 2 , b =3 5
∗ Object-oriented languages
∗ Program must define objects that it is manipulating
∗ Such definitions include:
∗ The general characteristics of objects (attribute/state)
∗ Specific operations to manipulate objects (behavior/method)
∗ C++ is an object-oriented language
∗ Has procedures and objects
∗ Supports code reuse
A First Book of C++ 4th Edition 9
Introduction to ProgrammingIntroduction to Programming
(cont’d.)(cont’d.)
∗ C++ began as extension to C
∗ C is a procedural language developed in the 1970s at
AT&T Bell Laboratories
∗ In early 1980s, Bjarne Stroustrup (“Bee-yarn-eh Strow-
strup”, also at AT&T) used his background in
simulation languages to develop C++
∗ Object-orientation and other procedural
improvements were combined with existing C
language features to form C++
A First Book of C++ 4th Edition 10
Introduction to ProgrammingIntroduction to Programming
(cont’d.)(cont’d.)
∗ Before writing a program, a programmer must clearly
understand:
∗ What data is to be used
∗ The expected result
∗ The procedure needed to produce this result
∗ The procedure is referred to as an algorithm
∗ Step-by-step sequence of instructions describing how to
perform a computation
A First Book of C++ 4th Edition 11
Algorithms and ProceduresAlgorithms and Procedures
∗ Computers think algorithmically (step by step, use rules)
NOT heuristically (based on experience, no rules)!
∗ Assume that a program must calculate the sum of all
whole numbers from 1 through 100 (1+2+3+4+5+…+100)
∗ A computer:
∗ Cannot respond to heuristic command: “Add the numbers
from 1 - 100”
∗ Is an algorithm-responding machine and not a heuristic-
responding machine
∗ Several methods or algorithms can be used to find the
required sum
A First Book of C++ 4th Edition 12
Algorithms and Procedures (cont’d.)
A First Book of C++ 4th Edition 13
Algorithms and Procedures (cont’d.)
A First Book of C++ 4th Edition 14
Calculate the result for 3 x 2
A First Book of C++ 4th Edition 15
Flow Chart
A First Book of C++ 4th Edition 16
∗ C++ source program
∗ Set of instructions written in C++ language
∗ Machine language
∗ Internal computer language
∗ Consists of a series of 1s and 0s (binaries)
∗ Source program cannot be executed until it is
translated into machine language
∗ Interpreted language translates one statement at a time
∗ Compiled language translates all statements together
A First Book of C++ 4th Edition 17
Program Translation
Program Translation (cont'd.)
A First Book of C++ 4th Edition 18
100100 010010int x = 8
Processing a Program
A First Book of C++ 4th Edition 19
∗ Modular programs
∗ Segments arranged in logical order to form an integrated unit
∗ Module
∗ Segments (small parts) of modular program
∗ Function: Name of a C++ procedure
∗ Composed of sequence of C++ instructions
∗ Function interface is its inputs and results (output)
∗ Method of converting input to results is encapsulated and
hidden within function
A First Book of C++ 4th Edition 20
Function and Class Names
A First Book of C++ 4th Edition 21
Function and Class Names (cont'd.)
Function and Class Names (cont'd.)
A First Book of C++ 4th Edition 22
Accepts 2
numbers as
input,
produce a
result
3 5
15
Input
∗ Identifiers (or variables)
∗ Names that convey an idea of the purpose of function or class
∗ Identifier composition rules
∗ First character must be a letter or underscore (A1, _1)
∗ Only letter, digit, or underscore may follow (AA, A2, A_)
∗ Blank spaces aren’t allowed (A B)
∗ Identify component words with initial capitalization (numPos)
∗ Cannot be C++ keyword (e.g., auto, break, int, switch …)
∗ Should be a mnemonic (short, easy to remember, meaningful)
A First Book of C++ 4th Edition 23
Function and Class Names (cont'd.)
Function and Class Names (cont'd.)
A First Book of C++ 4th Edition 24
∗ Examples of valid identifiers:
grosspay $cost (valid in C++)
addNums degToRad
multByTwo salesTax
netPay bessel
_name my$
**Note: When we combine two or more words to form an
identifier (or variables), it is a good practice to capitalize each of
the new word.
A First Book of C++ 4th Edition 25
Function and Class Names (cont'd.)
∗ Examples of invalid identifiers:
4ab3(begins with a number)
e*6 (contains a special character)
while (is a keyword)
#amount (begins with special character)
A First Book of C++ 4th Edition 26
Function and Class Names (cont'd.)
∗ Each C++ program must have one and only one key
function named main()
∗ Called a driver function because it drives the other
modules
A First Book of C++ 4th Edition 27
The main() Function
The main() Function (cont'd.)
A First Book of C++ 4th Edition 28
∗ First line of function is called header line
∗ What type of data, if any, is returned from function
∗ The name of function
∗ What type of data, if any, is sent into function
∗ Data transmitted into function at runtime are referred
to as arguments of function
arguments (input to function)
Example:
header line void sum(int a, int b) {
}A First Book of C++ 4th Edition 29
The main() Function (cont'd.)
Starting to Program with Dev C++
A First Book of C++ 4th Edition 30
Starting to Program with Dev C++
A First Book of C++ 4th Edition 31
The main() Function (cont'd.)
A First Book of C++ 4th Edition 32
beginning of program
end of program
∗ The cout object sends data to the standard output
display device
∗ The display device is usually a video screen
∗ Name derived from console output and pronounced
“see out”
∗ Data is passed to cout by the insertion symbol
∗ cout << “Hello there, World!”;
A First Book of C++ 4th Edition 33
The cout Object
The cout Object (cont’d.)
A First Book of C++ 4th Edition 34
//Pre-processor command <header file>
//File for pre-written classes/classes (a containet //that
provides contexts/scope for variables)
system(“pause”);
The cout Object (cont’d.)
A First Book of C++ 4th Edition 35
//Pre-processor command <header file>
system(“pause”);
std::cout << “Hello there world!”;
name for namespace
∗ Preprocessor command
∗ Performs an action before the compiler translates source
code to machine code
∗ Example: #include <iostream>
∗ Causes the iostream file to be inserted wherever the
#include command appears
∗ iostream is part of the C++ standard library
∗ Included in iostream are two important classes:
∗ istream: Declarations and methods for data input
∗ ostream: Declarations and methods for data output
A First Book of C++ 4th Edition 36
The cout Object (cont’d.)
∗ Namespace
∗ File accessed by compiler when looking for prewritten
classes or functions
∗ Sample namespace statement:
∗ using namespace std;
∗ iostream contained in a namespace called std
∗ Compiler uses iostream’s cout object from std
whenever cout is referenced
A First Book of C++ 4th Edition 37
The cout Object (cont’d.)
The cout Object (cont’d.)
A First Book of C++ 4th Edition 38
∗ Newline escape sequence (“n”)
∗ Instructs the display device to move to a new line
∗ Caused when the characters backslash  and n are used
together
∗ Backslash provides an “escape” from the normal
interpretation of the character that follows
∗ Newline escape sequences can be placed anywhere
within a message to cout
A First Book of C++ 4th Edition 39
The cout Object (cont’d.)
The cout Object (cont’d.)
A First Book of C++ 4th Edition 40
∗ Every C++ program must contain one and only one
main() function
∗ Statements included within braces { }
∗ C++ allows flexibility in format for the word main, the
parentheses ( ), and braces { }
∗ More than one statement can be put on line
∗ One statement can be written across lines
∗ Use formatting for clarity and ease of program
reading
A First Book of C++ 4th Edition 41
Programming StyleProgramming Style
∗ Function name starts in column 1
∗ Name and parentheses on their own line
∗ Opening brace of function body on next line
∗ Aligned with first letter of function name
∗ Closing brace is last line of function
∗ Aligned with opening brace
∗ Standard form highlights the function as a unit
A First Book of C++ 4th Edition 42
Programming Style (cont’d.)Programming Style (cont’d.)
∗ Within function, indent statements 2-3 spaces
∗ Creates uniform look for similar statement groups
∗ Good programming practice
∗ Final program form should be consistent
∗ Proper format improves program readability and
understandability
A First Book of C++ 4th Edition 43
Programming Style (cont’d.)Programming Style (cont’d.)
∗ Explanatory remarks written within program (//)
∗ Clarify purpose of the program
∗ Describe objective of a group of statements
∗ Explain function of a single line of code
∗ Computer ignores all comments
∗ Comments exist only for convenience of reader
∗ A well-constructed program should be readable and
understandable
∗ Comments help explain unclear components
A First Book of C++ 4th Edition 44
CommentsComments
∗ Line comment
∗ Begins with two slashes(//) and continues to the end of the line
∗ Can be written on line by itself or at the end of line that contains
program code
// this is a line comment
∗ Block comment
∗ Multiple-line comment begins with the symbols /* and ends with
the symbols */
/* This is a block comment that
spans
three lines */
A First Book of C++ 4th Edition 45
Comments (cont’d.)Comments (cont’d.)
∗ Omitting parentheses after main()
∗ Omitting or incorrectly typing the opening brace {
∗ Opening brace signifies start of function body
∗ Omitting or incorrectly typing the closing brace }
∗ Closing brace signifies end of function
∗ Omitting the semicolon at the end of each statement ;
∗ Adding a semicolon after the #include
<iostream> preprocessor command
#include <iostream> ; X (wrong, no need)
A First Book of C++ 4th Edition 46
Common Programming ErrorsCommon Programming Errors
∗ Misspelling the name of an object or function
∗ Example: Typing “cot” instead of “cout”
∗ Forgetting to close a string sent to cout with a
double-quote symbol
cout << “Hello world
∗ Forgetting n to indicate a new line
A First Book of C++ 4th Edition 47
Common Programming ErrorsCommon Programming Errors
(cont'd.)(cont'd.)
∗ A C++ program consists of one or more modules
∗ One module must be the function main()
∗ main() is starting point of C++ program
∗ The simplest C++ program has the form:
#include <iostream>
using namespaces std;
int main()
{
program statements;
return 0;
}
A First Book of C++ 4th Edition 48
SummarySummary
∗ C++ statements are terminated by a semicolon ;
∗ Standard library contains many functions and classes
∗ Standard Library provided with C++ compiler
∗ Includes <iostream> for input and output
∗ cout object displays text or numeric results
∗ Stream of characters is sent to cout by:
∗ Enclosing characters in double quotes “ ”
∗ Using the insertion (“put to”) operator, <<
A First Book of C++ 4th Edition 49
Summary (cont'd.)Summary (cont'd.)

More Related Content

What's hot

C and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharC and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharDreamtech Labs
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREjatin batra
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programminggajendra singh
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xiiSyed Zaid Irshad
 
C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?Mateusz Pusz
 
Advanced C Language for Engineering
Advanced C Language for EngineeringAdvanced C Language for Engineering
Advanced C Language for EngineeringVincenzo De Florio
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Lecture#5 c lang new
Lecture#5 c lang newLecture#5 c lang new
Lecture#5 c lang newZeeshan Ahmad
 
introduction of c langauge(I unit)
introduction of c langauge(I unit)introduction of c langauge(I unit)
introduction of c langauge(I unit)Prashant Sharma
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming languagesanjay joshi
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0xppd1961
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of Ceducationfront
 

What's hot (20)

C vs c++
C vs c++C vs c++
C vs c++
 
C and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharC and C++ Industrial Training Jalandhar
C and C++ Industrial Training Jalandhar
 
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTREC and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
 
C programming language
C programming languageC programming language
C programming language
 
C vs c++
C vs c++C vs c++
C vs c++
 
C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?C++ Concepts and Ranges - How to use them?
C++ Concepts and Ranges - How to use them?
 
Advanced C Language for Engineering
Advanced C Language for EngineeringAdvanced C Language for Engineering
Advanced C Language for Engineering
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
C language
C languageC language
C language
 
Lecture#5 c lang new
Lecture#5 c lang newLecture#5 c lang new
Lecture#5 c lang new
 
C++ ch1
C++ ch1C++ ch1
C++ ch1
 
Ch9a
Ch9aCh9a
Ch9a
 
introduction of c langauge(I unit)
introduction of c langauge(I unit)introduction of c langauge(I unit)
introduction of c langauge(I unit)
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming language
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 
Ch9b
Ch9bCh9b
Ch9b
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
 

Viewers also liked

Mule cloud connectors versus el resto del mundo
Mule cloud connectors versus el resto del mundoMule cloud connectors versus el resto del mundo
Mule cloud connectors versus el resto del mundoManuel Antonio
 
SamXinRomeShow
SamXinRomeShowSamXinRomeShow
SamXinRomeShowSam Lewis
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009IIUM
 
Redo midterm
Redo midtermRedo midterm
Redo midtermIIUM
 
Digital That Delivers: Strategies You Should Implement Now
Digital That Delivers: Strategies You Should Implement NowDigital That Delivers: Strategies You Should Implement Now
Digital That Delivers: Strategies You Should Implement NowErin Overstreet
 
Psychology cs
Psychology   csPsychology   cs
Psychology csIIUM
 
Principle and Practice of Management MGT Ippt chap014
Principle and Practice of Management MGT Ippt chap014Principle and Practice of Management MGT Ippt chap014
Principle and Practice of Management MGT Ippt chap014IIUM
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoIIUM
 
VOLUME, 6th std., Learning material
VOLUME, 6th std., Learning materialVOLUME, 6th std., Learning material
VOLUME, 6th std., Learning materialShahaziya Ummer
 

Viewers also liked (10)

Mule cloud connectors versus el resto del mundo
Mule cloud connectors versus el resto del mundoMule cloud connectors versus el resto del mundo
Mule cloud connectors versus el resto del mundo
 
SamXinRomeShow
SamXinRomeShowSamXinRomeShow
SamXinRomeShow
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
 
Oop l3n
Oop l3nOop l3n
Oop l3n
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Digital That Delivers: Strategies You Should Implement Now
Digital That Delivers: Strategies You Should Implement NowDigital That Delivers: Strategies You Should Implement Now
Digital That Delivers: Strategies You Should Implement Now
 
Psychology cs
Psychology   csPsychology   cs
Psychology cs
 
Principle and Practice of Management MGT Ippt chap014
Principle and Practice of Management MGT Ippt chap014Principle and Practice of Management MGT Ippt chap014
Principle and Practice of Management MGT Ippt chap014
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
 
VOLUME, 6th std., Learning material
VOLUME, 6th std., Learning materialVOLUME, 6th std., Learning material
VOLUME, 6th std., Learning material
 

Similar to Csc1100 lecture01 ch01-pt1

Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14IIUM
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14IIUM
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming LanguageProf Ansari
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++oggyrao
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1SURBHI SAROHA
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itPushkarNiroula1
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introductionraghukatagall2
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Rohit Singh
 
Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1IIUM
 

Similar to Csc1100 lecture01 ch01-pt1 (20)

Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14
 
The C++ Programming Language
The C++ Programming LanguageThe C++ Programming Language
The C++ Programming Language
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Lab 1.pptx
Lab 1.pptxLab 1.pptx
Lab 1.pptx
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 
C
CC
C
 
C
CC
C
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 

More from IIUM

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhostIIUM
 
Chapter 2
Chapter 2Chapter 2
Chapter 2IIUM
 
Chapter 1
Chapter 1Chapter 1
Chapter 1IIUM
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimediaIIUM
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblockIIUM
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice keyIIUM
 
Group p1
Group p1Group p1
Group p1IIUM
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lformsIIUM
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answerIIUM
 
Heaps
HeapsHeaps
HeapsIIUM
 
Report format
Report formatReport format
Report formatIIUM
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelinesIIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam PaperIIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam PaperIIUM
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516IIUM
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotationsIIUM
 
Week12 graph
Week12   graph Week12   graph
Week12 graph IIUM
 
Vpn
VpnVpn
VpnIIUM
 
Principle and Practice of Management MGT Ippt chap001
Principle and Practice of Management MGT Ippt chap001Principle and Practice of Management MGT Ippt chap001
Principle and Practice of Management MGT Ippt chap001IIUM
 
Principle and Practice of Management MGT Ippt chap002
Principle and Practice of Management MGT Ippt chap002Principle and Practice of Management MGT Ippt chap002
Principle and Practice of Management MGT Ippt chap002IIUM
 

More from IIUM (20)

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
 
Group p1
Group p1Group p1
Group p1
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
 
Heaps
HeapsHeaps
Heaps
 
Report format
Report formatReport format
Report format
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
 
Vpn
VpnVpn
Vpn
 
Principle and Practice of Management MGT Ippt chap001
Principle and Practice of Management MGT Ippt chap001Principle and Practice of Management MGT Ippt chap001
Principle and Practice of Management MGT Ippt chap001
 
Principle and Practice of Management MGT Ippt chap002
Principle and Practice of Management MGT Ippt chap002Principle and Practice of Management MGT Ippt chap002
Principle and Practice of Management MGT Ippt chap002
 

Recently uploaded

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 

Recently uploaded (20)

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 

Csc1100 lecture01 ch01-pt1

  • 1. A First Book of C++ 4th Edition 1 Du`a for StudyDu`a for Study
  • 2. A First Book of C++A First Book of C++ Chapter 1Chapter 1 Getting StartedGetting Started
  • 3. ∗ In this chapter, you will learn about: ∗ Introduction to Programming ∗ Function and Class Names ∗ The cout Object ∗ Programming Style ∗ Common Programming Errors A First Book of C++ 4th Edition 3 ObjectivesObjectives
  • 4. ∗ Computer program (software) ∗ Data and instructions used to operate a computer ∗ Programming ∗ Writing computer program in a language that the computer can respond to and that other programmers can understand ∗ Programming language ∗ Set of instructions, data, and rules used to construct a program A First Book of C++ 4th Edition 4 Introduction to ProgrammingIntroduction to Programming
  • 5. ∗ Categories of Programming Language ∗ Level ∗ High-level languages (e.g., C, C++, C#, Visual Basic, Java, Python) ∗ Low-level languages (e.g., Assembly language) A First Book of C++ 4th Edition 5 Introduction to ProgrammingIntroduction to Programming (cont’d.)(cont’d.)
  • 6. Assembly vs Machine LanguageAssembly vs Machine Language A First Book of C++ 4th Edition 6 • Early computers were programmed in assembly language • To calculate wages = rates * hours in assembly language: 1) Load 2) Multiply 3) Store 010001 010011 010010
  • 7. ∗ Categories of Programming Language (cont) ∗ Orientation ∗ Procedural language ∗ Instructions are used to create self-contained units (procedures) ∗ Procedures accept data as input and transform data to produce a specific result as an output ∗ Initially, high-level programming languages were predominately procedural A First Book of C++ 4th Edition 7 Introduction to ProgrammingIntroduction to Programming (cont’d.)(cont’d.)
  • 8. Introduction to ProgrammingIntroduction to Programming (cont’d.)(cont’d.) A First Book of C++ 4th Edition 8 a + b = ? a = 2 , b =3 5
  • 9. ∗ Object-oriented languages ∗ Program must define objects that it is manipulating ∗ Such definitions include: ∗ The general characteristics of objects (attribute/state) ∗ Specific operations to manipulate objects (behavior/method) ∗ C++ is an object-oriented language ∗ Has procedures and objects ∗ Supports code reuse A First Book of C++ 4th Edition 9 Introduction to ProgrammingIntroduction to Programming (cont’d.)(cont’d.)
  • 10. ∗ C++ began as extension to C ∗ C is a procedural language developed in the 1970s at AT&T Bell Laboratories ∗ In early 1980s, Bjarne Stroustrup (“Bee-yarn-eh Strow- strup”, also at AT&T) used his background in simulation languages to develop C++ ∗ Object-orientation and other procedural improvements were combined with existing C language features to form C++ A First Book of C++ 4th Edition 10 Introduction to ProgrammingIntroduction to Programming (cont’d.)(cont’d.)
  • 11. ∗ Before writing a program, a programmer must clearly understand: ∗ What data is to be used ∗ The expected result ∗ The procedure needed to produce this result ∗ The procedure is referred to as an algorithm ∗ Step-by-step sequence of instructions describing how to perform a computation A First Book of C++ 4th Edition 11 Algorithms and ProceduresAlgorithms and Procedures
  • 12. ∗ Computers think algorithmically (step by step, use rules) NOT heuristically (based on experience, no rules)! ∗ Assume that a program must calculate the sum of all whole numbers from 1 through 100 (1+2+3+4+5+…+100) ∗ A computer: ∗ Cannot respond to heuristic command: “Add the numbers from 1 - 100” ∗ Is an algorithm-responding machine and not a heuristic- responding machine ∗ Several methods or algorithms can be used to find the required sum A First Book of C++ 4th Edition 12 Algorithms and Procedures (cont’d.)
  • 13. A First Book of C++ 4th Edition 13
  • 14. Algorithms and Procedures (cont’d.) A First Book of C++ 4th Edition 14 Calculate the result for 3 x 2
  • 15. A First Book of C++ 4th Edition 15 Flow Chart
  • 16. A First Book of C++ 4th Edition 16
  • 17. ∗ C++ source program ∗ Set of instructions written in C++ language ∗ Machine language ∗ Internal computer language ∗ Consists of a series of 1s and 0s (binaries) ∗ Source program cannot be executed until it is translated into machine language ∗ Interpreted language translates one statement at a time ∗ Compiled language translates all statements together A First Book of C++ 4th Edition 17 Program Translation
  • 18. Program Translation (cont'd.) A First Book of C++ 4th Edition 18 100100 010010int x = 8
  • 19. Processing a Program A First Book of C++ 4th Edition 19
  • 20. ∗ Modular programs ∗ Segments arranged in logical order to form an integrated unit ∗ Module ∗ Segments (small parts) of modular program ∗ Function: Name of a C++ procedure ∗ Composed of sequence of C++ instructions ∗ Function interface is its inputs and results (output) ∗ Method of converting input to results is encapsulated and hidden within function A First Book of C++ 4th Edition 20 Function and Class Names
  • 21. A First Book of C++ 4th Edition 21 Function and Class Names (cont'd.)
  • 22. Function and Class Names (cont'd.) A First Book of C++ 4th Edition 22 Accepts 2 numbers as input, produce a result 3 5 15 Input
  • 23. ∗ Identifiers (or variables) ∗ Names that convey an idea of the purpose of function or class ∗ Identifier composition rules ∗ First character must be a letter or underscore (A1, _1) ∗ Only letter, digit, or underscore may follow (AA, A2, A_) ∗ Blank spaces aren’t allowed (A B) ∗ Identify component words with initial capitalization (numPos) ∗ Cannot be C++ keyword (e.g., auto, break, int, switch …) ∗ Should be a mnemonic (short, easy to remember, meaningful) A First Book of C++ 4th Edition 23 Function and Class Names (cont'd.)
  • 24. Function and Class Names (cont'd.) A First Book of C++ 4th Edition 24
  • 25. ∗ Examples of valid identifiers: grosspay $cost (valid in C++) addNums degToRad multByTwo salesTax netPay bessel _name my$ **Note: When we combine two or more words to form an identifier (or variables), it is a good practice to capitalize each of the new word. A First Book of C++ 4th Edition 25 Function and Class Names (cont'd.)
  • 26. ∗ Examples of invalid identifiers: 4ab3(begins with a number) e*6 (contains a special character) while (is a keyword) #amount (begins with special character) A First Book of C++ 4th Edition 26 Function and Class Names (cont'd.)
  • 27. ∗ Each C++ program must have one and only one key function named main() ∗ Called a driver function because it drives the other modules A First Book of C++ 4th Edition 27 The main() Function
  • 28. The main() Function (cont'd.) A First Book of C++ 4th Edition 28
  • 29. ∗ First line of function is called header line ∗ What type of data, if any, is returned from function ∗ The name of function ∗ What type of data, if any, is sent into function ∗ Data transmitted into function at runtime are referred to as arguments of function arguments (input to function) Example: header line void sum(int a, int b) { }A First Book of C++ 4th Edition 29 The main() Function (cont'd.)
  • 30. Starting to Program with Dev C++ A First Book of C++ 4th Edition 30
  • 31. Starting to Program with Dev C++ A First Book of C++ 4th Edition 31
  • 32. The main() Function (cont'd.) A First Book of C++ 4th Edition 32 beginning of program end of program
  • 33. ∗ The cout object sends data to the standard output display device ∗ The display device is usually a video screen ∗ Name derived from console output and pronounced “see out” ∗ Data is passed to cout by the insertion symbol ∗ cout << “Hello there, World!”; A First Book of C++ 4th Edition 33 The cout Object
  • 34. The cout Object (cont’d.) A First Book of C++ 4th Edition 34 //Pre-processor command <header file> //File for pre-written classes/classes (a containet //that provides contexts/scope for variables) system(“pause”);
  • 35. The cout Object (cont’d.) A First Book of C++ 4th Edition 35 //Pre-processor command <header file> system(“pause”); std::cout << “Hello there world!”; name for namespace
  • 36. ∗ Preprocessor command ∗ Performs an action before the compiler translates source code to machine code ∗ Example: #include <iostream> ∗ Causes the iostream file to be inserted wherever the #include command appears ∗ iostream is part of the C++ standard library ∗ Included in iostream are two important classes: ∗ istream: Declarations and methods for data input ∗ ostream: Declarations and methods for data output A First Book of C++ 4th Edition 36 The cout Object (cont’d.)
  • 37. ∗ Namespace ∗ File accessed by compiler when looking for prewritten classes or functions ∗ Sample namespace statement: ∗ using namespace std; ∗ iostream contained in a namespace called std ∗ Compiler uses iostream’s cout object from std whenever cout is referenced A First Book of C++ 4th Edition 37 The cout Object (cont’d.)
  • 38. The cout Object (cont’d.) A First Book of C++ 4th Edition 38
  • 39. ∗ Newline escape sequence (“n”) ∗ Instructs the display device to move to a new line ∗ Caused when the characters backslash and n are used together ∗ Backslash provides an “escape” from the normal interpretation of the character that follows ∗ Newline escape sequences can be placed anywhere within a message to cout A First Book of C++ 4th Edition 39 The cout Object (cont’d.)
  • 40. The cout Object (cont’d.) A First Book of C++ 4th Edition 40
  • 41. ∗ Every C++ program must contain one and only one main() function ∗ Statements included within braces { } ∗ C++ allows flexibility in format for the word main, the parentheses ( ), and braces { } ∗ More than one statement can be put on line ∗ One statement can be written across lines ∗ Use formatting for clarity and ease of program reading A First Book of C++ 4th Edition 41 Programming StyleProgramming Style
  • 42. ∗ Function name starts in column 1 ∗ Name and parentheses on their own line ∗ Opening brace of function body on next line ∗ Aligned with first letter of function name ∗ Closing brace is last line of function ∗ Aligned with opening brace ∗ Standard form highlights the function as a unit A First Book of C++ 4th Edition 42 Programming Style (cont’d.)Programming Style (cont’d.)
  • 43. ∗ Within function, indent statements 2-3 spaces ∗ Creates uniform look for similar statement groups ∗ Good programming practice ∗ Final program form should be consistent ∗ Proper format improves program readability and understandability A First Book of C++ 4th Edition 43 Programming Style (cont’d.)Programming Style (cont’d.)
  • 44. ∗ Explanatory remarks written within program (//) ∗ Clarify purpose of the program ∗ Describe objective of a group of statements ∗ Explain function of a single line of code ∗ Computer ignores all comments ∗ Comments exist only for convenience of reader ∗ A well-constructed program should be readable and understandable ∗ Comments help explain unclear components A First Book of C++ 4th Edition 44 CommentsComments
  • 45. ∗ Line comment ∗ Begins with two slashes(//) and continues to the end of the line ∗ Can be written on line by itself or at the end of line that contains program code // this is a line comment ∗ Block comment ∗ Multiple-line comment begins with the symbols /* and ends with the symbols */ /* This is a block comment that spans three lines */ A First Book of C++ 4th Edition 45 Comments (cont’d.)Comments (cont’d.)
  • 46. ∗ Omitting parentheses after main() ∗ Omitting or incorrectly typing the opening brace { ∗ Opening brace signifies start of function body ∗ Omitting or incorrectly typing the closing brace } ∗ Closing brace signifies end of function ∗ Omitting the semicolon at the end of each statement ; ∗ Adding a semicolon after the #include <iostream> preprocessor command #include <iostream> ; X (wrong, no need) A First Book of C++ 4th Edition 46 Common Programming ErrorsCommon Programming Errors
  • 47. ∗ Misspelling the name of an object or function ∗ Example: Typing “cot” instead of “cout” ∗ Forgetting to close a string sent to cout with a double-quote symbol cout << “Hello world ∗ Forgetting n to indicate a new line A First Book of C++ 4th Edition 47 Common Programming ErrorsCommon Programming Errors (cont'd.)(cont'd.)
  • 48. ∗ A C++ program consists of one or more modules ∗ One module must be the function main() ∗ main() is starting point of C++ program ∗ The simplest C++ program has the form: #include <iostream> using namespaces std; int main() { program statements; return 0; } A First Book of C++ 4th Edition 48 SummarySummary
  • 49. ∗ C++ statements are terminated by a semicolon ; ∗ Standard library contains many functions and classes ∗ Standard Library provided with C++ compiler ∗ Includes <iostream> for input and output ∗ cout object displays text or numeric results ∗ Stream of characters is sent to cout by: ∗ Enclosing characters in double quotes “ ” ∗ Using the insertion (“put to”) operator, << A First Book of C++ 4th Edition 49 Summary (cont'd.)Summary (cont'd.)