You are on page 1of 35

CSC240

INTRODUCTION TO PROGRAMMING – I
Mr. Imran yar
Lecturer,
Department of Computer Science,
Jahan University
Kabul, Afghanistan.
Previous Lecture Outline
• Understanding the concept of flowcharts.
• Working with sequence, decision, repetition and case control
flowchart structures.
• Understanding algorithms.
Lecture Outline
• Introduction to C++ and other popular programming languages
• Historical development of C++
• Writing C++ program
• Structure of C++ program
Introduction to C++
• C++ is the advanced version of C language that is used for developing
computer programs.
• C++ is a powerful programming language that fully supports
• Procedural programming
• Object-oriented programming
• Data abstraction
• Generic programming
Java
• It’s one of the most widely adopted programming languages,
• used by some 9 million developers and running on 7 billion devices
worldwide.
• It’s also the programming language used to develop all native Android
apps.
• Java’s popularity with developers is due to the fact that the language
is grounded in readability and simplicity
JavaScript
• JavaScript – not to be confused with Java – is another one of the
world’s most popular and powerful programming languages, and is
used to spice up web pages by making them interactive. For example,
JavaScript can be used to add effects to web pages, display pop-up
messages or to create games with basic functionality. It’s also worth
noting that JavaScript is the scripting language of the World Wide
Web and is built right into all major web browsers including Internet
Explorer, FireFox and Safari.
C#
• Dating from 2000, C# (pronounced C-sharp) is a relatively new
programming language designed by Microsoft for a wide range of
enterprise applications that run on the .NET Framework. An evolution
of C and C++, the C# language is simple, modern, type safe and
object oriented.
BCPL

• BCPL (Basic Combined Programming Language) is a procedural,


imperative, and structured computer
programming language designed by Martin Richards of the University
of Cambridge in 1966. Originally intended for writing compilers for
other languages, BCPL is no longer in common use.
B language
B is a programming language developed at Bell Labs 1969. It is the
work of Ken Thompson with Dennis Ritchie. B was derived from BCPL,
and its name may be a contraction of BCPL
C
• BCPL and B are "type less" languages whereas C provides a variety of
data types. In 1972 Dennis Ritchie at Bell Labs writes C and in 1978
the publication of The C Programming Language by Kernighan &
Ritchie caused a revolution in the computing world.
C++
• C++ (pronounced C-plus-plus) is a general purpose object-oriented
programming language based on the earlier ‘C’ language. Developed
by Bjarne Stroustrup at Bell Labs, C++ was first released in 1983.
Stroustrup keeps an wide list of applications written in C++. The list
includes Adobe and Microsoft applications, MongoDB databases,
large portions of Mac OS/X and is the best language to learn for
performance-critical applications such as “twitch” game development
or audio/video processing.
Writing C++ Program
• C++ systems generally consist of three parts
• A program development environment
• The language
• C++ Standard Library
• C++ programs typically go through six phases
• Edit, Preprocess, Compile, Link, Load and Execute.
Writing C++ Program
Writing C++ Program
Writing C++ Program
• Phase 1 consists of editing a file with an editor program, normally
known simply as an editor.
• Type a C++ program (source code) using the editor.
• Make any necessary corrections.
• Save the program.
• C++ source code filenames often end with the .cpp, .cxx, .cc or .C extensions
(note that C is in uppercase) which indicate that a file contains C++ source
code.
Writing C++ Program
Writing C++ Program
• Linux editors: vi and emacs.
• C++ software packages for Microsoft Windows such as Microsoft
Visual C++ (microsoft.com/express) have editors integrated into the
programming environment.
• You can also use a simple text editor, such as Notepad in Windows, to
write your C++ code.
• Integrated Development Environments (IDEs)
• Provide tools that support the software-development process, including
editors for writing and editing programs and debuggers for locating logic
errors—errors that cause programs to execute incorrectly.
Writing C++ Program
• Popular IDEs
• Microsoft® Visual Studio 2012 Express Edition
• Dev C++
• NetBeans
• Eclipse
• Apple’s Xcode
• CodeLite
Writing C++ Program
• In phase 2, you give the command to compile the program.
• A preprocessor program executes automatically before the compiler’s
translation phase begins (so we call preprocessing Phase 2 and compiling
Phase 3).
• The C++ preprocessor submits commands called preprocessing directives,
which indicate that certain manipulations are to be performed on the
program before compilation.
• These manipulations usually include other text files to be compiled, and
perform various text replacements.
Writing C++ Program
Writing C++ Program
• In Phase 3, the compiler translates the C++ program into machine-
language code—also referred to as object code.
Writing C++ Program
• Phase 4 is called linking.
• The object code produced by the C++ compiler typically contains “holes” due
to some missing parts.
• A linker links the object code with the code for the missing functions to
produce an executable program.
• If the program compiles and links correctly, an executable image is produced.
Writing C++ Program
Writing C++ Program
• Phase 5 is called loading.
• Before a program execution , it must first be placed in memory.
• This is done by the loader, which takes the executable image from disk and
transfers it to memory.
• Additional components from shared libraries that support the program are
also loaded.
Writing C++ Program
Writing C++ Program
• Phase 6: Execution
• Finally, the computer, under the control of its CPU, executes the program
one instruction at a time.
• Some modern computer architectures can execute several instructions in
parallel.
Writing C++ Program
Writing C++ Program
• Problems That May Occur at Execution Time
• Programs might not work on the first try.
• Each of the preceding phases can fail because of various errors that we’ll
discuss throughout this book.
• If this occurred, you’d have to return to the edit phase, make the necessary
corrections and proceed through the remaining phases again to determine
that the corrections fixed the problem(s).
Writing C++ Program
Structure of C++ Program
• Preprocessor Directives
• Header Files
• main() function
• Body of main() function
• Statements
Structure of C++ Program
Components of C Program multi-line comment
block
single line comment /*
block C Programming for the Absolute Beginner
*/
standard input output
//by Michael Vine
preprocessor library
directive #include <stdio.h>
main() program statement
begin logical {
program block printf("\n C you later \n") ;
}
end logical
program block
program statement
printf function escape sequence terminator
Structure of C++ Program
• The instructions that are given to the compiler before the beginning
of the actual program are called preprocessor directives.
• Also known as compiler directives.
• The preprocessor directives consist of instructions for the compiler.
• The compiler adds special instructions or code from these directives into the
program at the time of compilation.
• It starts with a # (HASH) or (SHARP) and the keyword include or define.
• They are used to include header files.
Summery
• Introduction to C++ and other popular programming languages
• Historical development of C++
• Writing C++ program
• Structure of C++ program
Thank You
For your Patience

You might also like