Cours de C++  - Introduction
25 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
25 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

CoursdeC++IntroductionCécile Braunsteincecile.braunstein@lip6.frCours de C++ 1 / 20GénéralitéNotes• Interros cours 1/3• Contrôle TP 1/3• Mini projet 1/3• Bonus (Note de Participation) jusqu’à 2 pointsRéférences• H. GARRETA, Le langage et la bibliothèque C++, ellipses 2000• A. KOENIG, B. MOO, Accelerated C++, Addison Wesley 2006• http://www.cplusplus.com• http://www.google.com• http://www.cppreference.comCours de C++ 2 / 20WhyC++?C++• Middle level language• Developed by Bjarne Stroustrup in 1979 at Bell Labs• First view as an extension of C (C with classes)Philosophy• C++ is designed to be a statically typed, general purposelanguage that is as efficient and portable as C• C++ is designed to give the programmer choice, even if thismakes it possible for the programmer to choose incorrectly• C++ is object language it implies :• Re use• Modularity• MaintainabilityCours de C++ 3 / 20Helloworld!helloworld.cpp// The first programm#include int main(){std::cout << "Hello, world !" << std::endl ;return 0;} Cours de C++ 4 / 20Callthecompilerg++ -Wall -g helloworld.cpp -o hello Compile Optionsg++ accepts most options as gcc• Wall : all warnings• g : include debug code• o : specify the outfile name (a.out by default)Cours de C++ 5 / 206Programdetails#includeMany fundamentals facilities are part of standard library rather thancore language#include #include directive + angle brackets refers to ...

Informations

Publié par
Nombre de lectures 76
Langue English

Extrait

Cours de C++
Cours
de
C++
Introduction
Cécile Braunstein cecile.braunstein@lip6.fr
1 / 20
Généralité
Notes Interros cours Contrôle TP Mini-projet Bonus (Note de Participation)
1/3 1/3 1/3 jusqu’à 2 points
Références H. GARRETA, Le langage et la bibliothèque C++, ellipses 2000 A. KOENIG, B. MOO, Accelerated C++, Addison Wesley 2006 c.www//:sulpsulp.comtpht elc.oggomohttwww.p:// .cceomferpnereww//pc.wtt:ph
Coursde+C+2/02
Why C++ ?
C++ Middle-level language Developed by Bjarne Stroustrup in 1979 at Bell Labs First view as an extension of C (C with classes)
Philosophy C++ is designed to be a statically typed, general-purpose language that is as efficient and portable as C C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly C++ is object language it implies : Re-use Modularity Maintainability
Coursed+C+3/02
Hello world !
helloworld.cpp // The first programm
oCrused
#include<iostream>
intmain() { std::cout<<"Hello,
return0; }
+C+
world
!"
<<
std::endl
;
4/20
Call the compiler
g++ -Wall -g helloworld.cpp
Compile Options g++ accepts most options as gcc
Cou
-o
hello
Wall : all warnings g : include debug code o : specify the outfile name (a.outby default)
srdeC++5/20
Program details
#include Many fundamentals facilities are part ofstandard libraryrather than core language
#include<iostream> ✝ ✆ #includedirective + angle brackets refers tostandard header
main function C++ program must contain a function namedEvery main. When we run the program, the implementation call this function. The result of this function is an integer to tell the implementation if the program ran successfully Convention :
Coursed+C+
0:success| 6=0:fail
6/02
Using the standard library for output
oCu
std::cout<<"Hello, world !"<<std::endl;
< <: output operator std : :: namespacestd std : :cout: standard output stream std : :endl: stream manipulator
sred+C+
7/02
Expressions in C++ Type
A variable is anobjectthat has a name. An object is a part of the memory that has atype. Every object, expression and function has a type. Types specify properties of data and operations on that data.
Primitive types
C
bool char int unsigned long short float double
To improve the code re-use it is important to use the right type at the right place !
oursdeC++8/02
Expressions in C++ Type conversion
Goal: bring the operands to each operator to a common type.
Some basic rules 1Preserve information 2Prefer unsigned conversion
Co
3Promote values to larger type 4Preserve precision
rused+C+9/20
Expressions in C++ Type conversion
Exercice #include<iostream> intmain() { floata = 1.2; floatc; intb;
oC
b = a; a = c;
std::cout<< c <<std::endl; return0; }
rused+C+
#include<iostream> intmain () { intd = -1; unsigned inte = d;
std::cout<< e <<std::endl; return0; }
01/20
Variable definition #include<iostream> #include<string>
intmain() { std::cout <<"Your first name: ";
std::string name; std::cin>> name;
std::cout<<"Hello, " << name <<"!" <<std::endl; return0; }
oCrusde+C+
Variable can be define anywhere in the program. local variableare destroyed when an end of block is reached. Variable has a type and an interface The variablenameis implicitly initialize
How to define a variable type-name name ; type-name name = value ;  ;type-name name(args)
11/20
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents