This repository has been archived by the owner on Jul 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
FonctionBinaire.cpp
112 lines (86 loc) · 3.26 KB
/
FonctionBinaire.cpp
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
//-----------------------------------------------------------------------------------//
// Nom du projet : Fonctions Binaires
// Nom du fichier : FonctionBinaire.cpp
// Date de création : 19.01.2021
// Date de modification : 20.01.2021
//
// Auteur : Philou (Ph. Bovey)
//
// Description : ce programme est relié au test n°1 C++ - SLO2
//
// Remarques : lien pour la table ASCII :
// -> http://www.asciitable.com/
//----------------------------------------------------------------------------------//
//-- librairie standart --//
#include <iostream> //-- utilisation des entrées / sorties
#include <iomanip> //-- lib pour la partie affichage
#include <cstdlib> //-- librairie système
#include <string>
//-- librairie personnelle --//
#include "FonctionBinaire.h"
FonctionBinaire::FonctionBinaire()
{
FonctionBinaire::EntreeA = 0;
FonctionBinaire::EntreeB = 0;
FonctionBinaire::Sortie = 0;
FonctionBinaire::nbDigit = 0;
FonctionBinaire::limitMaxValue = 0;
}
FonctionBinaire::~FonctionBinaire()
{
}
void FonctionBinaire::InsererValeur()
{
//uint16_t nbDigitMax = 0;
//-- message utilisateur --//
std::cout << "veuillez inserer le nombre de digit voulue : ";
//-- récupération de la valeur --//
std::cin >> FonctionBinaire::nbDigit;
//-- essai PBY -> le 29.03.2023
//int test = nbDigit;
//int test2 = this->nbDigit;
// -> INVALIDE FonctionBinaire::test3 = test2; car attribut statique !!!
//-- création du nombre limite que peut inserer l'utilisateur --//
FonctionBinaire::limitMaxValue = pow(2,nbDigit);
//-- message utilisateur --//
//-- MAJ de l'entree A
std::cout << "\nveuillez inserer une valeur entre 0 et " << FonctionBinaire::limitMaxValue << "\n"; // à complèter
//-- rendre la valeur en mode absolue --//
std::cin >> FonctionBinaire::EntreeA;
FonctionBinaire::EntreeA = abs(FonctionBinaire::EntreeA);
//-- test sur la valeur --//
if ((FonctionBinaire::EntreeA > FonctionBinaire::limitMaxValue) || (FonctionBinaire::EntreeA < 0))
FonctionBinaire::EntreeA = FonctionBinaire::limitMaxValue;
//-- message utilisateur --//
//-- MAJ de l'entree B
std::cout << "veuillez inserer une valeur entre 0 et " << FonctionBinaire::limitMaxValue << "\n"; // à complèter
//-- rendre la valeur en mode absolue --//
std::cin >> FonctionBinaire::EntreeB;
FonctionBinaire::EntreeB = abs(FonctionBinaire::EntreeB);
//-- test sur la valeur --//
if ((FonctionBinaire::EntreeB > FonctionBinaire::limitMaxValue) || (FonctionBinaire::EntreeB < 0))
FonctionBinaire::EntreeB = FonctionBinaire::limitMaxValue;
}
std::string FonctionBinaire::ConversionBinaire(int valConvert)
{
// Déclaration de varîables
int i = FonctionBinaire::nbDigit;
//-- déclaration d'objet --//
std::string binaryString = "";
//-- boucle de convertion --//
// Convertit tout en string selon le nombre de digits spécifié
for (i - 1; i >= 0; i--) {
//-- récuperation de l'info binaire --//
// Ajoute 1 ou 0 au string en fonction de la valeur du LSB
binaryString += ((valConvert & (1 << i)) != 0) ? "1" : "0";
}
// retour de la chaîne de caractère => object string
return binaryString;
}
//-- FONCTION NON DEFINIE --//
void FonctionBinaire::OperationBinaire()
{
}
void FonctionBinaire::AfficherInfo()
{
}