CHAP02 - Chapter 2 C+ Syntax and Semantics, and the Program...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Chapter 2 Topics Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation Output Statements C++ Program Comments
Background image of page 2
3 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
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Program With Several Functions main function square function cube function
Background image of page 4
5 Program With Three Functions #include <iostream> int Square( int ); // declares these two int Cube( int ); // value-returning functions using namespace std ; int main( ) { cout << “The square of 27 is “ << Square(27) << endl; // function call cout << “The cube of 27 is “ << Cube(27) << endl; // function call return 0; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Rest of Program int Square( int n ) { return n * n; } int Cube( int n ) { return n * n * n; }
Background image of page 6
7 Output of program The square of 27 is 729 The cube of 27 is 19683
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Shortest C++ Program int main ( ) { return 0; } type of returned value name of function
Background image of page 8
What is in a heading? int main ( ) type of returned value name of function says no parameters
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 a block is a sequence of zero or more statements enclosed by a pair of curly braces { } SYNTAX { Statement (optional) . . . } Block (Compound Statement)
Background image of page 10
Every C++ function has 2 parts int main ( ) heading { body block     return 0; }
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 What is an Identifier? An  identifier  is the name used for a  data object (a variable or a constant),  or for a function,  in a C++ program. C++ is a case-sensitive language. using meaningful identifiers is a good  programming practice
Background image of page 12
13 Identifiers an identifier must start with a letter or underscore, and be followed by zero or more letters (A-Z, a-z), digits (0-9), or underscores VALID age_of_dog taxRateY2K PrintHeading ageOfHorse NOT VALID (Why?) age# 2000TaxRate Age-Of-Cat
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 37

CHAP02 - Chapter 2 C+ Syntax and Semantics, and the Program...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online