begin process at 2012 05 27 13:54:19
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Maths & Algorithmes

 > BIPNUM : CLASSE POUR NOMBRE MONÉTAIRE

BIPNUM : CLASSE POUR NOMBRE MONÉTAIRE


 Information sur la source

Note :
Aucune note
Catégorie :Maths & Algorithmes Niveau :Initié Date de création :16/11/2004 Date de mise à jour :15/06/2005 23:37:30 Vu / téléchargé :2 803 / 78

Auteur : bipcpp

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Cette classe permet de stocker des nombres monétaires.
C'est à dire qui permet de stocker des chiffres décimaux en conservant l'intégrité de la valeur (contrairement aux float).
La précision est de 18 chiffres pour la partie entière et 9 chiffres pour la partie décimale). La valeur nulle est gérée.
Le nombre peut être formaté en sortie et en entrée (signe décimal, symbole des milliers, symbole monétaire, ...)
Par exemple le nombre "1.234.567,89" est accepté en entrée et en sortie.

Cette classe est particulièrement faite pour les nombres des bases de données et/ou les chiffres monétaire.

Source

  • Le fichier header :
  • //************************************************************************
  • //* BipNUM Win V0.9.2 *
  • //*----------------------------------------------------------------------*
  • //* Header file for BipNUM Win *
  • //* *
  • //* *
  • //* Licence : freeware *
  • //************************************************************************
  • // include BipNUM only one time
  • #ifndef _BipNUM_
  • #define _BipNUM_
  • #include <iostream>
  • typedef __int64 LONGLONG;
  • // global define
  • const long BP_DECIMAL = 1000000000; // add to decimal part of currency
  • const long BP_DECIMALX2 = 2000000000; // BP_DECIMAL X 2
  • const int BP_DEC_DIGIT = 9; // number of digit in decimal part
  • const LONGLONG BP_MAX_INT = 1000000000000000000; // max value for integer part
  • const unsigned long int BP_MAX_DEC = 1999999999; // max value for decimal part
  • // structure define
  • struct BP_STRUCT_CURRENCY // Currency structure
  • {
  • LONGLONG lBP_Integer; // integer value
  • unsigned long int lBP_Decimal; // decimal value
  • bool bBP_Negative; // true : the currency is negative
  • bool bBP_Null; // true : the currency is null
  • };
  • struct BP_STRUCT_FORMAT // Format structure
  • {
  • int iBP_NumInt; // format:number of character before decimal sign
  • int iBP_NumDec; // format:number of character after decimal sign
  • std::string sBP_DecimalSign; // format:decimal sign
  • std::string sBP_KiloSign; // format:kilo sign
  • std::string sBP_CurrencySymbol; // format:currency symbol
  • std::string sBP_LeadChar; // format:leading character (only 1 char)
  • std::string sBP_Null; // null format
  • bool bBP_TrailZero; // trailing zero
  • };
  • class BP_Currency
  • {
  • private:
  • BP_STRUCT_CURRENCY BP_Cur; // Currency structure
  • BP_STRUCT_FORMAT BP_Fmt; // Format structure
  • int iBPError; // error code
  • public:
  • BP_Currency::BP_Currency (); // constructor
  • BP_Currency::~BP_Currency (); // destructor
  • BP_Currency::set (const std::string BP_SetString);
  • BP_Currency::set (const long BP_Long);
  • BP_Currency::setnull (void);
  • std::string BP_Currency::str (void);
  • BP_Currency::setstdformat (const int iBP_SetNumInt,
  • const int iBP_SetNumDec,
  • const std::string sBP_SetFormat);
  • BP_Currency::setformat (const int iBP_SetNumInt,
  • const int iBP_SetNumDec,
  • const std::string sBP_SetDecimalSign,
  • const std::string sBP_SetKiloSign,
  • const std::string sBP_SetCurrencySymbol,
  • const std::string sBP_SetLeadChar,
  • const std::string sBP_SetNull,
  • const bool bBP_TrailZero);
  • BP_Currency::setformat (const std::string sBP_SetFormat);
  • BP_Currency::reset (void);
  • BP_STRUCT_FORMAT BP_Currency::getformat (void);
  • bool BP_Currency::isnull (void);
  • BP_Currency::copyvalue (BP_Currency BP_CurSource);
  • BP_Currency::copyformat (BP_Currency BP_CurSource);
  • int BP_Currency::geterror (void);
  • // overload operator : currency
  • BP_Currency BP_Currency::operator + (const BP_Currency& BPright);
  • BP_Currency BP_Currency::operator - (const BP_Currency& BPright);
  • BP_Currency BP_Currency::operator += (const BP_Currency& BPright);
  • BP_Currency BP_Currency::operator -= (const BP_Currency& BPright);
  • bool BP_Currency::operator == (const BP_Currency& BPright);
  • bool BP_Currency::operator != (const BP_Currency& BPright);
  • bool BP_Currency::operator > (const BP_Currency& BPright);
  • bool BP_Currency::operator >= (const BP_Currency& BPright);
  • bool BP_Currency::operator < (const BP_Currency& BPright);
  • bool BP_Currency::operator <= (const BP_Currency& BPright);
  • BP_Currency BP_Currency::operator ++ (int BPright);
  • BP_Currency BP_Currency::operator -- (int BPright);
  • friend std::ostream & operator << (std::ostream & os, const BP_Currency& BPright);
  • // overload operator : long
  • friend BP_Currency BP_Currency::operator + (const BP_Currency& BPleft, const long& BPright);
  • friend BP_Currency BP_Currency::operator + (const long& BPleft, const BP_Currency& BPright);
  • friend BP_Currency BP_Currency::operator - (const BP_Currency& BPleft, const long& BPright);
  • friend BP_Currency BP_Currency::operator - (const long& BPleft, const BP_Currency& BPright);
  • bool BP_Currency::operator == (const long& BPright);
  • bool BP_Currency::operator != (const long& BPright);
  • bool BP_Currency::operator > (const long& BPright);
  • bool BP_Currency::operator >= (const long& BPright);
  • bool BP_Currency::operator < (const long& BPright);
  • bool BP_Currency::operator <= (const long& BPright);
  • };
  • #endif /* _BipNUM_ */
Le fichier header :

//************************************************************************
//*                           BipNUM Win V0.9.2                          *
//*----------------------------------------------------------------------*
//*                      Header file for BipNUM Win                      *
//*                                                                      *
//*                                                                      *
//* Licence : freeware                                                   *
//************************************************************************


// include BipNUM only one time
#ifndef _BipNUM_
#define _BipNUM_

#include <iostream>

typedef __int64 LONGLONG;


// global define
const long BP_DECIMAL = 1000000000;		// add to decimal part of currency
const long BP_DECIMALX2 = 2000000000;	// BP_DECIMAL X 2
const int BP_DEC_DIGIT = 9;				// number of digit in decimal part
const LONGLONG BP_MAX_INT = 1000000000000000000;	// max value for integer part
const unsigned long int BP_MAX_DEC = 1999999999;	// max value for decimal part


// structure define
struct BP_STRUCT_CURRENCY			// Currency structure
{
	LONGLONG lBP_Integer;			// integer value
	unsigned long int lBP_Decimal;	// decimal value
	bool bBP_Negative;				// true : the currency is negative
	bool bBP_Null;					// true : the currency is null
};

struct BP_STRUCT_FORMAT				// Format structure
{
	int iBP_NumInt;					// format:number of character before decimal sign
	int iBP_NumDec;					// format:number of character after decimal sign
	std::string sBP_DecimalSign;	// format:decimal sign
	std::string sBP_KiloSign;		// format:kilo sign
	std::string sBP_CurrencySymbol;	// format:currency symbol
	std::string sBP_LeadChar;		// format:leading character (only 1 char)
	std::string sBP_Null;			// null format
	bool bBP_TrailZero;				// trailing zero
};



class BP_Currency
{
	private:
		BP_STRUCT_CURRENCY BP_Cur;	// Currency structure
		BP_STRUCT_FORMAT BP_Fmt;	// Format structure
		int iBPError;				// error code

	public:
		BP_Currency::BP_Currency (); // constructor
		BP_Currency::~BP_Currency (); // destructor
		BP_Currency::set (const std::string BP_SetString);
		BP_Currency::set (const long BP_Long);
		BP_Currency::setnull (void);
		std::string BP_Currency::str (void);
		BP_Currency::setstdformat (const int iBP_SetNumInt,
					  const int iBP_SetNumDec,
					  const std::string sBP_SetFormat);
		BP_Currency::setformat (const int iBP_SetNumInt,
						const int iBP_SetNumDec,
						const std::string sBP_SetDecimalSign,
						const std::string sBP_SetKiloSign,
						const std::string sBP_SetCurrencySymbol,
						const std::string sBP_SetLeadChar,
						const std::string sBP_SetNull,
						const bool bBP_TrailZero);
		BP_Currency::setformat (const std::string sBP_SetFormat);
		BP_Currency::reset (void);
		BP_STRUCT_FORMAT BP_Currency::getformat (void);
		bool BP_Currency::isnull (void);
		BP_Currency::copyvalue (BP_Currency BP_CurSource);
		BP_Currency::copyformat (BP_Currency BP_CurSource);
		int BP_Currency::geterror (void);


		// overload operator : currency
		BP_Currency BP_Currency::operator + (const BP_Currency& BPright);
		BP_Currency BP_Currency::operator - (const BP_Currency& BPright);
		BP_Currency BP_Currency::operator += (const BP_Currency& BPright);
		BP_Currency BP_Currency::operator -= (const BP_Currency& BPright);
		bool BP_Currency::operator == (const BP_Currency& BPright);
		bool BP_Currency::operator != (const BP_Currency& BPright);
		bool BP_Currency::operator > (const BP_Currency& BPright);
		bool BP_Currency::operator >= (const BP_Currency& BPright);
		bool BP_Currency::operator < (const BP_Currency& BPright);
		bool BP_Currency::operator <= (const BP_Currency& BPright);
		BP_Currency BP_Currency::operator ++ (int BPright);
		BP_Currency BP_Currency::operator -- (int BPright);
		friend std::ostream & operator << (std::ostream & os, const BP_Currency& BPright);

		// overload operator : long
		friend BP_Currency BP_Currency::operator + (const BP_Currency& BPleft, const long& BPright);
		friend BP_Currency BP_Currency::operator + (const long& BPleft, const BP_Currency& BPright);
		friend BP_Currency BP_Currency::operator - (const BP_Currency& BPleft, const long& BPright);
		friend BP_Currency BP_Currency::operator - (const long& BPleft, const BP_Currency& BPright);
		bool BP_Currency::operator == (const long& BPright);
		bool BP_Currency::operator != (const long& BPright);
		bool BP_Currency::operator >  (const long& BPright);
		bool BP_Currency::operator >= (const long& BPright);
		bool BP_Currency::operator <  (const long& BPright);
		bool BP_Currency::operator <= (const long& BPright);
};

#endif /* _BipNUM_ */


 Conclusion

Les commentaires sont les bienvenus avant que j'attaque les opérations (addition, multiplication, ...).

Vous trouverez la documentation de la classe ici : http://bipcpp.free.fr/

Vous trouverez un démontrateur (source + exe) ici : http://bipcpp.free.fr/fr/bipnum/testnum.zip
Une mini calculatrice qui utilise cette classe (source + exe) ici : http://bipcpp.free.fr/fr/bipgdi/BipCalc-v110.zip

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

15 juin 2005 23:37:30 :
Surchage des opérateurs d'opération, de comparaison et de flux. Pour les nombres BipCurrency et les long.

 Sources du même auteur

Source avec Zip Source avec une capture AUTOCLIC - AUTOMATISATION DE WINDOWS
Source avec Zip PLANSCAN : SCANNEUR DE FICHIER ET CONFIGURATION PC
Source avec Zip Source avec une capture [ODBC] BIPFILE - FONCTIONS D'ACCÈS AUX BASES DE DONNÉES
Source avec Zip Source avec une capture BIPCPP - FENÊTRE,DIALOG,MENU INTER-ACTIFS
Source avec Zip CLASSE DATE C++ AVEC FORMAT ET VALEUR NULLE

 Sources de la même categorie

Source avec Zip UN EXAMPLE D'APPLICATION EN CUDA DE L'ALGORITHME DE SCAN POU... par oguzaras
Source avec Zip Source avec une capture CHIFFREMENT DE VIGENERE par lajouad
Source avec Zip Source avec une capture ANALYSE SYNTAXIQUE par lajouad
Source avec Zip Source avec une capture STRUCTURE D'UNE MATRICE PAR LES LISTE LINÉAIRE (NON CONTUGUS... par benzarabel
Source avec Zip Source avec une capture DESSINER UNE ARBRE BINAIRE( MODE CONSOLE): par benzarabel

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,484 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales