Date: Tue, 14 Jan 1997 23:13:28 GMT Server: Apache/1.1.1 Content-type: text/html Content-length: 10029 Last-modified: Wed, 28 Aug 1996 19:38:30 GMT Data Structures - Lecture 2

Data Structures - Lecture 2

Topics

References

Topics

Hello World!

Hello World - Source Code

Hello World - Compile/Execute

Topics

Data Types - Type Categories

Void Type

Integral Types

Floating Point Types

Enumeration Types

Pointer Types (Example)

Array Types (Example)

Function Types

Function Example

Functions in C++

Topics

Operators

Assigment Operators

Binary Arithmetic Operators

Unary Operators

Relational Operators

Logical Operators

Bit Operators

Misc. Operators

Expressions

Statements

If Statement

While Statement

Do Statement

For Statement

Switch Statement

Example
switch (response) {
case 'q': exit(0); // quit
case 's': process_s(); break;
case 'h': process_h(); break;
default:
cout << "Invalid Response\n";
break;
}

Break/Continue

Example:
for (i=0; i<n; i++) {
if (s[i] < 0) break; // exits loop
if (s[i] > 0) continue;
cout << "s[i]=0 for i=" << i;
}
cout << "i>=n or s[i]<0 for i=" << i;

Topics

Input/Output

Errors in Input

Topics

Topics

Main

Example: main.cpp
int main (int argc, char ** argv) {
for (int i=0; i<argc; i++) {
cout << "Argv[" << i << "] = "
<< argv[i] << endl;
}

Files

Makefile Example

Header Files

Topics

Optional Exercises

Write function rot13, to encrypt/decrypt a string. For example, rot13("abxy") should return "nokl". Note: use rot13.h, rot13.cpp