CPS 6, Ramm - Summer Semester I - 5/19/00 #2
- Announce
- Roll
- Lab #1 Today
- Assignment #1
Chapter 2: C++ Programs: Form and Function
- Functions: Dia & Mond
diamond.cpp
tree.cpp
- Flow of Control
- Output, Stream Insertion Operator
<<
- Literals: string, integer, real, expressions
cout << "product = " << "12" << endl;
cout << "product = " << 12 << endl;
cout << "product = " << "3 * 4" << endl;
cout << "product = " << 3 * 4 << endl;
literals.cpp
What is evaluated? What is not?
- Syntax/Grammar
- Semantics/Meaning
- Some C++ Syntax Rules
- Start with
#include statements
- Follow with user-defined functions (if any)
- Must have
int main() function
- Case is Important
- (more to come)
- Style (Important!)
- Functions with Parameters
Flexibility/Versatility
rect5by.cpp
page.cpp
- Functions with several parameters
announce.cpp
Order of Parameters
- Functions Invoking Functions
diamond2.cpp
- Order of Functions
mondias.cpp
- Function Prototypes - Syntax
return-type
function(type name, type name, ...);
return-type
function(type, type, ...);
===>>> ;
- Using Function Prototypes
diamondsp.cpp
- Let's Write a Program (class activity)
Requirements:
- Use functions
- Have functions use functions
- Minimize repetition
- Some kind of "graphic" output
Questions:
- Do we need prototype statements?
- What language features could we use?
- More on Style
- Indenting
- Braces on separate lines
- Good Identifiers
- Identifiers/Syntax
- letters, digits, underscore
- do not start with digit
- case sensitive
- arbitrary length
- do not use reserved words
- Identifiers/Style
- meaningful identifiers
- user defined functions & types start: uppercase
- parameters or variables start: lowercase
- constants (later): all uppercase
- use uppercase to start multi-part words (not _)