1 / 18

Basic C++

Basic C++. daniel.soto@upf.edu. Introduction. Daniel Soto. Introduction. Philosophy: learn to program with objects Bibliography. The C++ Programming Language, 3rd Edition by Bjarne Stroustrup. Addison Wesley Professional. http://www.awprofessional.com/title/0201889544.

aitana
Download Presentation

Basic C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic C++ daniel.soto@upf.edu

  2. Introduction Daniel Soto

  3. Introduction • Philosophy: learn to program with objects • Bibliography The C++ Programming Language, 3rd Edition by Bjarne Stroustrup. Addison Wesley Professional. http://www.awprofessional.com/title/0201889544 “Aprenda C++ como si estuviera en primero” http://mat21.etsii.upm.es/ayudainf/aprendainf/Cpp/manualcpp.pdf

  4. Programming Languages C=A+B High-Level Languages LOAD A ADD B STORE C Assembly Languages +1300042774 +1400593419 +1200274027 Machine Languages

  5. Programming paradigms • Imperative • Declarative • Functional • Object-Oriented

  6. Evolution of High-LevelProgramming Languages • Functions and Methods • Libraries (packages, units, etc.) • Abstract Data Types • Objects

  7. 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.

  8. 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!)

  9. C++ language • First program (C-style): #include <stdio.h> int main() { printf("Hello world!\n"); } ; • First program (Pure C++-style): #include <iostream> int main() { std::cout << "Hello world!\n"; } ;

  10. Compilation C++ runtime Edit hello.cpp compile hello.o Link a.out a.exe Source File Object File Executable g++ hello.cpp

  11. 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 …

  12. 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.

  13. Summary • The paradigm of Object-Oriented Programming

  14. OOP: Objective • Say to a machine what it need to do (using objects). • In general this is programming

  15. A OOP: approach • We can view a program as a “object” • This object is the medium to do work using a machine

  16. OOP: approach • Is the Object-Oriented Programming a thing like… • Cooking programs with objects?

  17. OOP: approach • Create programs with pieces? • Work with programs?

  18. 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

More Related