cs - Click to edit Master subtitle style Chapter 2...

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style 11 Chapter 2 Dale/Weems
Background image of page 1

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

View Full DocumentRight Arrow Icon
22 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
33 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
44 Program With Several Functions main function square function cube function
Background image of page 4
55 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
66 Rest of Program int Square(int n) { return n * n; } int Cube(int n) { return n * n * n; }
Background image of page 6
77 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
88 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 9
Background image of page 9

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

View Full DocumentRight Arrow Icon
1010 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; } 11
Background image of page 11

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

View Full DocumentRight Arrow Icon
1212 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 Beware: C++ is a case-sensitive language Using  meaningful identifiers  is a good  programming practice
Background image of page 12
1313 Identifiers An identifier must start with a alphabetic 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
1414 More About Identifiers Some C++ compilers recognize only the first 32 characters of an identifier as significant Then these identifiers are considered the same: age_Of_This_Old_Rhinoceros_At_My_Zoo age_Of_This_Old_Rhinoceros_At_My_Safari Consider these:
Background image of page 14
1515 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long double
Background image of page 15

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

View Full DocumentRight Arrow Icon
1616 C++ Simple Data Types simple types integral floating char short int long bool enum float double long double unsigned
Background image of page 16
1717 Standard Data Types in C++ Integral Types represent whole numbers and their negatives declared as int , short , or long Floating Types represent real numbers with a decimal point declared as float , or double Character Types represent single characters declared as char
Background image of page 17

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

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

This note was uploaded on 10/23/2010 for the course BIOL 2308 taught by Professor Boxer during the Spring '10 term at University of Houston - Downtown.

Page1 / 52

cs - Click to edit Master subtitle style Chapter 2...

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

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