Programmation - Semestre 1

PART A - Presentation Generale du Cours

Contexte de la formation

La programmation est une competence fondamentale pour tout technicien ou ingenieur en GEII. Elle permet de controler des systemes embarques, automatiser des taches, traiter des donnees et developper des applications. Ce premier module de programmation, dispense en C++, pose les bases de la pensee algorithmique et de la programmation structuree, competences essentielles pour les projets futurs et la vie professionnelle.

Positionnement dans le cursus

  • Semestre : S1 (1ere annee DUT GEII)
  • Volume horaire : 60h (20h CM + 25h TD + 15h TP)
  • Credits ECTS : 5
  • Prerequis : Aucun prerequis en programmation (debutants acceptes)
  • Continuite : Programmation S2 (C/C++ avance), puis S3-S4 (embarque, Python)

Public vise

Etudiants de premiere annee DUT GEII, debutants ou ayant quelques notions en programmation. Le cours s'adresse a tous les profils, avec une pedagogie progressive permettant a chacun de reussir.


PART B: EXPERIENCE, CONTEXTE ET FONCTION

Objectifs pedagogiques

Competences algorithmiques :

  • Analyser un probleme et le decomposer en etapes
  • Concevoir des algorithmes structures et efficaces
  • Evaluer la complexite d'un algorithme
  • Deboguer et tester son code

Competences techniques C++ :

  • Maitriser la syntaxe de base du C++
  • Utiliser les structures de controle (conditions, boucles)
  • Manipuler les tableaux et les chaines de caracteres
  • Creer et utiliser des fonctions
  • Comprendre et utiliser les pointeurs (introduction)

Competences methodologiques :

  • Utiliser un environnement de developpement (IDE)
  • Compiler et executer un programme
  • Deboguer avec des outils appropries
  • Documenter son code
  • Travailler en mode projet

Programme detaille

1. Introduction a la programmation (5h)

Concepts fondamentaux :

  • Qu'est-ce qu'un programme ? Un algorithme ?
  • Langages de programmation (compiles vs interpretes)
  • Processus de compilation (source → compilation → executable)
  • Structure d'un programme C++

Premier programme "Hello World" :

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    return 0;
}

Elements de syntaxe :

  • Directives du preprocesseur (#include)
  • Fonction main()
  • Instructions et point-virgule
  • Entrees/sorties (cin, cout)
  • Commentaires (// et /* */)

2. Variables et types de donnees (8h)

Types de base (primitifs) :

int age = 20;              // Entier signe (4 octets)
unsigned int count = 100;  // Entier non signe
float temperature = 25.5;  // Flottant simple precision
double pi = 3.14159265359; // Flottant double precision
char letter = 'A';         // Caractere (1 octet)
bool isValid = true;       // Booleen (true/false)

Declaration et initialisation :

  • Declaration : int x;
  • Initialisation : int x = 10;
  • Affectation : x = 20;
  • Constantes : const double PI = 3.14159;

Operateurs :

  • Arithmetiques : +, -, *, /, % (modulo)
  • Comparaison : ==, !=, <, >, <=, >=
  • Logiques : && (AND), || (OR), ! (NOT)
  • Incrementation : ++, --
  • Affectation composee : +=, -=, *=, /=

Conversions de types (cast) :

int a = 10;
float b = 3.7;
int result = a + (int)b;  // Cast explicite
float average = (float)a / 3;  // Division flottante

Entrees/sorties utilisateur :

int age;
cout << "Entrez votre age : ";
cin >> age;
cout << "Vous avez " << age << " ans" << endl;

3. Structures de controle (10h)

Instructions conditionnelles :

if / else if / else :

if (temperature > 30) {
    cout << "Il fait chaud" << endl;
}
else if (temperature > 20) {
    cout << "Il fait bon" << endl;
}
else {
    cout << "Il fait froid" << endl;
}

Operateur ternaire :

int max = (a > b) ? a : b;  // Si a>b alors max=a sinon max=b

Switch / case :

int choice;
cin >> choice;

switch (choice) {
    case 1:
        cout << "Option 1" << endl;
        break;
    case 2:
        cout << "Option 2" << endl;
        break;
    default:
        cout << "Option invalide" << endl;
}

Boucles :

Boucle for (nombre d'iterations connu) :

// Afficher les nombres de 1 a 10
for (int i = 1; i <= 10; i++) {
    cout << i << " ";
}

Boucle while (condition en entree) :

int i = 1;
while (i <= 10) {
    cout << i << " ";
    i++;
}

Boucle do-while (condition en sortie, au moins 1 iteration) :

int number;
do {
    cout << "Entrez un nombre positif : ";
    cin >> number;
} while (number <= 0);

break et continue :

for (int i = 0; i < 10; i++) {
    if (i == 5) continue;  // Passer a l'iteration suivante
    if (i == 8) break;     // Sortir de la boucle
    cout << i << " ";
}
// Affiche : 0 1 2 3 4 6 7

4. Tableaux et chaines de caracteres (10h)

Tableaux statiques (arrays) :

// Declaration et initialisation
int notes[5] = {12, 15, 10, 18, 14};

// Acces aux elements (index commence a 0)
cout << "Premiere note : " << notes[0] << endl;
notes[2] = 16;  // Modification

// Parcours avec boucle
float somme = 0;
for (int i = 0; i < 5; i++) {
    somme += notes[i];
}
float moyenne = somme / 5;

Tableaux multidimensionnels :

int matrice[3][4] = {
    {1, 2, 3, 4},
    {5, 6, 7, 8},
    {9, 10, 11, 12}
};

// Parcours avec boucles imbriquees
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
        cout << matrice[i][j] << " ";
    }
    cout << endl;
}

Chaines de caracteres (C-style strings) :

char nom[50];
cout << "Entrez votre nom : ";
cin >> nom;

// Fonctions de <cstring>
#include <cstring>
strlen(nom);        // Longueur
strcpy(dest, src);  // Copie
strcat(s1, s2);     // Concatenation
strcmp(s1, s2);      // Comparaison (0 si egales)

Chaines C++ (std::string) :

#include <string>

string prenom = "Jean";
string nom = "Dupont";
string complet = prenom + " " + nom;  // Concatenation

cout << complet.length() << endl;  // Longueur
cout << complet[0] << endl;        // Premier caractere
complet += " Jr.";                 // Ajout a la fin

5. Fonctions (12h)

Declaration et definition :

// Declaration (prototype)
int addition(int a, int b);

// Definition
int addition(int a, int b) {
    return a + b;
}

// Utilisation
int main() {
    int resultat = addition(5, 3);
    cout << "5 + 3 = " << resultat << endl;
    return 0;
}

Passage de parametres :

Par valeur (copie) :

void incrementer(int x) {
    x++;  // Modification locale, pas d'effet sur l'original
}

int main() {
    int a = 5;
    incrementer(a);
    cout << a << endl;  // Affiche 5 (inchange)
}

Par reference (modification de l'original) :

void incrementer(int& x) {  // Notez le &
    x++;  // Modifie l'original
}

int main() {
    int a = 5;
    incrementer(a);
    cout << a << endl;  // Affiche 6
}

Fonctions void (sans retour) :

void afficherMessage() {
    cout << "Bonjour !" << endl;
    // Pas de return (ou return; sans valeur)
}

Surcharge de fonctions (overloading) :

int addition(int a, int b) {
    return a + b;
}

double addition(double a, double b) {
    return a + b;
}

// Le compilateur choisit selon les types des arguments

Valeurs par defaut :

void afficher(string texte, int repetitions = 1) {
    for (int i = 0; i < repetitions; i++) {
        cout << texte << endl;
    }
}

afficher("Bonjour");      // Utilise 1 par defaut
afficher("Bonjour", 3);   // Affiche 3 fois

6. Structures (struct) (8h)

Definition et utilisation :

struct Point {
    double x;
    double y;
};

int main() {
    Point p1;
    p1.x = 10.5;
    p1.y = 20.3;

    Point p2 = {5.0, 7.0};  // Initialisation

    cout << "Point 1 : (" << p1.x << ", " << p1.y << ")" << endl;
}

Structures imbriquees :

struct Adresse {
    string rue;
    int codePostal;
    string ville;
};

struct Personne {
    string nom;
    int age;
    Adresse adresse;
};

Personne p;
p.nom = "Dupont";
p.adresse.ville = "Toulouse";

Tableaux de structures :

struct Etudiant {
    string nom;
    float moyenne;
};

Etudiant classe[30];
classe[0].nom = "Alice";
classe[0].moyenne = 15.5;

7. Introduction aux pointeurs (7h)

Concept de pointeur :

int x = 10;
int* ptr = &x;  // ptr contient l'adresse de x

cout << "Valeur de x : " << x << endl;
cout << "Adresse de x : " << &x << endl;
cout << "Valeur de ptr : " << ptr << endl;
cout << "Valeur pointee : " << *ptr << endl;  // Dereferencement

Modification via pointeur :

int a = 5;
int* p = &a;
*p = 10;  // a vaut maintenant 10

Pointeurs et tableaux :

int tab[5] = {10, 20, 30, 40, 50};
int* p = tab;  // Pointeur sur le premier element

for (int i = 0; i < 5; i++) {
    cout << *(p + i) << " ";  // Acces par arithmetique de pointeurs
}

Pointeurs et fonctions :

void echanger(int* a, int* b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main() {
    int x = 5, y = 10;
    echanger(&x, &y);
    cout << "x = " << x << ", y = " << y << endl;  // x=10, y=5
}

Semaine intensive de programmation

Projet integratif (40h sur 1 semaine) :

Realisation d'un projet complet mobilisant toutes les competences :

  • Analyse et decomposition du probleme
  • Conception de l'algorithme (organigramme ou pseudo-code)
  • Implementation en C++
  • Tests et debogage
  • Documentation et presentation

Exemples de projets :

  1. Jeu du pendu : Gestion de chaines, structures de controle
  2. Gestion de contacts : Tableaux de structures, fichiers
  3. Calculatrice scientifique : Fonctions mathematiques, switch/case
  4. Jeu de la vie (Conway) : Tableaux 2D, algorithmique
  5. Gestionnaire de notes : Calculs statistiques, tri

Organisation :

  • Travail en binome
  • Suivi quotidien par les enseignants
  • Presentation finale (demo + code)
  • Rapport technique

PART C: ASPECTS TECHNIQUES

Environnements de developpement (IDE)

Code::Blocks (recommande pour debutants)

Installation :

  • Telecharger sur codeblocks.org
  • Version avec MinGW (compilateur GCC inclus)
  • Configuration automatique

Fonctionnalites :

  • Coloration syntaxique
  • Auto-completion
  • Compilation en un clic (F9)
  • Debogueur integre
  • Gestion de projets

Creation d'un projet :

  1. File → New → Project → Console Application
  2. Choisir C++
  3. Nommer le projet et choisir l'emplacement
  4. Code genere automatiquement

Visual Studio (Windows)

Avantages :

  • IDE professionnel puissant
  • Excellent debogueur
  • IntelliSense (auto-completion avancee)
  • Outils de profilage

Creation d'un projet :

  • File → New → Project → Empty Project (C++)
  • Ajouter un fichier .cpp
  • Build → Build Solution (Ctrl+Shift+B)
  • Debug → Start Debugging (F5)

VS Code (multiplateforme)

Configuration pour C++ :

  1. Installer VS Code
  2. Installer extension "C/C++"
  3. Installer MinGW (Windows) ou GCC (Linux/Mac)
  4. Configurer tasks.json pour compilation

Avantages :

  • Leger et rapide
  • Tres personnalisable
  • Extensions nombreuses
  • Integration Git native

Compilation et debogage

Processus de compilation

Etapes :

Code source (.cpp) → Preprocesseur → Compilateur →
Assembleur → Linker → Executable (.exe ou binaire)

Compilation en ligne de commande :

# Compilation simple
g++ programme.cpp -o programme

# Avec warnings et optimisation
g++ -Wall -Wextra -O2 programme.cpp -o programme

# Avec informations de debug
g++ -g programme.cpp -o programme

# Execution
./programme  # Linux/Mac
programme.exe  # Windows

Debogage avec GDB

Commandes de base :

gdb ./programme

(gdb) break main       # Point d'arret sur main
(gdb) run             # Lancer le programme
(gdb) next            # Ligne suivante (sans entrer dans fonctions)
(gdb) step            # Ligne suivante (en entrant dans fonctions)
(gdb) print variable  # Afficher valeur d'une variable
(gdb) continue        # Continuer jusqu'au prochain breakpoint
(gdb) quit            # Quitter GDB

Debogage dans IDE :

  • Placer des breakpoints (clic marge gauche)
  • F5 : Lancer en mode debug
  • F10 : Passer a la ligne suivante
  • F11 : Entrer dans une fonction
  • Inspecter les variables dans la fenetre "Watch"

Bonnes pratiques de programmation

Style et conventions

Nommage :

// Variables : camelCase ou snake_case
int nombreEtudiants;  // camelCase
int nombre_etudiants;  // snake_case

// Constantes : MAJUSCULES
const int MAX_SIZE = 100;

// Fonctions : verbes d'action
void calculerMoyenne();
bool estPair(int n);

// Noms explicites (pas de x, y, z sauf cas mathematiques)
int age;  // Bien
int a;    // A eviter (sauf contexte clair)

Indentation et lisibilite :

// Mauvais
if(a>b){cout<<a;}else{cout<<b;}

// Bon
if (a > b) {
    cout << a << endl;
} else {
    cout << b << endl;
}

Commentaires :

// Commentaire ligne simple

/*
 * Commentaire
 * multi-lignes
 */

/**
 * Documentation fonction (style Doxygen)
 * @param rayon : rayon du cercle
 * @return surface du cercle
 */
double surfaceCercle(double rayon) {
    return 3.14159 * rayon * rayon;
}

Gestion des erreurs

Validation des entrees :

int age;
cout << "Entrez votre age : ";
cin >> age;

if (cin.fail()) {
    cout << "Erreur : entree invalide" << endl;
    cin.clear();  // Reinitialiser le flux
    cin.ignore(1000, '\n');  // Vider le buffer
}

if (age < 0 || age > 150) {
    cout << "Erreur : age non valide" << endl;
}

Tests et assertions :

#include <cassert>

assert(diviseur != 0);  // Arrete le programme si faux (mode debug)

PART D: ANALYSE ET REFLEXION

Evaluation des competences

Modalites d'evaluation

Controle continu (40%) :

  • QCM theoriques (2 dans le semestre) - 10%
  • Tests pratiques sur machine (2x1h) - 30%

Travaux pratiques (30%) :

  • 8 TP notes
  • Evaluation : code fonctionnel, methodologie, documentation
  • Presence obligatoire

Projet semaine intensive (20%) :

  • Code source commente
  • Fonctionnalites implementees
  • Presentation et demo
  • Rapport technique

Examen terminal (10%) :

  • Epreuve theorique (1h)
  • Questions de cours, analyse de code, algorithmique

Grille d'evaluation TP (exemple)

CritereDetailPoints
FonctionnalitesProgramme compile et s'execute/4
CorrectionResultats conformes aux attendus/6
AlgorithmiqueLogique et efficacite de l'algorithme/4
StyleLisibilite, nommage, commentaires/3
TestsCas limites testes/2
DocumentationExplications claires/1
Total/20

Competences acquises

Savoirs theoriques

  • Comprendre les concepts de la programmation structuree
  • Connaitre la syntaxe et les structures du langage C++
  • Maitriser l'algorithmique de base
  • Comprendre la notion de complexite algorithmique

Savoir-faire techniques

  • Ecrire, compiler et executer un programme C++
  • Utiliser un IDE et des outils de debogage
  • Concevoir des algorithmes structures
  • Manipuler tableaux, fonctions, structures
  • Deboguer et tester son code
  • Documenter son travail

Savoir-etre

  • Rigueur et methode dans la resolution de problemes
  • Autonomie dans l'apprentissage
  • Perseverance face aux bugs
  • Travail en equipe sur des projets
  • Curiosite et veille technologique

Progression et liens avec le cursus

Suite du parcours Programmation

SemestreModuleLangageContenu
S1Programmation 1C++Bases, structures, fonctions
S2Programmation 2C/C++Pointeurs avances, allocation dynamique, POO
S3Informatique EmbarqueeCProgrammation microcontroleurs (Arduino, STM32)
S4Python / Outils logicielsPythonScripts, traitement donnees, automatisation

Liens avec les autres matieres

MatiereUtilisation de la programmation
Systemes Numeriques (SIN)Simulations VHDL, scripts de test
Informatique EmbarqueeProgrammation microcontroleurs en C
AutomatiqueImplementation regulateurs, simulations
Traitement du SignalAlgorithmes de filtrage numerique
MathematiquesCalculs numeriques, resolution d'equations
ProjetsDeveloppement logiciel des prototypes

Indicateurs de reussite

Statistiques

Taux de reussite : 90% (moyenne ≥ 10/20)
Moyenne generale : 13/20

Profils d'etudiants :

  • Debutants complets : 60%
  • Ayant fait de la programmation au lycee (NSI, ISN) : 30%
  • Ayant programme en autonomie : 10%

Difficultes frequentes

Problemes courants :

  • Confusion entre = (affectation) et == (comparaison)
  • Oublier les accolades {} ou points-virgules ;
  • Boucles infinies (condition mal formulee)
  • Depassement d'indices de tableaux
  • Oubli du & dans passage par reference
  • Confusion pointeurs/valeurs

Solutions et conseils :

  • Compiler frequemment (eviter d'accumuler les erreurs)
  • Utiliser le debogueur au lieu de cout partout
  • Dessiner les structures de donnees sur papier
  • Tester avec des cas simples d'abord
  • Commenter son code au fur et a mesure
  • Refaire les TP chez soi

Debouches et applications

Applications professionnelles

Metiers utilisant le C/C++ :

  • Developpeur embarque (IoT, automobile, aeronautique)
  • Programmeur de microcontroleurs
  • Developpeur systemes temps reel
  • Automaticien (interfaces, supervision)
  • Developpeur logiciel industriel

Industries :

  • Electronique grand public
  • Automobile (systemes embarques)
  • Aeronautique et spatial
  • Robotique
  • Automatisation industrielle
  • Telecommunications

Ressources complementaires

Ouvrages de reference

Pour debutants :

  1. Programmer en langage C++ - Claude Delannoy (Eyrolles) - LE classique francais
  2. C++ pour les Nuls - Stephen Randy Davis (First)
  3. Apprendre la programmation - Sebastien Rohaut (Eyrolles)

Pour approfondir :

  • The C++ Programming Language - Bjarne Stroustrup (createur du C++)
  • Effective C++ - Scott Meyers (bonnes pratiques)

Sites web et tutoriels

Cours en ligne (gratuits) :

  • OpenClassrooms : Cours C++ tres complet en francais
  • Codecademy : Exercices interactifs
  • SoloLearn : Application mobile ludique
  • cplusplus.com : Documentation complete + tutoriels

References C++ :

  • cppreference.com : Documentation officielle
  • Stack Overflow : Forum Q&A (chercher avant de poster)

Exercices en ligne :

  • France-IOI : Exercices progressifs d'algorithmique
  • CodinGame : Apprendre en jouant
  • HackerRank / LeetCode : Defis algorithmiques
  • Project Euler : Problemes mathematiques a resoudre par programmation

Outils en ligne

Compilateurs en ligne (pour tester rapidement) :

  • OnlineGDB (onlinegdb.com) : IDE complet dans le navigateur
  • Compiler Explorer (godbolt.org) : Voir le code assembleur genere
  • Repl.it : Environnement collaboratif

Visualisation d'algorithmes :

  • PythonTutor (pythontutor.com) : Visualiser l'execution pas a pas
  • VisuAlgo : Animations d'algorithmes (tri, recherche, graphes)

Conseils methodologiques

Pour reussir en programmation

Pendant les cours/TD :

  • Taper le code soi-meme (ne pas juste regarder)
  • Experimenter : modifier le code pour voir ce qui se passe
  • Poser des questions immediatement
  • Noter les erreurs frequentes et comment les corriger

En TP :

  • Lire entierement le sujet avant de commencer
  • Decomposer le probleme en petites etapes
  • Tester chaque fonction individuellement
  • Compiler souvent (toutes les 5-10 lignes)
  • Demander de l'aide si bloque >15 min

Travail personnel (3-4h/semaine recommandees) :

  • Refaire les exercices de TD sans regarder la correction
  • Creer ses propres petits programmes
  • Lire des codes d'autres personnes (GitHub, forums)
  • Participer a des defis (CodinGame, HackerRank)

Methodologie de resolution de problemes

Etapes systematiques :

  1. Comprendre : Lire et reformuler le probleme
  2. Decomposer : Identifier les sous-problemes
  3. Algorithme : Ecrire en pseudo-code ou organigramme
  4. Coder : Traduire en C++
  5. Tester : Cas normaux, limites, erreurs
  6. Deboguer : Si ca ne marche pas, identifier l'erreur
  7. Optimiser : Ameliorer si necessaire

Exemple : Calculer la moyenne d'un tableau

1. Comprendre : Somme des elements / nombre d'elements
2. Decomposer :
   - Parcourir le tableau
   - Additionner les valeurs
   - Diviser par la taille
3. Pseudo-code :
   somme = 0
   POUR chaque element du tableau
       somme = somme + element
   moyenne = somme / taille
4. Coder en C++
5. Tester avec {10, 15, 20} -> moyenne = 15

Bienvenue dans le monde de la programmation !

"Everybody should learn to program a computer, because it teaches you how to think." - Steve Jobs

N'ayez pas peur de faire des erreurs : les bugs font partie de l'apprentissage. Chaque erreur corrigee est une lecon apprise !

Ressources complementaires

  • Documentation C++ standard
  • Exercices en ligne (France-IOI, CodinGame)
  • Livres de reference sur le C++

Programming - Semester 1

PART A - General Course Overview

Training context

Programming is a fundamental skill for any technician or engineer in GEII (Electrical Engineering and Industrial Computing). It enables the control of embedded systems, task automation, data processing, and application development. This first programming module, taught in C++, lays the foundations of algorithmic thinking and structured programming -- essential skills for future projects and professional life.

Position in the curriculum

  • Semester: S1 (1st year DUT GEII)
  • Course hours: 60h (20h lectures + 25h tutorials + 15h practical work)
  • ECTS credits: 5
  • Prerequisites: No prior programming experience required (beginners welcome)
  • Continuation: Programming S2 (advanced C/C++), then S3-S4 (embedded, Python)

Target audience

First-year DUT GEII students, beginners or with some programming knowledge. The course is designed for all profiles, with a progressive pedagogy enabling everyone to succeed.


PART B: EXPERIENCE, CONTEXT AND FUNCTION

Learning objectives

Algorithmic skills:

  • Analyze a problem and break it down into steps
  • Design structured and efficient algorithms
  • Evaluate algorithm complexity
  • Debug and test code

C++ technical skills:

  • Master the basic syntax of C++
  • Use control structures (conditions, loops)
  • Handle arrays and character strings
  • Create and use functions
  • Understand and use pointers (introduction)

Methodological skills:

  • Use a development environment (IDE)
  • Compile and run a program
  • Debug with appropriate tools
  • Document code
  • Work in project mode

Detailed program

1. Introduction to programming (5h)

Fundamental concepts:

  • What is a program? An algorithm?
  • Programming languages (compiled vs interpreted)
  • Compilation process (source → compilation → executable)
  • Structure of a C++ program

First "Hello World" program:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    return 0;
}

Syntax elements:

  • Preprocessor directives (#include)
  • The main() function
  • Statements and semicolons
  • Input/output (cin, cout)
  • Comments (// and /* */)

2. Variables and data types (8h)

Basic (primitive) types:

int age = 20;              // Signed integer (4 bytes)
unsigned int count = 100;  // Unsigned integer
float temperature = 25.5;  // Single precision float
double pi = 3.14159265359; // Double precision float
char letter = 'A';         // Character (1 byte)
bool isValid = true;       // Boolean (true/false)

Declaration and initialization:

  • Declaration: int x;
  • Initialization: int x = 10;
  • Assignment: x = 20;
  • Constants: const double PI = 3.14159;

Operators:

  • Arithmetic: +, -, *, /, % (modulo)
  • Comparison: ==, !=, <, >, <=, >=
  • Logical: && (AND), || (OR), ! (NOT)
  • Increment: ++, --
  • Compound assignment: +=, -=, *=, /=

Type conversions (cast):

int a = 10;
float b = 3.7;
int result = a + (int)b;  // Explicit cast
float average = (float)a / 3;  // Floating-point division

User input/output:

int age;
cout << "Enter your age: ";
cin >> age;
cout << "You are " << age << " years old" << endl;

3. Control structures (10h)

Conditional statements:

if / else if / else:

if (temperature > 30) {
    cout << "It's hot" << endl;
}
else if (temperature > 20) {
    cout << "It's nice" << endl;
}
else {
    cout << "It's cold" << endl;
}

Ternary operator:

int max = (a > b) ? a : b;  // If a>b then max=a else max=b

Switch / case:

int choice;
cin >> choice;

switch (choice) {
    case 1:
        cout << "Option 1" << endl;
        break;
    case 2:
        cout << "Option 2" << endl;
        break;
    default:
        cout << "Invalid option" << endl;
}

Loops:

for loop (known number of iterations):

// Display numbers from 1 to 10
for (int i = 1; i <= 10; i++) {
    cout << i << " ";
}

while loop (entry condition):

int i = 1;
while (i <= 10) {
    cout << i << " ";
    i++;
}

do-while loop (exit condition, at least 1 iteration):

int number;
do {
    cout << "Enter a positive number: ";
    cin >> number;
} while (number <= 0);

break and continue:

for (int i = 0; i < 10; i++) {
    if (i == 5) continue;  // Skip to next iteration
    if (i == 8) break;     // Exit the loop
    cout << i << " ";
}
// Prints: 0 1 2 3 4 6 7

4. Arrays and character strings (10h)

Static arrays:

// Declaration and initialization
int grades[5] = {12, 15, 10, 18, 14};

// Accessing elements (index starts at 0)
cout << "First grade: " << grades[0] << endl;
grades[2] = 16;  // Modification

// Traversal with loop
float sum = 0;
for (int i = 0; i < 5; i++) {
    sum += grades[i];
}
float average = sum / 5;

Multidimensional arrays:

int matrix[3][4] = {
    {1, 2, 3, 4},
    {5, 6, 7, 8},
    {9, 10, 11, 12}
};

// Traversal with nested loops
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
        cout << matrix[i][j] << " ";
    }
    cout << endl;
}

Character strings (C-style strings):

char name[50];
cout << "Enter your name: ";
cin >> name;

// Functions from <cstring>
#include <cstring>
strlen(name);       // Length
strcpy(dest, src);  // Copy
strcat(s1, s2);     // Concatenation
strcmp(s1, s2);      // Comparison (0 if equal)

C++ strings (std::string):

#include <string>

string firstName = "Jean";
string lastName = "Dupont";
string fullName = firstName + " " + lastName;  // Concatenation

cout << fullName.length() << endl;  // Length
cout << fullName[0] << endl;        // First character
fullName += " Jr.";                  // Append

5. Functions (12h)

Declaration and definition:

// Declaration (prototype)
int addition(int a, int b);

// Definition
int addition(int a, int b) {
    return a + b;
}

// Usage
int main() {
    int result = addition(5, 3);
    cout << "5 + 3 = " << result << endl;
    return 0;
}

Parameter passing:

By value (copy):

void increment(int x) {
    x++;  // Local modification, no effect on original
}

int main() {
    int a = 5;
    increment(a);
    cout << a << endl;  // Prints 5 (unchanged)
}

By reference (modifies original):

void increment(int& x) {  // Note the &
    x++;  // Modifies the original
}

int main() {
    int a = 5;
    increment(a);
    cout << a << endl;  // Prints 6
}

Void functions (no return value):

void displayMessage() {
    cout << "Hello!" << endl;
    // No return (or return; without value)
}

Function overloading:

int addition(int a, int b) {
    return a + b;
}

double addition(double a, double b) {
    return a + b;
}

// The compiler chooses based on argument types

Default values:

void display(string text, int repetitions = 1) {
    for (int i = 0; i < repetitions; i++) {
        cout << text << endl;
    }
}

display("Hello");       // Uses default value of 1
display("Hello", 3);    // Prints 3 times

6. Structures (struct) (8h)

Definition and usage:

struct Point {
    double x;
    double y;
};

int main() {
    Point p1;
    p1.x = 10.5;
    p1.y = 20.3;

    Point p2 = {5.0, 7.0};  // Initialization

    cout << "Point 1: (" << p1.x << ", " << p1.y << ")" << endl;
}

Nested structures:

struct Address {
    string street;
    int zipCode;
    string city;
};

struct Person {
    string name;
    int age;
    Address address;
};

Person p;
p.name = "Dupont";
p.address.city = "Toulouse";

Arrays of structures:

struct Student {
    string name;
    float average;
};

Student classroom[30];
classroom[0].name = "Alice";
classroom[0].average = 15.5;

7. Introduction to pointers (7h)

Pointer concept:

int x = 10;
int* ptr = &x;  // ptr holds the address of x

cout << "Value of x: " << x << endl;
cout << "Address of x: " << &x << endl;
cout << "Value of ptr: " << ptr << endl;
cout << "Pointed value: " << *ptr << endl;  // Dereferencing

Modification via pointer:

int a = 5;
int* p = &a;
*p = 10;  // a is now 10

Pointers and arrays:

int tab[5] = {10, 20, 30, 40, 50};
int* p = tab;  // Pointer to the first element

for (int i = 0; i < 5; i++) {
    cout << *(p + i) << " ";  // Access via pointer arithmetic
}

Pointers and functions:

void swap(int* a, int* b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main() {
    int x = 5, y = 10;
    swap(&x, &y);
    cout << "x = " << x << ", y = " << y << endl;  // x=10, y=5
}

Intensive programming week

Integrative project (40h over 1 week):

Completion of a full project using all acquired skills:

  • Problem analysis and decomposition
  • Algorithm design (flowchart or pseudo-code)
  • Implementation in C++
  • Testing and debugging
  • Documentation and presentation

Project examples:

  1. Hangman game: String handling, control structures
  2. Contact manager: Arrays of structures, files
  3. Scientific calculator: Mathematical functions, switch/case
  4. Game of Life (Conway): 2D arrays, algorithms
  5. Grade manager: Statistical calculations, sorting

Organization:

  • Work in pairs
  • Daily follow-up by instructors
  • Final presentation (demo + code)
  • Technical report

PART C: TECHNICAL ASPECTS

Development environments (IDE)

Code::Blocks (recommended for beginners)

Installation:

  • Download from codeblocks.org
  • Version with MinGW (GCC compiler included)
  • Automatic configuration

Features:

  • Syntax highlighting
  • Auto-completion
  • One-click compilation (F9)
  • Integrated debugger
  • Project management

Creating a project:

  1. File → New → Project → Console Application
  2. Choose C++
  3. Name the project and choose location
  4. Code generated automatically

Visual Studio (Windows)

Advantages:

  • Powerful professional IDE
  • Excellent debugger
  • IntelliSense (advanced auto-completion)
  • Profiling tools

Creating a project:

  • File → New → Project → Empty Project (C++)
  • Add a .cpp file
  • Build → Build Solution (Ctrl+Shift+B)
  • Debug → Start Debugging (F5)

VS Code (cross-platform)

Configuration for C++:

  1. Install VS Code
  2. Install "C/C++" extension
  3. Install MinGW (Windows) or GCC (Linux/Mac)
  4. Configure tasks.json for compilation

Advantages:

  • Lightweight and fast
  • Highly customizable
  • Numerous extensions
  • Native Git integration

Compilation and debugging

Compilation process

Steps:

Source code (.cpp) → Preprocessor → Compiler →
Assembler → Linker → Executable (.exe or binary)

Command-line compilation:

# Simple compilation
g++ program.cpp -o program

# With warnings and optimization
g++ -Wall -Wextra -O2 program.cpp -o program

# With debug information
g++ -g program.cpp -o program

# Execution
./program    # Linux/Mac
program.exe  # Windows

Debugging with GDB

Basic commands:

gdb ./program

(gdb) break main       # Breakpoint on main
(gdb) run             # Run the program
(gdb) next            # Next line (without entering functions)
(gdb) step            # Next line (entering functions)
(gdb) print variable  # Display variable value
(gdb) continue        # Continue to next breakpoint
(gdb) quit            # Quit GDB

Debugging in IDE:

  • Place breakpoints (click left margin)
  • F5: Launch in debug mode
  • F10: Step over to next line
  • F11: Step into a function
  • Inspect variables in the "Watch" window

Programming best practices

Style and conventions

Naming:

// Variables: camelCase or snake_case
int studentCount;      // camelCase
int student_count;     // snake_case

// Constants: UPPERCASE
const int MAX_SIZE = 100;

// Functions: action verbs
void calculateAverage();
bool isEven(int n);

// Explicit names (avoid x, y, z except for mathematical context)
int age;  // Good
int a;    // Avoid (unless context is clear)

Indentation and readability:

// Bad
if(a>b){cout<<a;}else{cout<<b;}

// Good
if (a > b) {
    cout << a << endl;
} else {
    cout << b << endl;
}

Comments:

// Single-line comment

/*
 * Multi-line
 * comment
 */

/**
 * Function documentation (Doxygen style)
 * @param radius: radius of the circle
 * @return area of the circle
 */
double circleArea(double radius) {
    return 3.14159 * radius * radius;
}

Error handling

Input validation:

int age;
cout << "Enter your age: ";
cin >> age;

if (cin.fail()) {
    cout << "Error: invalid input" << endl;
    cin.clear();  // Reset the stream
    cin.ignore(1000, '\n');  // Clear the buffer
}

if (age < 0 || age > 150) {
    cout << "Error: invalid age" << endl;
}

Tests and assertions:

#include <cassert>

assert(divisor != 0);  // Stops the program if false (debug mode)

PART D: ANALYSIS AND REFLECTION

Skills assessment

Assessment methods

Continuous assessment (40%):

  • Theoretical quizzes (2 per semester) - 10%
  • Practical computer tests (2x1h) - 30%

Practical work (30%):

  • 8 graded lab sessions
  • Evaluation: working code, methodology, documentation
  • Mandatory attendance

Intensive week project (20%):

  • Commented source code
  • Implemented features
  • Presentation and demo
  • Technical report

Final exam (10%):

  • Theoretical test (1h)
  • Course questions, code analysis, algorithms

Lab grading rubric (example)

CriterionDetailPoints
FeaturesProgram compiles and runs/4
CorrectnessResults match expectations/6
AlgorithmsLogic and efficiency of algorithm/4
StyleReadability, naming, comments/3
TestingEdge cases tested/2
DocumentationClear explanations/1
Total/20

Skills acquired

Theoretical knowledge

  • Understand structured programming concepts
  • Know the syntax and structures of the C++ language
  • Master basic algorithms
  • Understand the notion of algorithmic complexity

Technical know-how

  • Write, compile and run a C++ program
  • Use an IDE and debugging tools
  • Design structured algorithms
  • Handle arrays, functions, structures
  • Debug and test code
  • Document work

Soft skills

  • Rigor and method in problem solving
  • Self-directed learning
  • Perseverance when facing bugs
  • Teamwork on projects
  • Curiosity and technology watch

Progression and links with the curriculum

Programming pathway

SemesterModuleLanguageContent
S1Programming 1C++Basics, structures, functions
S2Programming 2C/C++Advanced pointers, dynamic allocation, OOP
S3Embedded ComputingCMicrocontroller programming (Arduino, STM32)
S4Python / Software ToolsPythonScripts, data processing, automation

Links with other subjects

SubjectUse of programming
Digital Systems (SIN)VHDL simulations, test scripts
Embedded ComputingMicrocontroller programming in C
Control SystemsController implementation, simulations
Signal ProcessingDigital filtering algorithms
MathematicsNumerical calculations, equation solving
ProjectsPrototype software development

Success indicators

Statistics

Pass rate: 90% (average ≥ 10/20)
Overall average: 13/20

Student profiles:

  • Complete beginners: 60%
  • With high school programming experience (NSI, ISN): 30%
  • Self-taught programmers: 10%

Common difficulties

Frequent issues:

  • Confusion between = (assignment) and == (comparison)
  • Forgetting braces {} or semicolons ;
  • Infinite loops (poorly formulated condition)
  • Array index out of bounds
  • Forgetting the & in pass by reference
  • Pointer/value confusion

Solutions and tips:

  • Compile frequently (avoid accumulating errors)
  • Use the debugger instead of cout everywhere
  • Draw data structures on paper
  • Test with simple cases first
  • Comment code as you go
  • Redo lab exercises at home

Career opportunities and applications

Professional applications

Careers using C/C++:

  • Embedded developer (IoT, automotive, aerospace)
  • Microcontroller programmer
  • Real-time systems developer
  • Automation engineer (interfaces, supervision)
  • Industrial software developer

Industries:

  • Consumer electronics
  • Automotive (embedded systems)
  • Aerospace and space
  • Robotics
  • Industrial automation
  • Telecommunications

Additional resources

Reference books

For beginners:

  1. Programmer en langage C++ - Claude Delannoy (Eyrolles) - THE French classic
  2. C++ for Dummies - Stephen Randy Davis (First)
  3. Apprendre la programmation - Sebastien Rohaut (Eyrolles)

For deeper study:

  • The C++ Programming Language - Bjarne Stroustrup (creator of C++)
  • Effective C++ - Scott Meyers (best practices)

Websites and tutorials

Online courses (free):

  • OpenClassrooms: Comprehensive C++ course in French
  • Codecademy: Interactive exercises
  • SoloLearn: Fun mobile application
  • cplusplus.com: Complete documentation + tutorials

C++ references:

  • cppreference.com: Official documentation
  • Stack Overflow: Q&A forum (search before posting)

Online exercises:

  • France-IOI: Progressive algorithm exercises
  • CodinGame: Learn by playing
  • HackerRank / LeetCode: Algorithm challenges
  • Project Euler: Mathematical problems to solve through programming

Online tools

Online compilers (for quick testing):

  • OnlineGDB (onlinegdb.com): Full IDE in the browser
  • Compiler Explorer (godbolt.org): View generated assembly code
  • Repl.it: Collaborative environment

Algorithm visualization:

  • PythonTutor (pythontutor.com): Visualize step-by-step execution
  • VisuAlgo: Algorithm animations (sorting, searching, graphs)

Methodological tips

How to succeed in programming

During lectures/tutorials:

  • Type the code yourself (don't just watch)
  • Experiment: modify the code to see what happens
  • Ask questions immediately
  • Note frequent errors and how to fix them

During lab sessions:

  • Read the entire assignment before starting
  • Break the problem into small steps
  • Test each function individually
  • Compile often (every 5-10 lines)
  • Ask for help if stuck for >15 min

Personal work (3-4h/week recommended):

  • Redo tutorial exercises without looking at the solution
  • Create your own small programs
  • Read other people's code (GitHub, forums)
  • Participate in challenges (CodinGame, HackerRank)

Problem-solving methodology

Systematic steps:

  1. Understand: Read and rephrase the problem
  2. Decompose: Identify sub-problems
  3. Algorithm: Write in pseudo-code or flowchart
  4. Code: Translate to C++
  5. Test: Normal cases, edge cases, errors
  6. Debug: If it doesn't work, identify the error
  7. Optimize: Improve if necessary

Example: Calculate the average of an array

1. Understand: Sum of elements / number of elements
2. Decompose:
   - Traverse the array
   - Add the values
   - Divide by the size
3. Pseudo-code:
   sum = 0
   FOR each element of the array
       sum = sum + element
   average = sum / size
4. Code in C++
5. Test with {10, 15, 20} -> average = 15

Welcome to the world of programming!

"Everybody should learn to program a computer, because it teaches you how to think." - Steve Jobs

Don't be afraid of making mistakes: bugs are part of learning. Every fixed error is a lesson learned!

Additional resources

  • Standard C++ documentation
  • Online exercises (France-IOI, CodinGame)
  • C++ reference books