Course Notes 1
-
Upload
selcuk-can -
Category
Documents
-
view
213 -
download
0
Transcript of Course Notes 1
-
CEN 111
Introduction to Algorithms and Programming
2013-2014 Spring Term
Faculty of and Information
Technologies
Selcuk Cankurt
-
Main Textbook H.M.Deitel & P.J.Deitel, C++ How to Program, Eighth
Edition, Prentice Hall PTR, 2011.
Supplementary Textbook H.M.Deitel & P.J.Deitel, C How to Program, seventh
International Edition, Prentice Hall PTR, 2012.
Textbooks
-
COMPUTER SYSTEM
SOFTWARE HARDWARE
Computer is a device that can perform computations and make logical decisions.
Programs are the set of the instructions which tell to computer what to do and how to do.
Parts of a computer (e.g., the keyboard, screen, mouse, hard disks, memory, DVDs and processing units)
-
Computer Organization
ALU and CU INPUT OUTPUT
PROCESSING= Arithmetic Logic Unit + Control Unit
STORING
MEMORY
Every computer involves six units or sections.
keyboard, mouse
hard disks, DVDs, memory sticks
RAM, ROM
screen, printer processor
HARDWARE
-
SOFTWARE
Application Programs System Programs
Operating System Programs
UNIX, Linux, Mac OS X, iOS, Android, Solaris and Windows.
Programming languages
C, C++, Basic, Pascal, Fortran, Cobol, Java, C#
Word processing, text editor
Spreadsheets
Notepad, MS Word
MS Excel
Presentation programs
MS PowerPoint
Database programs
MS Access, MS SQL, Oracle, MySQL
-
Type of the programming language
i ) low level programming languages
Machine language
Assemble language
ii ) high level programming languages
e.g.: Pascal, C, C++, Fortran
-
Low level languages Machine languages are the only languages understood by the computers directly. But, machine languages are not human readable languages because they consist entirely a stream of 0's and 1's. Each type of processor has its own machine language and assembly language, so an assembly language program written for one type of processor won't run on another. Machine language performs much faster. Assembly language is similar to machine language, but they are much easier to program in because they allow a programmer to use English-like abbreviations rather than numbers. Programs so-called assemblers are used to convert assembly-language programs to machine languages.
-
High-level languages make the programmers able to type instructions
almost like everyday English and mathematical notations. Using high-
level languages speeds the time of the program writing process.
Programs so-called compilers convert high-level language programs
into machine language.
C, C++, Visual Basic.NET, Visual C++, Visual C#, Java are among the most
widely used high-level programming languages.
High level languages
-
History of C and C++
BCPL was developed in 1967 by Martin Richards as a language for writing
operating systems software and compilers for operating systems.
Ken Thompson modeled many features in his language B after their
counterparts in BCPL.
The C language was evolved from B by Dennis Ritchie at Bell Laboratories.
C++, an extension of C, was developed by Bjarne Stroustrup in the early 1980s
at Bell Laboratories.
-
Java is one of the most used programming language to develop large-scale enterprise applications, to enhance the functionality of web servers (the computers that provide the content we see in our web browsers), to provide applications for consumer devices (e.g., cell phones, pagers and personal digital assistants) and for many other purposes.
FORTRAN (FORmula TRANslator) was developed by IBM Corporation in the mid-1950s to be used for scientific and engineering applications that require complex mathematical computations. Fortran is still widely used in engineering applications.
COBOL (COmmon Business Oriented Language) was developed in the late 1950s by computer manufacturers, the U.S. government and industrial computer users. COBOL is used for commercial applications that require precise and efficient manipulation of large amounts of data. Much business software is still programmed in COBOL.
The -purpose Symbolic Instruction Code) programming language was developed in the mid-1960s at Dartmouth College as a means of
programming techniques.
-
-wide strategy for
integrating the Internet and the web into computer applications. This strategy is
need to make and run computer applications that can execute on computers
Visual Basic (based on the original BASIC), Visual C++ (based on C++) and Visual C# (a
new language based on C++ and Java that was developed expressly for the .NET
platform).
-
Examples for languages:
1111001010
0101010101
1101001010
1101010101
1010101011
load 5
add 4
store a
program add; begin
var a : integer;
a:=5+4;
end.
Machine language
Assembly language
Pascal Language
If you write a program to add the number 5 and the number 4 in machine, assembly, Pascal and C++ languages typical program
codes will be following:
C++ Language
int main() {
int a=5+4;
}
-
ADVANTAGES OF
LOW LEVEL LANGUAGE HIGH LEVEL LANGUAGE
1. It occupies less space in memory.
2. It performs (runs) very fast.
3. Because it is only program that
computer can understand directly,
program.
1. It is easier to learn and closer to
human language.
2. It is easier to analyze to be partially
rewritten or updated to conform to
changing conditions.
3. It is simpler to debug to find the
mistakes and problems.
4. It makes enable the programmers
to type programs without having to
know the details of the parts of the
computer.
-
Typical C++ Development Environment
C++ programs typically go through six phases: 1. edit, 2. preprocess, 3. compile, 4. link, 5. load and 6. execute.
-
How to make C++ programs
C++ Compilers C++ Interpreters C++ IDEs (Integrated Development Environments)
You can select your C++ programming tool according to your platform (Type of the computer such as x86, x64, and Itanium and operating system).
-
Integrated Development Environments provides comprehensive tools for typing and editing codes adding and editing resources building (compiling and linking) debugging codes deploying applications
-
Intel Software Development Products with C++
Intel Parallel Studio XE 2013 SP1 Intel Composer XE 2013 for Windows and Linux, formerly Intel Compiler Suite Intel C++ Composer XE 2013 for Windows, Linux, and Mac OS X, formerly Intel C++ Compiler
-
Performance
Source: http://www.microway.com.au/catalog/intel/
Intel Plus is tool of Intel C++ and is a powerful capability for increasing C++ application performance.
It is a lot more than a Fortran and C++ compiler. It includes three powerful, function libraries that offer the easiest way in which to add parallelism-based performance to your application software. The three libraries are:
Intel Math Kernel Library, also known as Intel MKL Intel Integrated Performance Primitives, also known as Intel IPP Intel Threading Building Blocks, also known as Intel TBB
-
Source: http://www.microway.com.au/catalog/intel/
-
Embarcadero RAD Studio XE5
With RAD Studio's multi-device app development, you don't have to maintain separate development projects to deliver your app natively for multiple devices (PCs, tablets and smartphones) on multiple platforms (Android, iOS, Windows, and OS X).
Embarcadero C++Builder XE5
For building true native apps for Windows and OS X.
-
Oracle Solaris Studio 12.3 #1 Development Platform for Oracle Systems with C, C++ and Fortran development tool suite, delivers the latest in compiler optimizations, multithread performance, and powerful analysis tools for the best application performance and reliability on Oracle Solaris, Oracle Linux, and Red Hat Enterprise Linux operating systems.
http:// www.oracle.com/technetwork/server-storage/solarisstudio/downloads/index.html
http://www.oracle.com/technetwork/server-storage/solarisstudio/downloads/index.htmlhttp://www.oracle.com/technetwork/server-storage/solarisstudio/downloads/index.htmlhttp://www.oracle.com/technetwork/server-storage/solarisstudio/downloads/index.htmlhttp://www.oracle.com/technetwork/server-storage/solarisstudio/downloads/index.html -
FastReport InterBase TeeChart
IntraWeb Beyond Compare AQtime
CodeSite glyFX Icon Library IP*Works
Tools and Components included in C++Builder
C++Builder XE5 includes sophisticated tools and components from Embarcadero Technology Partners at no extra cost to make you able to develop applications. Some of them are listed below:
http://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-componentshttp://www.embarcadero.com/products/cbuilder/tools-and-components -
Microsoft Visual Studio Express 2013 for Windows Desktop / for Web / for Windows free versions. You can use Visual Studio Express 2013 to make powerful desktop apps / innovative web apps and web APIs / Windows Store apps in C#, Visual Basic, and C++.
Microsoft Visual Studio 2013 Ultimate / Premium / Professional paid versions.
Visual Studio 2013 is an integrated development environment that includes advanced tools.
http://msdn.microsoft.com/en-us/dn369242 for download
http://msdn.microsoft.com/en-us/dn369242http://msdn.microsoft.com/en-us/dn369242http://msdn.microsoft.com/en-us/dn369242 -
Code::Blocks IDE for C/C++ Code::Blocks is a free, open-source, cross-platform C/C++ IDE
Dev-C++
A portable, free C/C++/C++11 IDE
Eclipse
Eclipse is an IDE to develop Java by default, and has plugins to support: Ada, C, C++, COBOL, Perl, PHP, Python, R, Ruby, Scala, Clojure, Groovy and Scheme.
NetBeans is an IDE for developing primarily with Java, but also with other languages, in particular PHP, C/C++, and HTML5. The NetBeans IDE is written in Java and can run on Windows, OS X, Linux, Solaris and other platforms supporting a compatible JVM.
-
Interpreters
Every time a program is run, Interpreter directly execute the source codes (program instructions) statement by statement (instruction by instruction).
Compilers Compiler translates the source codes (program instructions) which is written with the help of a human readable language into the machine readable language which can be understood by a computer.
Scripts languages work by the same way with the interpreters.
Some programming languages, such as C#, Visual Basic .NET, and Java firstly compile the source codes into the intermediate language which is so-called common intermediate language (CIL). Then their components called virtual machine (VM) or runtimes translate those intermediate codes into the actions like interpreters.
-
Compilers vs. Interpreters In the compilation, firstly complier program translates the source code into an intermediary form and produce a file called an object file with the extension .obj or .o. Then another program called linker combines one or more object files with one or more library files and produces an executable file with the extension .exe.
Interpreting is a far faster process to only edit and test codes. But once a source code is compiled, compiled program runs much faster than interpreted program. Another advantage of compiler is that you can distribute the executable
with the interpreter and each time you want to run the source code you need the interpreter.
-
A use of C++ Interpreter
In the Large Hadron Collider (LHC) experiments at CERN project, The four major LHC experiments have today more than 100 Petabytes of data in the form of C++ objects managed by the ROOT software. This software employs C++ interpreter. Several GB of libraries Hundreds of thousands of types / templates 50 MLOC C++ codes
-
C++ Compilers
GNU Compiler Collection (GCC) http://gcc.gnu.org/ GCC is a compiler system produced by the GNU Project supporting various programming languages. GNU is a Unix-like computer operating system developed by the GNU Project. It is composed wholly of free software.
GCC is included in all Unixes. For Windows, you could either install MinGW GCC or Cygwin GCC.
The GNU C and C++ compiler are gcc and g++, respectively.
http://gcc.gnu.org/http://gcc.gnu.org/ -
C++ Compilers
http:// www.compileonline.com/compile_cpp_online.php
Compile and Execute C++ Online (GNU GCC version 4.8.1)
Cygwin = GNU + Cygnus + Windows. Cygwin is a Open-source Linux-like environment for Windows. It consists of two parts: (1)A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing substantial Linux API functionality. (2) A collection of tools which provide Linux look and feel.
Cygwin http://www.cygwin.com/
MinGW (short for "Minimalist GNU for Windows") is a port of the GNU Compiler Collection (GCC), including C, C++, ADA and Fortran offers a development environment for native Microsoft Windows applications.
MinGW http://www.mingw.org/
http://www.compileonline.com/compile_cpp_online.phphttp://www.compileonline.com/compile_cpp_online.phphttp://www.cygwin.com/http://www.cygwin.com/http://www.mingw.org/http://www.mingw.org/ -
http://www.youtube.com/watch?v=f9Xfh8pv3Fs&list=PLAD733A8B80755D88
C++ Interpreters
Actually C++ is a compiled language, but there are some C++ interpreters.
CINT CINT is an interpreter for C and C++ code.
http://root.cern.ch/drupal/content/cint
CLING The C++ interactive interpreter cling is based on LLVM and its C++ frontend clang.
A tutorial for a practical use of CLING:
http://root.cern.ch/drupal/content/cling-brief
http://www.youtube.com/watch?v=f9Xfh8pv3Fs&list=PLAD733A8B80755D88http://root.cern.ch/drupal/content/cinthttp://llvm.org/http://clang.llvm.org/ -
Languages like , on the other hand, are procedural, so programming tends to be action oriented. In C, the unit of programming is the function.
Languages like C++ are object oriented. Programming in such a language is called object-oriented programming (OOP). In C++, the unit of programming is the class from which objects are eventually instantiated (an OOP term for
functions that implement operations and data that implements attributes.
C programmers concentrate on writing functions. Programmers group actions that perform some common task into functions, and group functions to form programs.
C vs. C++
-
First Program in C++: Printing Text
// a C++ program to display text messages on the screen.
#include // adds iostream library file
using namespace std ; // define the scope of standard namespace
int main() // this is main function
{
cout
-
using namespace std ; int main() { }
Basic anatomy of C++ programs
Every C++ program has the same essential format.
-
First Program in C++: Printing a Line of Text
// a C++ program to display text messages on the screen. #include // adds iostream library file
using namespace std ; // define the scope of standard namespace
int main() // this is main function
{
cout
-
Block style (C-like style) can span multiple lines.
/* Start of the comment .... .... End of the comment */
Line comments -- use the double-slash // and only can be wide of a line.
a = 5; // This is an example for the single line comment
Comments
Comments are used for documenting program codes. They are ignored by the compiler
like whitespaces.
-
First Program in C++: Printing a Line of Text
// a C++ program to display text messages on the screen. #include // adds iostream library file
using namespace std ; // define the scope of standard namespace
int main() // this is main function
{
cout
-
First Program in C++: Printing a Line of Text
// a C++ program to display text messages on the screen. #include // adds iostream library file
using namespace std ; // define the scope of standard namespace
int main() // this is main function
{
cout
-
First Program in C++: Printing a Line of Text
// a C++ program to display text messages on the screen. #include // adds iostream library file
using namespace std ; // define the scope of standard namespace
int main() // this is main function
{
cout
-
First Program in C++: Printing a Line of Text
// a C++ program to display text messages on the screen. #include // adds iostream library file
using namespace std ; // define the scope of standard namespace
int main() // this is main function
{
cout
-
endl (std::endl) a so-called stream manipulator. The name endl is an abbreviation
endl stream manipulator outputs
to display them on the screen, std::endl forces any accumulated outputs to be displayed
at that moment. This can be important when the outputs are prompting the user for an
action, such as entering data.
cout
-
First Program in C++: Printing a Line of Text
// a C++ program to display text messages on the screen. #include // adds iostream library file
using namespace std ; // define the scope of standard namespace
int main() // this is main function
{
cout
-
cout
-
Output and input in C++ are accomplished with streams of characters. Thus, when the
preceding statement is executed, it sends the stream of characters to C
to the standard output stream object cout (std::cout) which is
screen by the default value.
More closer to the cout
cout
-
#include
using namespace std ;
int main()
{
cout