This repository has been archived by the owner on May 17, 2024. It is now read-only.
forked from Feelzor/InterpreteurCpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-variables-typees: ajout de Valeur et ValeurEntiere
- Loading branch information
Showing
8 changed files
with
171 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef VALEUR_H | ||
#define VALEUR_H | ||
|
||
#include <string> | ||
#include <ostream> | ||
|
||
class Valeur { | ||
public: | ||
virtual int getEntier() const = 0; | ||
virtual float getReel() const = 0; | ||
virtual std::string getChaine() const = 0; | ||
virtual bool isVrai() const = 0; | ||
|
||
virtual Valeur* const operator+(const Valeur* v) const = 0; | ||
virtual Valeur* const operator-(const Valeur* v) const = 0; | ||
virtual Valeur* const operator*(const Valeur* v) const = 0; | ||
virtual Valeur* const operator/(const Valeur* v) const = 0; | ||
virtual bool operator> (const Valeur* v) const = 0; | ||
virtual bool operator>=(const Valeur* v) const = 0; | ||
virtual bool operator< (const Valeur* v) const = 0; | ||
virtual bool operator<=(const Valeur* v) const = 0; | ||
virtual bool operator==(const Valeur* v) const = 0; | ||
virtual bool operator!=(const Valeur* v) const = 0; | ||
|
||
bool operator&&(Valeur* v) { | ||
return isVrai() && v->isVrai(); | ||
} | ||
|
||
bool operator||(Valeur* v) { | ||
return isVrai() || v->isVrai(); | ||
} | ||
|
||
bool operator!() { | ||
return !isVrai(); | ||
} | ||
}; | ||
|
||
inline std::ostream& operator<<(std::ostream& out, Valeur* v) { | ||
out << v->getChaine(); | ||
return out; | ||
} | ||
|
||
#endif /* VALEUR_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "ValeurEntiere.h" | ||
#include "Valeur.h" | ||
|
||
#include <string> | ||
|
||
ValeurEntiere::ValeurEntiere(int valeur) : m_valeur(valeur) {} | ||
|
||
bool ValeurEntiere::isVrai() const { | ||
return m_valeur != 0; | ||
} | ||
|
||
int ValeurEntiere::getEntier() const { | ||
return m_valeur; | ||
} | ||
|
||
float ValeurEntiere::getReel() const { | ||
return ((float) m_valeur); | ||
} | ||
|
||
std::string ValeurEntiere::getChaine() const { | ||
return std::to_string(m_valeur); | ||
} | ||
|
||
Valeur* const ValeurEntiere::operator+(const Valeur* v) const { | ||
return new ValeurEntiere(m_valeur + v->getEntier()); | ||
} | ||
|
||
Valeur* const ValeurEntiere::operator-(const Valeur* v) const { | ||
return new ValeurEntiere(m_valeur - v->getEntier()); | ||
} | ||
|
||
Valeur* const ValeurEntiere::operator*(const Valeur* v) const { | ||
return new ValeurEntiere(m_valeur * v->getEntier()); | ||
} | ||
|
||
Valeur* const ValeurEntiere::operator/(const Valeur* v) const { | ||
return new ValeurEntiere(m_valeur / v->getEntier()); | ||
} | ||
|
||
bool ValeurEntiere::operator>(const Valeur* v) const { | ||
return m_valeur > v->getEntier(); | ||
} | ||
|
||
bool ValeurEntiere::operator>=(const Valeur* v) const { | ||
return m_valeur >= v->getEntier(); | ||
} | ||
|
||
bool ValeurEntiere::operator<(const Valeur* v) const { | ||
return m_valeur < v->getEntier(); | ||
} | ||
|
||
bool ValeurEntiere::operator<=(const Valeur* v) const { | ||
return m_valeur <= v->getEntier(); | ||
} | ||
|
||
bool ValeurEntiere::operator==(const Valeur* v) const { | ||
return m_valeur == v->getEntier(); | ||
} | ||
|
||
bool ValeurEntiere::operator!=(const Valeur* v) const { | ||
return m_valeur != v->getEntier(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef VALEURENTIERE_H | ||
#define VALEURENTIERE_H | ||
|
||
#include "Valeur.h" | ||
#include <string> | ||
|
||
class ValeurEntiere : public Valeur { | ||
public: | ||
ValeurEntiere(int valeur); | ||
int getEntier() const override; | ||
float getReel() const override; | ||
std::string getChaine() const override; | ||
bool isVrai() const override; | ||
|
||
Valeur* const operator+(const Valeur* v) const override; | ||
Valeur* const operator-(const Valeur* v) const override; | ||
Valeur* const operator*(const Valeur* v) const override; | ||
Valeur* const operator/(const Valeur* v) const override; | ||
bool operator> (const Valeur* v) const override; | ||
bool operator>=(const Valeur* v) const override; | ||
bool operator< (const Valeur* v) const override; | ||
bool operator<=(const Valeur* v) const override; | ||
bool operator==(const Valeur* v) const override; | ||
bool operator!=(const Valeur* v) const override; | ||
private: | ||
int m_valeur; | ||
}; | ||
|
||
#endif /* VALEURENTIERE_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters