C++
Outline
First Part:
Introduction to C++
Steps in C++ Program Development
IDE
General Form
Structures of a Program
Program Styles
Introduction
C programming Language
Developed in 1972 by Dennis Ritchie at Bell
Telephone laboratories
used primarily as a systems programming language.
a language to write operating systems.
efficient and flexible.
Used for re-writing UNIX OS which is written in the
Assembly language before.
C’s excellent portability allowed UNIX to be
recompiled on many different types of computers,
speeding its adoption.
C++
Developed by Bjarne Stroustrup at Bell Labs in
1979.
Extension to C
Adds many new features to the C language
Object-Oriented Programming Language(PL).
C++ Program Development
C++ Program Development (Step 1)
Compiling
Compiler – use for compiling the program.
Check the legality of C++ code.
Task:
1) To check your program and make sure it follows the rules of the
C++ language. If it does not, the compiler will give you an error
to help pinpoint what needs fixing.
2) To convert each file of source code into a machine language file
called an object file. Object files are typically named name.o or
name.obj, where name is the same name as the .cpp file it was
produced from. If your program had 5 .cpp files, the compiler
would generate 5 object files.
C++ Program Development (step 4 cont.)
Example:
G++ (g++ -c file1.cpp )
Turbo c++
Code::Blocks
C++ Program Development (step 5)
Linking
Processof taking all the object files generated by the
compiler and combining them into a single executable
program that you can run.
Uses a program called LINKER.
C++ Program Development (Step 6)
MinGW
Bloodshed’s Dev-C++
Xcode, Eclipse
Integrated Development Environment (IDE)
Project:
Stores the names of all the code files we want to
compile, and also saves various IDE settings.
Tells the compiler and linker which files to compile and
link
Will not work on different IDE’s.
Project (cont):
Will be added to a “workspace” or a “solution”.
container that can hold one or more related projects.
Must create a new workspace when you create a new project to
avoid errors and for easy implementation.
Build configuration (build target) - collection of project
settings that determines how your IDE will build your project.
Includes:
Executable file name
Directory the executable will be output in
What directories the IDE will look in for other code and header files,
whether to keep or exclude debugging information, and how highly to
have the compiler optimize your program.
Just leave it as is.
Integrated Development Environment (IDE)
Debug configuration
designedto help you debug your program, and is
generally the one you will use when developing your
programs.
General Form
Preprocessor directives(ex. #include, #define)
Main function heading (ex. Int main())
{
declarations; (ex. int x;)
executable statements; (ex. Cout<<x;)
}
Structure of a Program
Preprocessor Directives
Commands that gives instructions to the C++
preprocessor
Preprocessor – modify the text of a C++ program before it
is compiled.
Begins with the number symbol (#)
#include and #define – most commonly used