Basic C++ lectures 1 and 2MSc Bioinformatics Basic C++
Basic C++ lectures 1 and 2MSc Bioinformatics Introduction Daniel Soto phone: address:Departament de Tecnologia Desp.374 Estació de França Passeig de Circumval·lació, Barcelona
Basic C++ lectures 1 and 2MSc Bioinformatics Introduction Philosophy: learn to program with objects Bibliography The C++ Programming Language, 3rd Edition by Bjarne Stroustrup. Addison Wesley Professional. “Aprenda C++ como si estuviera en primero” manualcpp.pdf
Basic C++ lectures 1 and 2MSc Bioinformatics Programming Languages Machine Languages Assembly Languages High-Level Languages LOAD A ADD B STORE C C=A+B
Basic C++ lectures 1 and 2MSc Bioinformatics Programming paradigms Imperative Declarative Functional Object-Oriented
Basic C++ lectures 1 and 2MSc Bioinformatics Evolution of High-Level Programming Languages Functions and Methods Libraries (packages, units, etc.) Abstract Data Types Objects
Basic C++ lectures 1 and 2MSc Bioinformatics C++ language History 1980, creation of different flavours of “C with Classes” 1983, C++ evolution from C with inspiration in Simula67 1991, ANSI C++ C++ vs. C C was chosen as the base language for C++ because it: is versatile, terse, and relatively low-level; is adequate for most systems programming tasks; runs everywhere and on everything; and fits into the UNIX programming environment.
Basic C++ lectures 1 and 2MSc Bioinformatics C++ language What is C++? C++ is a general-purpose programming language with a bias towards systems programming that: is a better C, supports data abstraction, supports object-oriented programming, and supports generic programming. C is retained as a subset inside C++ (this is not completely true!)
Basic C++ lectures 1 and 2MSc Bioinformatics C++ language First program (C-style): #include int main() { printf("Hello world!\n"); } ; First program (Pure C++-style): #include int main() { std::cout << "Hello world!\n"; } ;
Basic C++ lectures 1 and 2MSc Bioinformatics Compilation hello.o compile a.out a.exe hello.cpp C++ runtime Link Source FileObject FileExecutable Edit g++ hello.cpp
Basic C++ lectures 1 and 2MSc Bioinformatics C/C++ Compatibility General: C++ provides the // comments // a comment return a; // another comment C Code that is not C++: Functions in C++ have strict syntax main() {} // Valid in C, not valid in C++ int main() {;} // Valid in C++ Default types not assumed const a=7; // In C is type int, not in C++ Several new keywords in C++: class, this, throw, public, protected, private, virtual, true, false, template, inline, friend, new …
Basic C++ lectures 1 and 2MSc Bioinformatics Summary C++ is a evolution of C. We can continue to use C syntax. Formal variations exist. We need to use a different compiler and new file extension. A new programming paradigm is integrated into it.
Basic C++ lectures 1 and 2MSc Bioinformatics Summary The paradigm of Object-Oriented Programming
Basic C++ lectures 1 and 2MSc Bioinformatics OOP: Objective Say to a machine what it need to do (using objects). In general this is programming
Basic C++ lectures 1 and 2MSc Bioinformatics OOP: approach We can view a program as a “object” This object is the medium to do work using a machine A
Basic C++ lectures 1 and 2MSc Bioinformatics OOP: approach Is the Object-Oriented Programming a thing like… Cooking programs with objects?
Basic C++ lectures 1 and 2MSc Bioinformatics OOP: approach Create programs with pieces? Work with programs?
Basic C++ lectures 1 and 2MSc Bioinformatics OOP: concepts Object: a mix of data and procedures Abstraction: view only a partial view of a thing Message interchange: how to object delegates a task to other object Class: the model of the object Instance: one agent (the object) Heritage: How to an object is a “derivate” from another object Polymorphism: Different views of the same object