This commit is contained in:
Cameron Bray 2020-05-27 01:35:03 +02:00
parent 958bfa9038
commit e8096b9681
7 changed files with 112 additions and 30 deletions

View file

@ -16,6 +16,7 @@ private:
int OKState;
int BackState;
public:
Terrarium(int id);
int getRadState() const;

View file

@ -8,18 +8,21 @@
class TerrariumParameter { //TODO add to diagram
private:
float value;
int thresholdHigh;
int thresholdLow;
float value, thresholdHigh, thresholdLow;
public:
TerrariumParameter(int thresholdHigh, int thresholdLow);
class ThresholdExcep {
public:
int id;
ThresholdExcep(int id):id(id){};
};
TerrariumParameter(float thresholdHigh, float thresholdLow);
//getters setters
float getValue() const;
void setValue(float value);
int getThresholdHigh() const;
float getThresholdHigh() const;
void setThresholdHigh(int thresholdHigh);
int getThresholdLow() const;
float getThresholdLow() const;
void setThresholdLow(int thresholdLow);
bool is2High();

View file

@ -16,6 +16,12 @@ private:
public:
class ExceptionDate{
public:
int id;
ExceptionDate(int id);
};
Tortue();
Tortue(const std::string &nom, const std::string &naissance, const std::string &sexe);

View file

@ -33,7 +33,7 @@ Menu::Menu() : id(0), choice(0), nbreChoices(1) {
list.push_back(*(new std::pair<int,
std::string>(5,"\n Nom de la tortue a ajouter")));
list.push_back(*(new std::pair<int,
std::string>(11,"\n Naissance")));
std::string>(11,"\n Naissance en utilisant le format jj/mm/yyyy")));
list.push_back(*(new std::pair<int,
std::string>(12,"\n Sexe")));

View file

@ -4,7 +4,7 @@
#include "../include/TerrariumParameter.h"
//Constructor
TerrariumParameter::TerrariumParameter(int thresholdHigh, int thresholdLow) : thresholdHigh(thresholdHigh),
TerrariumParameter::TerrariumParameter(float thresholdHigh, float thresholdLow) : thresholdHigh(thresholdHigh),
thresholdLow(thresholdLow){}
//Getters Setters
@ -14,17 +14,25 @@ float TerrariumParameter::getValue() const {
void TerrariumParameter::setValue(float value) {
TerrariumParameter::value = value;
}
int TerrariumParameter::getThresholdHigh() const {
float TerrariumParameter::getThresholdHigh() const {
return thresholdHigh;
}
void TerrariumParameter::setThresholdHigh(int thresholdHigh) {
TerrariumParameter::thresholdHigh = thresholdHigh;
if (thresholdHigh < thresholdLow){
throw ThresholdExcep(1);
} else {
TerrariumParameter::thresholdHigh = thresholdHigh;
}
}
int TerrariumParameter::getThresholdLow() const {
float TerrariumParameter::getThresholdLow() const {
return thresholdLow;
}
void TerrariumParameter::setThresholdLow(int thresholdLow) {
TerrariumParameter::thresholdLow = thresholdLow;
if (thresholdLow > thresholdHigh){
throw ThresholdExcep(2);
} else {
TerrariumParameter::thresholdLow = thresholdLow;
}
}
//Methods

View file

@ -86,7 +86,48 @@ void Tortue::setNom(const string &nom) {
}
void Tortue::setNaissance(std::string naissance) {
Tortue::naissance = naissance;
time_t rawtime;
struct tm * timeinfo ;
std::string date = naissance;
if (date.size() != 10 || date[2] != '/'
|| date[5] != '/'){
throw ExceptionDate(2);
}
int annee = std::stoi(date.substr(6,9));
int mois = std::stoi(date.substr(3,4));
int jour = std::stoi(date.substr(0,2));
if (annee < 1900) throw ExceptionDate(3);
else if (mois > 12) throw ExceptionDate(4);
else if (jour > 31) throw ExceptionDate(5);
int h = 0;
int m = 0;
int s = 0;
time(&rawtime);
timeinfo = localtime(&rawtime);
timeinfo->tm_year = annee - 1900;
timeinfo->tm_mon= mois - 1;
timeinfo->tm_mday = jour;
timeinfo->tm_hour = h;
timeinfo->tm_min = m;
timeinfo->tm_sec = s;
long naiss =std::mktime(timeinfo);
//std::cout << naiss << std::endl;
std::time_t now = std::time(nullptr);
long time = now - naiss;
if (time < 0){
throw ExceptionDate(1);
}
}
void Tortue::setSexe(const string &sexe) {
@ -98,5 +139,4 @@ void Tortue::delete1() {
}
Tortue::ExceptionDate::ExceptionDate(int id) : id(id) {}

View file

@ -150,8 +150,19 @@ void Board::loop() {
break;
}
case 11 :
tortues->back().setNaissance(input);
menu->menuNext();
try {
tortues->back().setNaissance(input);
menu->menuNext();
} catch (std::invalid_argument excep) {
cout << "Dates are not integers" << endl;
} catch (Tortue::ExceptionDate excep) {
if (excep.id == 1) cout << "Not yet born ? Time travelling turtles are not allowed in this terrarium";
else if (excep.id == 2) cout << "The format of the date is not correct";
else if (excep.id == 3) cout << "It wasn't really born before 1900... You were scammed";
else if (excep.id == 4) cout << "After December you start over at January";
else if (excep.id == 5) cout << "Months don't usually last more than 31 days !";
}
break;
case 12 :
tortues->back().setSexe(input);
@ -175,37 +186,50 @@ void Board::loop() {
break;
}
case 7:
//TODO vérifier que chiffres
if (stoi(input) >= temperature->getThresholdLow()){
try {
temperature->setThresholdHigh(stoi(input));
menu->menuBack();
} else {
cout << "booooo" << endl;
}
catch (TerrariumParameter::ThresholdExcep excep) {
if (excep.id == 1) cout << "value is under the minimum value";
}
catch (std::invalid_argument excep) {
cout << "Not a value" << endl;
}
break;
case 8 :
if (stoi(input) <= temperature->getThresholdHigh()){
try {
temperature->setThresholdLow(stoi(input));
menu->menuBack();
} else {
cout << "booooo" << endl;
}catch (TerrariumParameter::ThresholdExcep excep) {
if (excep.id == 2) cout << "value is over the maximum value";
}
catch (std::invalid_argument excep) {
cout << "Not a value" << endl;
}
break;
case 9 :
if (stoi(input) >= pressure->getThresholdLow()){
try {
pressure->setThresholdHigh(stoi(input));
menu->menuBack();
} else {
cout << "booooo" << endl;
}catch (TerrariumParameter::ThresholdExcep excep) {
if (excep.id == 1) cout << "value is under the minimum value";
}
catch (std::invalid_argument excep) {
cout << "Not a value" << endl;
}
break;
case 10 :
if (stoi(input) <= pressure->getThresholdHigh()){
try {
pressure->setThresholdLow(stoi(input));
menu->menuBack();
} else {
cout << "booooo" << endl;
}catch (TerrariumParameter::ThresholdExcep excep) {
if (excep.id == 2) cout << "value is over the maximum value";
}
catch (std::invalid_argument excep) {
cout << "Not a value" << endl;
}
break;
default:
break;
}