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
| #include <iostream>
#include <math.h>
using namespace std;
void menu(int &choix);
void nombrecote(int N,int &nbrc);
void perimetre(int N, int nbrc, float L, float &p);
void surface(int N, float L,float temp, float &A);
int main()
{
int etape,compt=0,choix,nbrc=0;
float Longueur,p=0,A=0,temp=0;
do {
cout << "entrez un entier N" << endl;
cin >> etape;
cout << "entrez un reel L" << endl;
cin >> Longueur;
compt++;
} while ((etape < 1 || Longueur <= 0) && compt < 3);
if(compt<3)
{
cout << "N=" << etape << endl;
cout << "L=" << Longueur << endl;
menu(choix);
switch (choix)
{
case 1:
nombrecote(etape, nbrc);
cout << "nombre de cotes = " << nbrc << endl;
break;
case 2:
perimetre(etape,nbrc,Longueur,p);
cout << "le perimetre = " << p << endl;
break;
case 3:
surface(etape,Longueur,temp,A);
cout << " aire = " << A << endl;
break;
}
}
else
{
;
}
}
void menu(int &choix)
{
cout << "choisissez une operation " << endl;
cout << "1. calcul du nombre de cotes" << endl;
cout << "2. calcul du perimetre " << endl;
cout << "3. calcul de l'aire " << endl;
cin >> choix;
}
void nombrecote(int etape,int &nbrc)
{
nbrc = 3 * pow(4, etape);
}
void perimetre(int etape,int nbrc,float Longueur, float &p )
{
nombrecote(etape, nbrc);
p = (float)nbrc * (Longueur / pow(3, etape));
}
void surface(int etape, float Longueur,float temp, float &A)
{
temp =((sqrt(3)/4)*pow(Longueur,2)) ;
A = temp * (1 + (1 / 3)*((1 - pow((4 / 9), (float)etape)) / 1 - (4 / 9)));
} |
Partager