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
136 lines (99 loc) · 3.3 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//-----------------------------------------------------------------------------------//
// 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
//-- librairie personnelle --//
#include "FonctionBinaire.h"
void FonctionBinaire::InsererValeur()
{
int tempUserValue = 0;
//-- message utilisateur --//
std::cout << "Veuillez inserer le nombre de digit voulue : ";
//-- récupération de la valeur --//
std::cin >> tempUserValue;
//-- Limitation de la valeur --//
if (tempUserValue <= 0)
tempUserValue = 1;
if (tempUserValue > 31)
tempUserValue = 31;
//-- Sauvegarde de la valeur --//
this->nbDigit = tempUserValue;
//-- création du nombre limite que peut inserer l'utilisateur --//
this->limitMaxValue = int(pow(2, this->nbDigit) - 1);
//-- message utilisateur --//
//-- MAJ de l'entree A --//
std::cout << "\nveuillez inserer une valeur entre 0 et " << this->limitMaxValue << " : ";
std::cin >> tempUserValue;
//-- rendre la valeur en mode absolue --//
tempUserValue = abs(tempUserValue);
//-- test sur la valeur --//
if (tempUserValue > this->limitMaxValue)
{
tempUserValue = this->limitMaxValue;
}
else if (tempUserValue == 0)
{
tempUserValue = 1;
}
//-- sauvegarde de la valeur --//
this->entreeA = tempUserValue;
//-- message utilisateur --//
//-- MAJ de l'entree B --//
std::cout << "\nveuillez inserer une valeur entre 0 et " << this->limitMaxValue << " : ";
std::cin >> tempUserValue;
//-- rendre la valeur en mode absolue --//
tempUserValue = abs(tempUserValue);
//-- test sur la valeur --//
if (tempUserValue > this->limitMaxValue)
{
tempUserValue = this->limitMaxValue;
}
else if (tempUserValue == 0)
{
tempUserValue = 1;
}
//-- sauvegarde de la valeur --//
this->entreeB = tempUserValue;
}
std::string FonctionBinaire::ConversionBinaire(int valConvert)
{
//-- déclaration d'objet --//
std::string strBinaire = "";
//-- déclaration de variable --//
int quotient = valConvert;
int reste = 0;
char charBinaire;
//-- boucle de convertion --//
//-- Conversion binaire par division par 2 successives --//
while (quotient > 0)
{
reste = quotient % 2;
//-- Conversion de binaire à charactère --//
charBinaire = reste + '0';
//-- Ajout du caractère à la chaine --//
strBinaire = strBinaire + charBinaire;
quotient = quotient / 2;
}
// retour de la chaîne de caractère => object string
return strBinaire;
}
//-- FONCTION NON DEFINIE --//
void FonctionBinaire::OperationBinaire()
{
}
void FonctionBinaire::AfficherInfo()
{
}