------------------------------------------------------------------------------
MC logo
Code Examples
[^] CSc 220: C and C++ Programming
------------------------------------------------------------------------------ This page links a large number of small code examples for use in lecture.

Introduction

Expressions, Statements and Functions

Basic Constructs
o Hello, World!
o Hello in C++
o Newlines
o Identifiers
o Constants
o An Average Example
o Problems With C I/O
o Average in C++
o Increment Operators
o C++ Strings
Control Constructs
o Boolean Operations
o Another Average Example
o Reading In the While Test
o Using Update Operators
o Watch Out For This
o Comparison Pitfall
o For Loops
o Average For Loop
o Tom Five Times I
o Tom Five Times II
o Tom Five Times III
o Tom Five Times IV
o Tom Five Times V
o Switch
o Switch Using Break
o Break and Continue
o Calculator Example
Functions In Plain C
o Functional Average
o Functional Average II
o Functional Average III
Functions In C++
o C++ Functions
o Default Parameters
o Function Overloading
o Reference Parameters
o Constant References

Data

Character Processing
o Character Operations
o Print the ASCII Set
o Convert To Upper Case
o Convert To Upper Case in C++
o Remove Indentation
o Input Statistics
o Character Warnings
Basic Types
o Builtin Types
o Sizeof Operator
o Type Conversion
o Unsigned Pitfalls
o Enum Declaration
o Typedef Declaration
Arrays and Pointers
o Array Echo
o Basic Pointers
o Swap Using Pointers
o Arrays and Pointers
o Array Passing
o Character Histogram Generator
o Integer Select Sort
o Integer Quick Sort
o Integer Library Sort
o Array Error I
o Array Error II
o Array Error III
o How Big Do You Want That Array, Sir?
o Dynamic Array Allocation
o Variable-Sized Arrays
Plain C Strings
o C Strings
o C String Facility
o String Copy Implementation I
o String Copy Implementation II
o String Copy Implementation III
o Simple String Sort
o String Sort With Dynamic Allocation
o List Command-Line Arguments.
o Simple String Formatter
o String Error
Structs and Classes
o C Structs
o Point With Struct
o C++ Point Class I
o C++ Point Class II
o Linked List (Structs)
o Linked List (Classes)

Multi-File Programs

o Introduction
C Point ADT
o Point Header File
o Point Implementation File
o Point Driver File
C++ Point ADT I
o Point Class Header File
o Point Class User File
C Point ADT II
o Point Class Header File II
o Point Class Implementation File II
o Point Class User File II
C Point ADT III
o Point Class Header File III
o Point Class Implementation File III
o Point Class User File III
C Integer Stack ADT
o C Integer Stack ADT
o C Integer Stack Implementation
o C Integer Stack Driver
C++ Integer Stack ADT
o C++ Integer Stack ADT
o C++ Integer Stack Implementation
o C++ Integer Stack Driver

Inheritance

Basics
o PrintMe Class
o PrintMe2 Class
o PrintMeLots Class
o PrintMeLots2 Class
o PrintMe Test Driver
Stack
o Generalized Stack Class
o Generalized Stack Implementation
o Generalized Stack Driver
Ugly Shapes
o Ugly Shapes
o Text Canvas Class
o Text Canvas Implementation
o Shape Classes
o Shape Implementations
o Compound Shape Class
o Compound Shape Implementation
o Shape Driver I
o Shape Driver II
o Shape Driver III
o Shape Driver IV
o Multiple Inheritance
o Expression Calculator
Linked Lists
o Linked List Node Classes
o Linked List Classes
o Linked List Implementation
o Linked List Driver

Templates

o Template Functions
Template Stack
o Template Generalized Stack
o Template Generalized Stack Driver
Array Template Stack
o Array Template Stack
o Array Template Test Driver
o Vector Demo
o Vector Demo With Iterators
Fast Primes Generator
o Prime Generator Algorithm
o Composite Number Eliminator Class
o Composite Number Eliminator Implementation
o Fast Primes Generator