-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
2331 lines (2179 loc) · 101 KB
/
mainwindow.cpp
File metadata and controls
2331 lines (2179 loc) · 101 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* \file mainwindow.cpp
* \author Jia Han & Antoine Hars
* \brief Déclaration des méthodes de la classe MainWindow.
* Ce fichier contient la déclaration des méthodes de la classe MainWindow.
*/
/* UV: LO21 - projet
* Sujet: Calculatrice à notation polonaise inversée
* Auteurs: Han Jia & Antoine Hars
* File: mainwindow.cpp
*/
// ui->listWidget->addItem("7");
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow * MainWindow::instanceUnique = 0;
Pile & pile = Pile::donneInstance();
FactoryConstante fac;
/*!
* \brief Méthode de MainWindow pour instancier le Design Pattern Singleton de MainWindow.
* Méthode appelant le constructeur de la classe MainWindow.
*/
MainWindow & MainWindow::donneInstance()
{
if (instanceUnique == 0)
instanceUnique = new MainWindow(0);
return * instanceUnique;
}
/*!
* \brief Méthode de MainWindow pour détruire le Design Pattern Singleton de MainWindow.
* Méthode appelant le destructeur de la classe MainWindow.
*/
void MainWindow::libereInstance()
{
if (instanceUnique != 0)
{
pile.libereInstance();
delete instanceUnique;
}
instanceUnique = 0;
}
/*!
* \brief Destructeur de MainWindow.
* Destructeur de la classe MainWindow.
*/
MainWindow::~MainWindow()
{
pile.supprimerObservateurMW(this);
if (instanceUnique != 0)
{
delete instanceUnique->ui;
delete instanceUnique;
}
}
/*!
* \brief Constructeur de MainWindow.
* Constructeur de la classe MainWindow.
* \param parent correspond à l'adresse du parent.
*/
MainWindow::MainWindow(QWidget * parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
test(0),
com(false),
type("radian"),
mode("entier")
{
ui->setupUi(this);
pile.ajouterObservateurMW(this);
// Raccourcis Clavier.
ui->button0->setShortcut(QKeySequence(Qt::Key_0));
ui->button1->setShortcut(QKeySequence(Qt::Key_1));
ui->button2->setShortcut(QKeySequence(Qt::Key_2));
ui->button3->setShortcut(QKeySequence(Qt::Key_3));
ui->button4->setShortcut(QKeySequence(Qt::Key_4));
ui->button5->setShortcut(QKeySequence(Qt::Key_5));
ui->button6->setShortcut(QKeySequence(Qt::Key_6));
ui->button7->setShortcut(QKeySequence(Qt::Key_7));
ui->button8->setShortcut(QKeySequence(Qt::Key_8));
ui->button9->setShortcut(QKeySequence(Qt::Key_9));
ui->buttonPlus->setShortcut(QKeySequence(Qt::Key_Plus));
ui->buttonDim->setShortcut(QKeySequence(Qt::Key_Minus));
ui->buttonMulti->setShortcut(QKeySequence(Qt::Key_Asterisk));
ui->buttonDiv->setShortcut(QKeySequence(Qt::Key_Slash));
ui->buttonExpression->setShortcut(QKeySequence(Qt::Key_Apostrophe));
ui->buttonSPACE->setShortcut(QKeySequence(Qt::Key_Space));
ui->buttonEntrer->setShortcut(QKeySequence(Qt::Key_Return));
ui->buttonFactoriel->setShortcut(QKeySequence(Qt::Key_Exclam));
ui->buttonPoint->setShortcut(QKeySequence(Qt::Key_Period));
ui->buttonDollar->setShortcut(QKeySequence(Qt::Key_Dollar));
ui->buttonAnnuler->setShortcut(QKeySequence(Qt::Key_Delete));
ui->actionQuit->setShortcut(QKeySequence(Qt::Key_Escape));
ui->buttonRetablir->setShortcut(QKeySequence(Qt::Key_Backspace));
ui->buttonAnnuler->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z));
ui->buttonRetablir->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Y));
ui->buttonEVAL->setShortcut(QKeySequence(Qt::Key_Tab));
ui->buttonCLEAR->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
// Connections.
QObject::connect(ui->button0, SIGNAL(clicked()), this, SLOT(num0Pressed()));
QObject::connect(ui->button1, SIGNAL(clicked()), this, SLOT(num1Pressed()));
QObject::connect(ui->button2, SIGNAL(clicked()), this, SLOT(num2Pressed()));
QObject::connect(ui->button3, SIGNAL(clicked()), this, SLOT(num3Pressed()));
QObject::connect(ui->button4, SIGNAL(clicked()), this, SLOT(num4Pressed()));
QObject::connect(ui->button5, SIGNAL(clicked()), this, SLOT(num5Pressed()));
QObject::connect(ui->button6, SIGNAL(clicked()), this, SLOT(num6Pressed()));
QObject::connect(ui->button7, SIGNAL(clicked()), this, SLOT(num7Pressed()));
QObject::connect(ui->button8, SIGNAL(clicked()), this, SLOT(num8Pressed()));
QObject::connect(ui->button9, SIGNAL(clicked()), this, SLOT(num9Pressed()));
QObject::connect(ui->buttonRetablir, SIGNAL(clicked()), this, SLOT(retablirPressed()));
QObject::connect(ui->buttonSPACE, SIGNAL(clicked()), this, SLOT(spacePressed()));
QObject::connect(ui->buttonEntrer, SIGNAL(clicked()), this, SLOT(entrerPressed()));
QObject::connect(ui->buttonAnnuler, SIGNAL(clicked()), this, SLOT(annulerPressed()));
QObject::connect(ui->buttonCLEAR, SIGNAL(clicked()), this, SLOT(clearPressed()));
QObject::connect(ui->buttonEVAL, SIGNAL(clicked()), this, SLOT(evalPressed()));
QObject::connect(ui->buttonPoint, SIGNAL(clicked()), this, SLOT(pointPressed()));
QObject::connect(ui->buttonExpression, SIGNAL(clicked()), this, SLOT(expressionPressed()));
QObject::connect(ui->buttonDollar, SIGNAL(clicked()), this, SLOT(dollarPressed()));
QObject::connect(ui->buttonPlus, SIGNAL(clicked()), this, SLOT(plusPressed()));
QObject::connect(ui->buttonDim, SIGNAL(clicked()), this, SLOT(dimPressed()));
QObject::connect(ui->buttonMulti, SIGNAL(clicked()), this, SLOT(multPressed()));
QObject::connect(ui->buttonDiv, SIGNAL(clicked()), this, SLOT(divPressed()));
QObject::connect(ui->buttonFactoriel, SIGNAL(clicked()), this, SLOT(factPressed()));
QObject::connect(ui->buttonSin, SIGNAL(clicked()), this, SLOT(sinPressed()));
QObject::connect(ui->buttonCos, SIGNAL(clicked()), this, SLOT(cosPressed()));
QObject::connect(ui->buttonTan, SIGNAL(clicked()), this, SLOT(tanPressed()));
QObject::connect(ui->buttonSinh, SIGNAL(clicked()), this, SLOT(sinhPressed()));
QObject::connect(ui->buttonCosh, SIGNAL(clicked()), this, SLOT(coshPressed()));
QObject::connect(ui->buttonTanh, SIGNAL(clicked()), this, SLOT(tanhPressed()));
QObject::connect(ui->buttonLog, SIGNAL(clicked()), this, SLOT(logPressed()));
QObject::connect(ui->buttonLn, SIGNAL(clicked()), this, SLOT(lnPressed()));
QObject::connect(ui->buttonSWAP, SIGNAL(clicked()), this, SLOT(swapPressed()));
QObject::connect(ui->buttonSUM, SIGNAL(clicked()), this, SLOT(sumPressed()));
QObject::connect(ui->buttonMEAN, SIGNAL(clicked()), this, SLOT(meanPressed()));
QObject::connect(ui->buttonDROP, SIGNAL(clicked()), this, SLOT(dropPressed()));
QObject::connect(ui->buttonDUP, SIGNAL(clicked()), this, SLOT(dupPressed()));
QObject::connect(ui->buttonPOW, SIGNAL(clicked()), this, SLOT(powPressed()));
QObject::connect(ui->buttonMOD, SIGNAL(clicked()), this, SLOT(modPressed()));
QObject::connect(ui->buttonSIGN, SIGNAL(clicked()), this, SLOT(signPressed()));
QObject::connect(ui->buttonINV, SIGNAL(clicked()), this, SLOT(invPressed()));
QObject::connect(ui->buttonSQRT, SIGNAL(clicked()), this, SLOT(sqrtPressed()));
QObject::connect(ui->buttonSQR, SIGNAL(clicked()), this, SLOT(sqrPressed()));
QObject::connect(ui->buttonCUBE, SIGNAL(clicked()), this, SLOT(cubePressed()));
QObject::connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
QObject::connect(ui->actionRad, SIGNAL(triggered()), this, SLOT(radSelected()));
QObject::connect(ui->actionDeg, SIGNAL(triggered()), this, SLOT(degSelected()));
QObject::connect(ui->actionEnt, SIGNAL(triggered()), this, SLOT(entierPressed()));
QObject::connect(ui->actionRationnel, SIGNAL(triggered()), this, SLOT(rationnelPressed()));
QObject::connect(ui->actionRe, SIGNAL(triggered()), this, SLOT(reelPressed()));
QObject::connect(ui->actionOui, SIGNAL(triggered()), this, SLOT(complexePressed()));
QObject::connect(ui->actionNon, SIGNAL(triggered()), this, SLOT(nonComplexePressed()));
LogSystem::add("Lancement de la calculatrice", 3);
// Chargement du contexte de la Pile.
//load();
}
/*!
* \brief Méthode de MainWindow mettant à jour l'affichage de la Pile.
* Méthode de la classe MainWindow qui affiche tous les éléments de la Pile.
*/
void MainWindow::miseAJour()
{
//afficher dans listWidget
ui->listWidget->clear();
ui->listWidget->addItem("ff");
ui->listWidget->addItem(QString::number(pile.getTab(pile.getN() - 1)->getEntier(), 10));
for (int j = pile.getN() - 1; j >= 0; j--)
{
if (pile.getTab(j)->getType() == "entier")
ui->listWidget->addItem(QString::number(pile.getTab(j)->getEntier(), 10));
if (pile.getTab(j)->getType() == "rationnel")
{
QString res = QString::number(pile.getTab(j)->getNumerateur(), 10) + "/" + QString::number(pile.getTab(j)->getDenominateur(), 10);
ui->listWidget->addItem(res);
}
if (pile.getTab(j)->getType() == "reel")
ui->listWidget->addItem(QString::number(pile.getTab(j)->getReel(), 'g', 10));
if (pile.getTab(j)->getType() == "complexe")
{
QString res;
//afficher partie reel
if (pile.getTab(j)->getPartieReelle()->getType() == "entier")
res = QString::number(pile.getTab(j)->getPartieReelle()->getEntier(), 10) + "$";
if (pile.getTab(j)->getPartieReelle()->getType() == "reel")
res = QString::number(pile.getTab(j)->getPartieReelle()->getReel(), 'g', 10) + "$";
if (pile.getTab(j)->getPartieReelle()->getType() == "rationnel")
res = QString::number(pile.getTab(j)->getPartieReelle()->getNumerateur(), 10) + "/" + QString::number(pile.getTab(j)->getPartieReelle()->getDenominateur(), 10) + "$";
//afficher partie virtuel
if (pile.getTab(j)->getPartieImaginaire()->getType() == "entier")
res += QString::number(pile.getTab(j)->getPartieImaginaire()->getEntier(), 10);
if (pile.getTab(j)->getPartieImaginaire()->getType() == "reel")
res += QString::number(pile.getTab(j)->getPartieImaginaire()->getReel(), 'g', 10);
if (pile.getTab(j)->getPartieImaginaire()->getType() == "rationnel")
res += QString::number(pile.getTab(j)->getPartieImaginaire()->getNumerateur(), 10) + "/" + QString::number(pile.getTab(j)->getPartieImaginaire()->getDenominateur(), 10);
ui->listWidget->addItem(res);
}
}
}
/*!
* \brief Méthode de MainWindow qui effectue les calculs de la calculatrice.
* Méthode de la classe MainWindow utilisé pour le traitement des Constantes.
*/
void MainWindow::entrerPressed()
{
// Récupération de tous les éléments séparés par des espaces.
QString value = ui->inputLine->text();
QRegExp re("[ ]+");
QStringList list = value.split(re);
int i = 0;
// Pour chaque élément de la liste de type QString que nous récupérons.
while (i < list.count())
{
// Expression régulière pour la détection d'une expression.
QRegExp ex("[']+");
QStringList expression = list[i].split(ex);
// Cas d'une expression.
if (expression.count() > 1 && expression[0] == "")
{
// Début de l'expression
list[i] = expression[1];
test = 1;
}
// Fin de l'expression
if (expression.count() > 1 && expression[1] == "")
list[i] = expression[0];
// Récupération du morceau de l'expression dans l'attribut de la classe MainWindow réservé aux expressions.
if (test == 1)
expPile.insert(list[i]);
// Dans le cas où ce n'est pas une expression et qu'il n'y a pas d'opérateur dans l'inputLine.
if (test == 0 && list[i] != "SWAP" && list[i] != "SUM" && list[i] != "MEAN" && list[i] != "DUP" &&
list[i] != "DROP" && list[i] != "+" && list[i] != "-" && list[i] != "*" &&
list[i] != "/" && list[i] != "!" && list[i] != "sin" && list[i] != "cos" &&
list[i] != "tan" && list[i] != "sinh" && list[i] != "cosh" && list[i] != "tanh" &&
list[i] != "log" && list[i] != "ln" && list[i] != "INV" && list[i] != "SQRT" &&
list[i] != "SQR" && list[i] != "CUBE" && list[i] != "POW" && list[i] != "MOD" &&
list[i] != "SIGN")
{
// Expressions régulières pour récupérer les rationnels, les réels et les complexes.
QRegExp ra("[/]+");
QStringList rationnelle = list[i].split(ra);
QRegExp ree("[.]+");
QStringList reel = list[i].split(ree);
QRegExp co("[$]+");
QStringList comp = list[i].split(co);
// S'il y a un complexe.
if (comp.count() > 1)
{
// L'option complexe est à non -> message d'erreur.
if (com == 0)
{
QMessageBox message;
message.setText("L'utilisation de complexes n'est pas autorisee.");
message.exec();
}
// L'option complexe est à oui.
else
{
// Récupération des parties Réelle et Imaginaire si elles sont de type réelles ou rationnelles.
// comp[0] = partie réelle.
// comp[1] = partie imaginaire.
QStringList rationReel = comp[0].split(ra);
QStringList rationVir = comp[1].split(ra);
QStringList reelReel = comp[0].split(ree);
QStringList reelVir = comp[1].split(ree);
Constante* comReel,* comVirtuel;
// Si la partie réelle du complexe est un rationnel.
if (rationReel.count() > 1)
{
// Récupération du rationnel.
int num = rationReel[0].toInt(); // Numérateur.
int den = rationReel[1].toInt(); // Dénominateur.
// Simplification.
int min = (num<=den ? num:den);
for (int i = min; i > 1; i--)
{
if (num%i == 0 && den%i == 0)
{
num /= i;
den /= i;
}
}
// Création de la constante contenant la partie réelle de type rationnel.
comReel = fac.creeConstante("rationnel", num, den);
}
// La partie réelle du complexe n'est pas un rationnel.
else
{
// Si la partie réelle du complexe est un réel.
if (reelReel.count() > 1)
{
// Création de la constante contenant la partie réelle de type réel.
comReel = fac.creeConstante("reel", 0, 0, comp[0].toFloat());
}
// La partie réelle du complexe est de type entier.
else
{
// Création de la constante contenant la partie réelle de type entier.
Constante * entier = fac.creeConstante("entier", comp[0].toInt());
comReel = entier;
}
}
// Si la partie imaginaire du complexe est un rationnel.
if (rationVir.count() > 1)
{
// Récupération du rationnel.
int num = rationVir[0].toInt(); // Numérateur.
int den = rationVir[1].toInt(); // Dénominateur.
// Simplification.
int min = (num<=den ? num:den);
for (int i = min; i > 1; i--)
{
if (num%i == 0 && den%i == 0)
{
num /= i;
den /= i;
}
}
// Création de la constante contenant la partie imaginaire de type rationnel.
comVirtuel = fac.creeConstante("rationnel", num, den);
}
// La partie imaginaire du complexe n'est pas un rationnel.
else
{
// Si la partie imaginaire du complexe est un réel.
if (reelVir.count() > 1)
{
// Création de la constante contenant la partie imaginaire de type réel.
comVirtuel = fac.creeConstante("reel", 0, 0, comp[1].toFloat());
}
// La partie imaginaire du complexe est de type entier.
else
{
// Création de la constante contenant la partie imaginaire de type entier.
Constante * entier = fac.creeConstante("entier", comp[1].toInt());
comVirtuel = entier;
}
}
// Création de la constante complexe contenant les parties réelles et imaginaires crées.
Constante * complexe = fac.creeConstante("complexe", 0, 0, 0, comReel, comVirtuel);
// On empile le complexe créé dans la pile.
pile.empiler(complexe);
}
}
// S'il n'y a pas de complexe.
else
{
// S'il y a un rationnel.
if (rationnelle.count() > 1)
{
// Mode rationnel non choisi.
if (mode != "rationnel")
{
QMessageBox message;
message.setText("Mode rationnel non selectionne.");
message.exec();
}
// Mode rationnel choisi.
else
{
// Récupération des éléments du rationnel.
int num = rationnelle[0].toInt(); // Numérateur
int den = rationnelle[1].toInt(); // Dénominateur
// Simplification.
int min = (num<=den ? num:den);
for (int i = min; i > 1; i--)
{
if (num%i == 0 && den%i == 0)
{
num /= i;
den /= i;
}
}
// Création de la constante rationnel avec le numérateur et le dénominateur.
Constante * ration = fac.creeConstante("rationnel", num, den);
// On empile le rationnel créé dans la pile.
pile.empiler(ration);
}
}
// S'il n'y a pas de rationnel.
else
{
// S'il y a un réel.
if (reel.count() > 1)
{
// Mode réel non choisi.
if (mode != "reel")
{
QMessageBox message;
message.setText("Mode reel non selectionne.");
message.exec();
}
// Mode réel choisi.
else
{
// Création de la constante contenant le réel.
Constante * reelle = fac.creeConstante("reel", 0, 0, list[i].toFloat());
// On empile le réel dans la pile.
pile.empiler(reelle);
}
}
// S'il n'y a pas de réel -> il y a un entier.
else
{
// Mode entier non choisi.
if (mode != "entier")
{
QMessageBox message;
message.setText("Mode entier non selectionne.");
message.exec();
}
// Mode entier choisi.
else
{
// Création de la constante contenant l'entier.
Constante * entier = fac.creeConstante("entier", list[i].toInt());
// On empile l'entier dans la pile.
pile.empiler(entier);
}
}
}
}
}
// Dans le cas où c'est une expression ou qu'il y a un opérateur dans l'inputLine.
else
{
// Ce n'est pas une expression -> c'est un opérateur.
if (test == 0)
{
// Opérateur SWAP.
if (list[i] == "SWAP")
{
// Le SWAP requiert 2 entiers présents dans la pile.
if (pile.getN() > 1 && pile.getTab(pile.getN() - 1)->getType() == "entier" &&
pile.getTab(pile.getN() - 2)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
int val2 = pile.getTab(pile.getN() - 2)->getEntier();
QString exp = "SWAP pile(" + QString::number(val1, 10) + ") et pile(" + QString::number(val2, 10) + ") :";
ui->Express->setText(exp);
this->opSWAP(pile);
}
else
{
QMessageBox mSWAP;
mSWAP.setText("SWAP requiert 2 entiers.");
mSWAP.exec();
}
}
// Opérateur SUM.
if (list[i] == "SUM")
{
// Le SUM requiert 1 entier présent dans la pile.
if (!pile.pileVide() && pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
QString exp = "Sum de premiers " + QString::number(val1, 10) + " elements :";
ui->Express->setText(exp);
this->opSUM(pile, mode, com);
}
else
{
QMessageBox mSUM;
mSUM.setText("SUM requiert 1 entier.");
mSUM.exec();
}
}
// Opérateur MEAN.
if (list[i] == "MEAN")
{
if (!pile.pileVide() && pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
QString exp = "MEAN de premiers " + QString::number(val1, 10) + " elements :";
ui->Express->setText(exp);
this->opMEAN(pile, mode, com);
}
else
{
QMessageBox mMEAN;
mMEAN.setText("MEAN requiert 1 entier.");
mMEAN.exec();
}
}
// Opérateur DUP.
if (list[i] == "DUP")
{
if (!pile.pileVide())
{
this->opDUP(pile);
ui->Express->setText("DUP");
}
else
{
QMessageBox mDUP;
mDUP.setText("DUP requiert une pile non vide.");
mDUP.exec();
}
}
// Opérateur DROP.
if (list[i] == "DROP")
{
if (!pile.pileVide())
{
this->opDROP(pile);
ui->Express->setText("DROP");
}
else
{
QMessageBox mDROP;
mDROP.setText("DROP requiert une pile non vide.");
mDROP.exec();
}
}
// Opérateur factoriel.
if (list[i] == "!")
{
// Factoriel requiert un entier.
if (!pile.pileVide() && pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
QString exp = QString::number(val1, 10) + "!=";
ui->Express->setText(exp);
this->opFact(pile);
}
else
{
QMessageBox mFact;
mFact.setText("Factoriel requiert 1 entier.");
mFact.exec();
}
}
// Opérateur sin.
if (list[i] == "sin")
{
if (!pile.pileVide())
{
QString exp;
// Pour un entier.
if (pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
exp = "sin" + QString::number(val1, 10) + "=";
}
// Pour un rationnel.
if (pile.getTab(pile.getN() - 1)->getType() == "rationnel")
{
int num1 = pile.getTab(pile.getN() - 1)->getNumerateur();
int den1 = pile.getTab(pile.getN() - 1)->getDenominateur();
exp = "sin" + QString::number(num1, 10) + "/" + QString::number(den1, 10) + "=";
}
// Pour un réel.
if (pile.getTab(pile.getN() - 1)->getType() == "reel")
{
float val1 = pile.getTab(pile.getN() - 1)->getReel();
exp = "sin" + QString::number(val1, 'g', 10) + "=";
}
ui->Express->setText(exp);
this->opSin(pile, type);
}
else
{
QMessageBox mSin;
mSin.setText("Sin requiert 1 constante.");
mSin.exec();
}
}
// Opérateur cos.
if (list[i] == "cos")
{
if (!pile.pileVide())
{
QString exp;
// Pour un entier.
if (pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
exp = "cos" + QString::number(val1, 10) + "=";
}
// Pour un rationnel.
if (pile.getTab(pile.getN() - 1)->getType() == "rationnel")
{
int num1 = pile.getTab(pile.getN() - 1)->getNumerateur();
int den1 = pile.getTab(pile.getN() - 1)->getDenominateur();
exp = "cos" + QString::number(num1, 10) + "/" + QString::number(den1, 10) + "=";
}
// Pour un réel.
if (pile.getTab(pile.getN() - 1)->getType() == "reel")
{
float val1 = pile.getTab(pile.getN() - 1)->getReel();
exp = "cos" + QString::number(val1, 'g', 10) + "=";
}
ui->Express->setText(exp);
this->opCos(pile, type);
}
else
{
QMessageBox mCos;
mCos.setText("Cos requiert 1 constante.");
mCos.exec();
}
}
// Opérateur tan.
if (list[i] == "tan")
{
if (!pile.pileVide())
{
QString exp;
// Pour un entier.
if (pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
exp = "tan" + QString::number(val1, 10) + "=";
}
// Pour un rationnel.
if (pile.getTab(pile.getN() - 1)->getType() == "rationnel")
{
int num1 = pile.getTab(pile.getN() - 1)->getNumerateur();
int den1 = pile.getTab(pile.getN() - 1)->getDenominateur();
exp = "tan" + QString::number(num1, 10) + "/" + QString::number(den1, 10) + "=";
}
// Pour un réel.
if (pile.getTab(pile.getN() - 1)->getType() == "reel")
{
float val1 = pile.getTab(pile.getN() - 1)->getReel();
exp = "tan" + QString::number(val1, 'g', 10) + "=";
}
ui->Express->setText(exp);
this->opTan(pile, type);
}
else
{
QMessageBox mTan;
mTan.setText("Tan requiert 1 constante.");
mTan.exec();
}
}
// Opérateur sinh.
if (list[i] == "sinh")
{
if (!pile.pileVide())
{
QString exp;
// Pour un entier.
if (pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
exp = "sinh" + QString::number(val1, 10) + "=";
}
// Pour un rationnel.
if (pile.getTab(pile.getN() - 1)->getType() == "rationnel")
{
int num1 = pile.getTab(pile.getN() - 1)->getNumerateur();
int den1 = pile.getTab(pile.getN() - 1)->getDenominateur();
exp = "sinh" + QString::number(num1, 10) + "/" + QString::number(den1, 10) + "=";
}
// Pour un réel.
if (pile.getTab(pile.getN() - 1)->getType() == "reel")
{
float val1 = pile.getTab(pile.getN() - 1)->getReel();
exp = "sinh" + QString::number(val1, 'g', 10) + "=";
}
ui->Express->setText(exp);
this->opSinh(pile, type);
}
else
{
QMessageBox mSinh;
mSinh.setText("Sinh requiert 1 constante.");
mSinh.exec();
}
}
// Opérateur cosh.
if (list[i] == "cosh")
{
if (!pile.pileVide())
{
QString exp;
// Pour un entier.
if (pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
exp = "cosh" + QString::number(val1, 10) + "=";
}
// Pour un rationnel.
if (pile.getTab(pile.getN() - 1)->getType() == "rationnel")
{
int num1 = pile.getTab(pile.getN() - 1)->getNumerateur();
int den1 = pile.getTab(pile.getN() - 1)->getDenominateur();
exp = "cosh" + QString::number(num1, 10) + "/" + QString::number(den1, 10) + "=";
}
// Pour un réel.
if (pile.getTab(pile.getN() - 1)->getType() == "reel")
{
float val1 = pile.getTab(pile.getN() - 1)->getReel();
exp = "cosh" + QString::number(val1, 'g', 10) + "=";
}
ui->Express->setText(exp);
this->opCosh(pile, type);
}
else
{
QMessageBox mCosh;
mCosh.setText("Cos requiert 1 constante.");
mCosh.exec();
}
}
// Opérateur tanh.
if (list[i] == "tanh")
{
if (!pile.pileVide())
{
QString exp;
// Pour un entier.
if (pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
exp = "tanh" + QString::number(val1, 10) + "=";
}
// Pour un rationnel.
if (pile.getTab(pile.getN() - 1)->getType() == "rationnel")
{
int num1 = pile.getTab(pile.getN() - 1)->getNumerateur();
int den1 = pile.getTab(pile.getN() - 1)->getDenominateur();
exp = "tanh" + QString::number(num1, 10) + "/" + QString::number(den1, 10) + "=";
}
// Pour un réel.
if (pile.getTab(pile.getN() - 1)->getType() == "reel")
{
float val1 = pile.getTab(pile.getN() - 1)->getReel();
exp = "tanh" + QString::number(val1, 'g', 10) + "=";
}
ui->Express->setText(exp);
this->opTanh(pile, type);
}
else
{
QMessageBox mTanh;
mTanh.setText("Tanh requiert 1 constante.");
mTanh.exec();
}
}
// Opérateur log.
if (list[i] == "log")
{
if (!pile.pileVide())
{
QString exp;
// Pour un entier.
if (pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
exp = "log" + QString::number(val1, 10) + "=";
}
// Pour un rationnel.
if (pile.getTab(pile.getN() - 1)->getType() == "rationnel")
{
int num1 = pile.getTab(pile.getN() - 1)->getNumerateur();
int den1 = pile.getTab(pile.getN() - 1)->getDenominateur();
exp = "log" + QString::number(num1, 10) + "/" + QString::number(den1, 10) + "=";
}
// Pour un réel.
if (pile.getTab(pile.getN() - 1)->getType() == "reel")
{
float val1 = pile.getTab(pile.getN() - 1)->getReel();
exp = "log" + QString::number(val1, 'g', 10) + "=";
}
ui->Express->setText(exp);
this->opLog(pile);
}
else
{
QMessageBox mLog;
mLog.setText("Log requiert 1 constante.");
mLog.exec();
}
}
// Opérateur ln.
if (list[i] == "ln")
{
if (!pile.pileVide())
{
QString exp;
// Pour un entier.
if (pile.getTab(pile.getN() - 1)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
exp = "ln" + QString::number(val1, 10) + "=";
}
// Pour un rationnel.
if (pile.getTab(pile.getN() - 1)->getType() == "rationnel")
{
int num1 = pile.getTab(pile.getN() - 1)->getNumerateur();
int den1 = pile.getTab(pile.getN() - 1)->getDenominateur();
exp = "ln" + QString::number(num1, 10) + "/" + QString::number(den1, 10) + "=";
}
// Pour un réel.
if (pile.getTab(pile.getN() - 1)->getType() == "reel")
{
float val1 = pile.getTab(pile.getN() - 1)->getReel();
exp = "ln" + QString::number(val1, 'g', 10) + "=";
}
ui->Express->setText(exp);
this->opLn(pile);
}
else
{
QMessageBox mLn;
mLn.setText("Ln requiert 1 constante.");
mLn.exec();
}
}
// Opérateur POW.
if (list[i] == "POW")
{
if (!pile.pileVide())
{
ui->Express->setText("POW");
this->opPOW(pile, mode);
}
else
{
QMessageBox mPOW;
mPOW.setText("POW requiert 1 constante.");
mPOW.exec();
}
}
// Opérateur %.
if (list[i] == "MOD")
{
if (pile.getN() > 1 && pile.getTab(pile.getN() - 1)->getType() == "entier" &&
pile.getTab(pile.getN() - 2)->getType() == "entier")
{
int val1 = pile.getTab(pile.getN() - 1)->getEntier();
int val2 = pile.getTab(pile.getN() - 2)->getEntier();
QString exp = QString::number(val2, 10) + "%" + QString::number(val1, 10) + "=";
ui->Express->setText(exp);
this->opMOD(pile);
}
else
{
QMessageBox mMOD;
mMOD.setText("MODULO requiert 2 entiers.");
mMOD.exec();
}
}
// Opérateur SIGN.
if (list[i] == "SIGN")
{
if (!pile.pileVide())
{
ui->Express->setText("SIGN");
this->opSIGN(pile);
}
else
{
QMessageBox mSIGN;
mSIGN.setText("SIGN requiert 1 constante.");
mSIGN.exec();
}
}
// Opérateur INV.
if (list[i] == "INV")
{
if (!pile.pileVide())
{
ui->Express->setText("INV");
this->opINV(pile);
}
else
{
QMessageBox mINV;
mINV.setText("INV requiert 1 constante.");
mINV.exec();
}
}
// Opérateur SQRT.
if (list[i] == "SQRT")
{
if (!pile.pileVide())
{
ui->Express->setText("SQRT");
this->opSQRT(pile);
}
else
{
QMessageBox mSQRT;
mSQRT.setText("SQRT requiert 1 constante.");
mSQRT.exec();
}
}
// Opérateur SQR.
if (list[i] == "SQR")
{
if (!pile.pileVide())
{
ui->Express->setText("SQR");
this->opSQR(pile);
}
else
{
QMessageBox mSQR;
mSQR.setText("SQR requiert 1 constante.");
mSQR.exec();
}
}
// Opérateur CUBE.
if (list[i] == "CUBE")
{
if (!pile.pileVide())
{
ui->Express->setText("CUBE");
this->opCUBE(pile);
}
else
{
QMessageBox mCUBE;
mCUBE.setText("CUBE requiert 1 constante.");
mCUBE.exec();
}
}
// Opérateur +.
if (list[i] == "+")
{
if (pile.getN() > 0)
{
QString exp;
// Cas de la première valeur.
// Pour un entier.