CPS 6L.2 Ramm - Fall 2001 - 8/29/01 #2
- Announce
- Now in Room D106 LSRC
- Roll
- Lab #1 starts Tuesday
- Friday Quizzes start next week
Chapter 2: C++ Programs: Form and Function
- First Programs
sample code
- Sample Function Call
rainf.cpp
- It's longer.
- What have we gained?
- Flow of Control
- Always start with
main()
- Learn to go with the flow...
- Producing Output
- The output stream
cout
- Stream Insertion Operator
<<
- Inserting multiple items in one statement
- Functions: Dia and Mond
diamond.cpp
tree.cpp
- How does the flow go here?
- Literals: string and integer 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
- Make up English sentence that is grammatically wrong
but whose meaning is clear.
- Semantics/Meaning
- Make up English sentence that is grammatically correct
but has problems
- 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!)
- Communicating with humans ...
- ... maybe yourself!
- Functions with Parameters
Flexibility/Versatility
rect5by.cpp
page.cpp
- Functions with several parameters
announce.cpp
- 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