Commit 2db2dd91 authored by Hernandez Francois's avatar Hernandez Francois

initial commit

parents
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
\ No newline at end of file
// Derivation.cpp
#include <iostream>
#include "Derivation.hpp"
int Expression::nb_instances_ = 0;
Expression::Expression(){
nb_instances_++;
}
Expression::~Expression(){
nb_instances_--;
}
Nombre::Nombre(double valeur){
this->valeur_ = valeur;
}
Nombre::~Nombre(){
}
void Nombre::affiche(std::ostream & o) const{
o << valeur_;
}
Expression * Nombre::derive(char nom) const{
Nombre * res = new Nombre(0);
return res;
}
Variable::Variable(char nom){
this->nom_ = nom;
}
Variable::~Variable(){
}
void Variable::affiche(std::ostream & o) const{
o << nom_;
}
Expression * Variable::derive(char nom) const{
Nombre * res;
if(this->nom_ == nom){
res = new Nombre(1);
} else {
res = new Nombre(0);
}
return res;
}
// Derivation.hpp
#include <iostream>
#ifndef DERIVATION_H
#define DERIVATION_H
class Expression {
public:
Expression(); // Constructeur
~Expression(); // Destructeur
virtual void affiche(std::ostream & o) const = 0;
virtual Expression * derive(char nom) const = 0;
//virtual Expression* clone() const = 0;
static int nb_instances(){
return nb_instances_;
}
private:
static int nb_instances_;
};
class Nombre : public Expression {
public:
Nombre(double valeur); // Constructeur
~Nombre(); // Destructeur
void affiche(std::ostream & o) const;
Expression * derive(char nom) const;
private:
double valeur_;
};
class Variable : public Expression {
public:
Variable(char nom); // Constructeur
~Variable(); // Destructeur
void affiche(std::ostream & o) const;
Expression * derive(char nom) const;
private:
char nom_;
};
#endif
// Main.cpp
#include <iostream>
#include <iomanip>
#include "Derivation.hpp"
int main()
{
Nombre * nb = new Nombre(2);
Variable * v = new Variable('x');
nb->affiche(std::cout);
std::cout << "\n";
v->affiche(std::cout);
std::cout << "\n";
Expression * dn = nb->derive('x');
dn->affiche(std::cout);
std::cout << "\n";
Expression * dv = v->derive('x');
dv->affiche(std::cout);
std::cout << "\n";
std::cout << dv->nb_instances();
}
# makefile
# création de l'exécutable 'Main'
all : Main
Main : Main.o Derivation.o
c++ -o Main Main.o Derivation.o
Main.o : Main.cpp Derivation.hpp
c++ -g -c Main.cpp
Derivation.o : Derivation.cpp Derivation.hpp
c++ -g -c Derivation.cpp
# suppression des fichiers temporaires
clean:
rm -rf *.o
rm -rf Main
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment