Transition from C to C++

20
Transition from C to C++ …and a Review of Basic Problem Solving

description

Transition from C to C++. …and a Review of Basic Problem Solving. Why Switch to C++. To pass this class. ;-) To get a job (or “Everyone else is doing it…”) Path of least resistance to OOP Nicer I/O model Better comment format. Why Switch to C++ (cont’d). - PowerPoint PPT Presentation

Transcript of Transition from C to C++

Page 1: Transition from C to C++

Transition from C to C++

…and a Review of Basic Problem Solving

Page 2: Transition from C to C++

Why Switch to C++

• To pass this class. ;-)

• To get a job (or “Everyone else is doing it…”)

• Path of least resistance to OOP

• Nicer I/O model

• Better comment format

Page 3: Transition from C to C++

Why Switch to C++ (cont’d)

• Supports an OO approach to programming– Classes– Inheritance– Polymorphism– Exceptions

• Provides powerful features on top of a “fast” language

Page 4: Transition from C to C++

How to Switch to C++

1. Learn about differencesa. New tools (compilers, debuggers, etc.)

b. New libraries

c. New file naming conventions

d. New syntax

e. Available standards

2. Rethink programming approach

Page 5: Transition from C to C++

1a. New Tools for C++

• Compiler: g++ or CC (CC is only on the SGIs)

• Debugger: gdb, dbx (SGI), cvd (SGI), or printf(). ;-)

• Some text editors “understand” C++. (formatting, syntax highlighting)

Page 6: Transition from C to C++

1b. New Libraries for C++

• All of the C libraries still work!

• Some C++ specific libraries will be introduced throughout the semester.

Page 7: Transition from C to C++

1c. New File Naming Conventions for C++

• Some conventions for file names– foo.H, foo.C– foo.hh, foo.cc– Also foo.cpp, foo.cxx

• Conventions for source code are on the course web page under Coding Standards

Page 8: Transition from C to C++

1d. New Syntax

• Syntax virtually identical to C– C++’s features add syntax

• More on syntax throughout the semester

Page 9: Transition from C to C++

1e. Available Standards

• ISO/IEC 14882 in 1997– Adopted ANSI in 1998

Page 10: Transition from C to C++

2. Rethinking Programming Approach

• Programming languages provide tools– Tools are your language to solve problems– Learn to work with them, not against them– Use the idioms of the language

Page 11: Transition from C to C++

Some questions about C

• What is C?– C is a low-level, procedural, systems

programming language.

• What problem did C solve?• Designed as a system’s programming language

for UNIX in the 1970s• A fast, flexible, low-level language was needed.

Page 12: Transition from C to C++

Some Questions about C++

• What is C++?– C++ is an extension of C that provides support

for object-oriented programming.

• What problem did it solve?– Stroustrup states, “I built C++ as a bridge over

which people would pass from traditional programming to styles relying on data abstraction and object-oriented programming.”

Page 13: Transition from C to C++

Procedural vs. Object-oriented

• Procedural Programming– Program execution is a series of “procedures” operating

on data.

– Procedures (or “operations”) and data are separate constructs.

• Object-oriented Programming– Program execution is a series of object interactions.

– Data and operations on those data belong together as a single unit.

Page 14: Transition from C to C++

Why OOP?

• OOP was “discovered” in the 1960s:– The Simula project

• Collections of variables and procedures for “natural units of programming”.

Page 15: Transition from C to C++

Goals of Software Development

• When developing software, we strive for software that is:– Correct (meets requirements)– Reliable (bug free)– Easily maintained (corrections and upgrades)– Reusable

Page 16: Transition from C to C++

C++ for Software Development

• As an “object-oriented” language, C++ helps create– Reusable code– More easily maintained code

• Bad programmers will still write bad programs.

Page 17: Transition from C to C++

Problem Solving

(A Review)

Page 18: Transition from C to C++

Tools for Problem Solving

1. Defining the problem (WHAT)• Formalization

2. Developing a solution (HOW)– Creativity– Decomposition

Page 19: Transition from C to C++

1. Defining the problem

• Formalize the problem– Name it– If you can’t formalize it, you don’t understand it

• Make your program solve the problem at hand (or a more general version of the same problem)

• Constraints are part of the problem too!– Time– $$$– Other Resources (memory, etc.)

Page 20: Transition from C to C++

2. Developing a solution

• Creativity– Creative != “Slick”

• Decomposition– Top down design– Every problem consists of subproblems.

• Decompose your problem into its subproblems, then repeat on each subproblem.

• Understand the interaction of the subproblems, then solve them one by one.