Selon le professeur du département d'informatique du Cégep de Momo, François Leroux, un des algorithmes de base permettant une compréhension universel de la programmation pour un débutant, peu importe son origine, sa classe social ou sa culture, est sans nulle doute les taxes!
De plus, le Canada est sans doute l'un des pays ou les taxes de vente sur les produits et services sont les plus compliqués à appliquer. Et pour cause: Elle varie d'une province ou territoire à l'autre, elle est parfois composé ou séparé. Voici leur représentation en date du mois de septembre de l'année 2006 :
Province/Territoire | Taxe 1 | Taxe 2 | Taux |
---|---|---|---|
Alberta | TVH: 6% | Aucune | 6% |
Colombie-Britanique | TVH: 6% | TVP: 7% | 13% |
Ile-du-Prince-Édouard | TPS: 6% | TVP: 10% | 16.6% |
Manitoba | TPS: 6% | TVP: 7% | 13% |
Nouveau-Brunswick | TVH: 14% | Aucune | 14% |
Nouvelle-Écosse | TVH: 14% | Aucune | 14% |
Nunavut | TVH: 6% | Aucune | 6% |
Ontario | TPS: 6% | TVP: 8% | 14% |
Québec | TPS: 6% | TVQ: 7.5% | 13.95% |
Saskatchewan | TPS: 6% | TVP: 7% | 13% |
Terre-Neuve/Labrador | TVH: 14% | Aucune | 14% |
Territoire du Nord Ouest | TVH: 6% | Aucune | 6% |
Territoire du Yukon | TVH: 6% | Aucune | 6% |
Tout d'abord, voici un premier exemple permet d'afficher des données complètes sur les taxes en Visual C++ :
- #include "stdafx.h"
- #include "stdio.h"
- #include "string.h"
-
- int main(int argc, char* argv[])
- {
- char Compute[]={'C','C','C','C','S','C','S','S','S','S','C','S','S'};
- char * TaxName1[]={"TPS","TVH","TVH","TVH","TPS","TVH","TPS","TVH","TVH","TPS","TPS","TPS","TVH"};
- double TaxRate1[]={6.0000,14.0000,14.0000,14.0000,6.0000,6.0000,6.0000,6.0000,6.0000,6.0000,6.0000,6.0000,6.0000};
- char * TaxName2[]={"TVQ","","","","TVP","","TVP","","","TVP","TVP","TVP",""};
- double TaxRate2[]={7.5000,0.0000,0.0000,0.0000,7.0000,0.0000,7.0000,0.0000,0.0000,8.0000,10.0000,7.0000,0.0000};
- char * RegionMID[]={"QC","NS","NB","NF","BC","AB","MB","NT","NU","ON","PE","SK","YT"};
- char * RegionName_EN[]={"Quebec","Nova Scotia","New Brunswick","Newfoundland","British Columbia","Alberta","Manitoba","Northwest Territories","Nunavut","Ontario","Prince Edward Island","Saskatchewan","Yukon Territory"};
- char * RegionName_FR[]={"Québec","Nouvelle-Écosse","Nouveau-Brunswick","Terre-Neuve/Labrador","Colombie-Britanique","Alberta","Manitoba","Territoire du Nord Ouest","Nunavut","Ontario","Ile-du-Prince-Édouard","Saskatchewan","Territoire du Yukon"};
- char Tmp[255];
-
- printf("Nom de la province/territoire MID Taxe 1 Taxe 2 Taux\n");
- for(int I=0;I<13;I++) {
- printf("%-30s",RegionName_FR[I]);
- printf("%-4s",RegionMID[I]);
- strcpy(Tmp,TaxName1[I]);
- strcat(Tmp,":");
- sprintf(Tmp,"%.1f%%",TaxRate1[I]);
- printf("%-7s",Tmp);
- if(TaxName2[I]=="") {
- printf("%7s","");
- } else {
- strcpy(Tmp,TaxName2[I]);
- strcat(Tmp,":");
- sprintf(Tmp,"%.1f%%",TaxRate2[I]);
- printf("%-7s",Tmp);
- }
- switch(Compute[I]) {
- case 'S': //Séparé
- printf("%.1f%%\t",TaxRate1[I]+TaxRate2[I]);
- break;
- case 'C': //Composé
- printf("%.1f%%\t",TaxRate1[I]+((TaxRate2[I]*(100+TaxRate1[I]))/100));
- break;
- }
- printf("\n");
- }
- return 0;
- }
on obtiendra le résultat suivant :
|
Ensuite, voici un deuxième exemple permet de calculer la taxe de vente d'un produit ou service en fonction des provinces ou territoires en Visual C++ :
- #include "stdafx.h"
- #include "stdio.h"
- #include "string.h"
-
- int main(int argc, char* argv[])
- {
- char Compute[]={'C','C','C','C','S','C','S','S','S','S','C','S','S'};
- char * TaxName1[]={"TPS","TVH","TVH","TVH","TPS","TVH","TPS","TVH","TVH","TPS","TPS","TPS","TVH"};
- double TaxRate1[]={6.0000,14.0000,14.0000,14.0000,6.0000,6.0000,6.0000,6.0000,6.0000,6.0000,6.0000,6.0000,6.0000};
- char * TaxName2[]={"TVQ","","","","TVP","","TVP","","","TVP","TVP","TVP",""};
- double TaxRate2[]={7.5000,0.0000,0.0000,0.0000,7.0000,0.0000,7.0000,0.0000,0.0000,8.0000,10.0000,7.0000,0.0000};
- char * RegionMID[]={"QC","NS","NB","NF","BC","AB","MB","NT","NU","ON","PE","SK","YT"};
- char * RegionName_EN[]={"Quebec","Nova Scotia","New Brunswick","Newfoundland","British Columbia","Alberta","Manitoba","Northwest Territories","Nunavut","Ontario","Prince Edward Island","Saskatchewan","Yukon Territory"};
- char * RegionName_FR[]={"Québec","Nouvelle-Écosse","Nouveau-Brunswick","Terre-Neuve/Labrador","Colombie-Britanique","Alberta","Manitoba","Territoire du Nord Ouest","Nunavut","Ontario","Ile-du-Prince-Édouard","Saskatchewan","Territoire du Yukon"};
- char Tmp[255];
-
- printf("Nom de la province/territoire Taxe 1 Taxe 2 Taux 1$\t15$\t44,95$\t100$\n");
- for(int I=0;I<13;I++) {
- double Tax = 0;
- printf("%-30s",RegionName_FR[I]);
- strcpy(Tmp,TaxName1[I]);
- strcat(Tmp,":");
- sprintf(Tmp,"%.1f%%",TaxRate1[I]);
- printf("%-7s",Tmp);
- if(TaxName2[I]=="") {
- printf("%7s","");
- } else {
- strcpy(Tmp,TaxName2[I]);
- strcat(Tmp,":");
- sprintf(Tmp,"%.1f%%",TaxRate2[I]);
- printf("%-7s",Tmp);
- }
- switch(Compute[I]) {
- case 'S': //Séparé
- Tax = TaxRate1[I]+TaxRate2[I];
- break;
- case 'C': //Composé
- Tax = TaxRate1[I]+((TaxRate2[I]*(100+TaxRate1[I]))/100);
- break;
- }
- strcpy(Tmp,"");
- sprintf(Tmp,"%.1f%%",Tax);
- printf("%-6s",Tmp);
- printf("%.2f$\t",1*(1+(Tax/100)));
- printf("%.2f$\t",15*(1+(Tax/100)));
- printf("%.2f$\t",44.95*(1+(Tax/100)));
- printf("%.2f$\t",100*(1+(Tax/100)));
- printf("\n");
- }
- return 0;
- }
on obtiendra le résultat suivant :
|