Presentation on theme: "Transition from C to C++ …and a Review of Basic Problem Solving."— Presentation transcript:
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) Supports an OO approach to programming –Classes –Inheritance –Polymorphism –Exceptions Provides powerful features on top of a “fast” language
How to Switch to C++ 1. Learn about differences a. New tools (compilers, debuggers, etc.) b. New libraries c. New file naming conventions d. New syntax e. Available standards 2. Rethink programming approach
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)
1b. New Libraries for C++ All of the C libraries still work! Some C++ specific libraries will be introduced throughout the semester.
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
1d. New Syntax Syntax virtually identical to C –C++’s features add syntax More on syntax throughout the semester
1e. Available Standards ISO/IEC in 1997 –Adopted ANSI in 1998
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
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.
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.”
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.
Why OOP? OOP was “discovered” in the 1960s: –The Simula project Collections of variables and procedures for “natural units of programming”.
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
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.
Problem Solving (A Review)
Tools for Problem Solving 1. Defining the problem (WHAT) Formalization 2. Developing a solution (HOW) –Creativity –Decomposition
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.)
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.