begin process at 2012 05 27 14:05:17
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Maths & Algorithmes

 > CALCUL POLYNOMIAL

CALCUL POLYNOMIAL


 Description

cALCUL POLYNOMIAL
ce programme fait la déclaration  nécessaire  et lecture d'un polynome
et  fait affichage de polynome et fait la somme , produit , intégrale et affiche


realiser par MISSOUM Abdelkader
www.kader.missoum@yahoo.fr  

Source

  • #include<iostream.h> //cout<< , cout>>
  • #include <conio.h> //getch ()
  • #include <stdlib.h>
  • #include <math.h> //pow(x,n)
  • //_______________________________________________________________
  • struct monome //la déclaration ...
  • {
  • int coef;
  • unsigned exp;
  • monome *suivant;
  • };
  • /*#############################################################*/
  • monome * creation(monome * poly) //pour saisir un polynome
  • {
  • poly = new monome;
  • cout<<"\nCoefession = "; cin>> poly->coef;
  • cout<<"\nExposant = "; cin>> poly->exp;
  • poly->suivant = NULL;
  • monome *p = poly;
  • int k;
  • cout<<"------------------------------";
  • cout<<"\nContinuer ... 0/1 :"; cin>> k;
  • while (k != 0)
  • {
  • monome *q = new monome;
  • cout<<"\nCoefession = "; cin>> q->coef;
  • cout<<"\nExposant = "; cin>> q->exp;
  • q->suivant = NULL;
  • p->suivant = q;
  • p = q;
  • cout<<"------------------------------";
  • cout<<"\nContinuer ... 0/1 :"; cin>> k;
  • }
  • return poly;
  • }
  • /*#############################################################*/
  • void afficherPolynome(monome * poly) //pour afficher le polynome
  • {
  • cout<<"\nP= ";
  • if ( poly == NULL )
  • {
  • cout<<"Le polynôme n'est pas défini";
  • exit (0);
  • }
  • else
  • {
  • if (( poly->coef > 0 )||( poly->coef < 0 ))
  • cout<<poly->coef<<"X^"<<poly->exp;
  • poly = poly->suivant;
  • while ( poly != NULL )
  • {
  • if ( poly->coef < 0 )
  • cout<<" "<<poly->coef<<"X^"<<poly->exp;
  • else
  • if ( poly->coef > 0 )
  • cout<<" +"<<poly->coef<<"X^"<<poly->exp;
  • poly = poly->suivant;
  • }
  • }
  • }
  • /*#############################################################*/
  • float x_Polynome(monome *poly, float x) //calculer f(x)
  • {
  • float resulta=0;
  • while (poly != NULL)
  • {
  • resulta = resulta + poly->coef * pow(x, poly->exp);
  • poly = poly->suivant;
  • }
  • return resulta;
  • }
  • /*#############################################################*/
  • monome * somme(monome *P, monome *Q) //la somme des deux polynomes
  • {
  • monome *grand ,*petit;
  • monome *S = new monome;
  • S->suivant = NULL;
  • if (P->exp >= Q->exp){
  • S->exp = P->exp;
  • S->coef = P->coef;
  • grand = P;
  • petit = Q;
  • }
  • else {
  • S->exp = Q->exp;
  • S->coef = Q->coef;
  • grand = Q;
  • petit = P;
  • }
  • int d = (S->exp)- 1;
  • monome *ss = S;
  • monome * position0 = grand;
  • for (int i=d;i>=0;i--){
  • monome *nouveau = new monome;
  • nouveau->exp = i;
  • nouveau->coef = 0;
  • nouveau->suivant = NULL;
  • ss->suivant = nouveau;
  • ss = nouveau;
  • while (grand != NULL){
  • if (i == grand->exp)
  • ss->coef = grand->coef;
  • grand = grand->suivant;
  • }
  • grand = position0;
  • }
  • while (petit != NULL)
  • {
  • for (ss = S;ss != NULL; ss=ss->suivant)
  • if (petit->exp == ss->exp)
  • ss->coef = ss->coef + petit->coef;
  • petit = petit->suivant;
  • }
  • return S;
  • }
  • /*#############################################################*/
  • monome * produit(monome * P, monome * Q) //le produit des deux polynomes
  • {
  • monome *T = new monome;
  • T->exp = P->exp + Q->exp;
  • T->coef = 0;
  • T->suivant = NULL;
  • monome *t_fin = T;
  • int v = 0;
  • for (monome *pp = P; pp!=NULL; pp = pp->suivant)
  • for (monome *qq = Q ; qq!=NULL; qq = qq->suivant) {
  • int exp0 = 0; int v = 1;
  • exp0 = pp->exp + qq->exp;
  • for (monome *tt = T; tt!=NULL; tt = tt->suivant)
  • if (exp0 == tt->exp)
  • {
  • tt->coef = tt->coef + pp->coef * qq->coef;
  • v = 0;
  • break;
  • }
  • if (v == 1){
  • monome *nouveau = new monome;
  • nouveau->exp = pp->exp + qq->exp;
  • nouveau->coef = pp->coef * qq->coef;
  • nouveau->suivant = NULL;
  • t_fin->suivant = nouveau;
  • t_fin = nouveau;
  • }
  • }
  • return T;
  • }
  • /*#############################################################*/
  • monome * derivee (monome * poly) //la dérivation d'un polynome
  • {
  • monome *derive = new monome;
  • monome * nouveau;
  • derive->exp = (poly->exp)-1;
  • derive->coef = (poly->coef)*(poly->exp);
  • derive->suivant = NULL;
  • monome *d = derive;
  • monome * p = poly->suivant;
  • while (p != NULL)
  • {
  • nouveau = new monome;
  • nouveau->exp = (p->exp) - 1;
  • nouveau->coef = (p->exp)*(p->coef);
  • nouveau->suivant = NULL;
  • d->suivant = nouveau;
  • d = nouveau;
  • p = p->suivant;
  • }
  • return derive;
  • }
  • /*#############################################################*/
  • void afficherIden(void)
  • {
  • cout<<"\n\n#####################################################";
  • cout<<"\n\n |=========================================|\n";
  • cout<<" | Realiser par MISSOUM Abdelkader |\n";
  • cout<<" | en 17/12/2007 |\n";
  • cout<<" | Age : 18 |\n";
  • cout<<" | Nationnalite : Algerien (K.E.B) |\n";
  • cout<<" | Niveau : 2eme Annee universite |\n";
  • cout<<" | |\n";
  • cout<<" | www.kader.missoum@yahoo.fr |\n";
  • cout<<" |=========================================|\n\n";
  • }
  • /*#############################################################*/
  • /*#############################################################*/
  • void afficherMenu(void) //Affichage de MEnu
  • {
  • cout<<"\n\n#####################################################";
  • cout<<"\n\n |======================================|\n";
  • cout<<" | 1- Saisir le polynôme. |\n";
  • cout<<" | 2- Afficher le polynôme. |\n";
  • cout<<" | 3- Calculer P(X). |\n";
  • cout<<" | 4- Somme de deux polynômes. |\n";
  • cout<<" | 5- Produit de deux polynômes. |\n";
  • cout<<" | 6- Pôlynome dérivé |\n";
  • cout<<" | 0- Quiter. |\n";
  • cout<<" |======================================|\n\n";
  • }
  • /*#############################################################*/
  • int main(){
  • monome *P, *Q, *pp, *qq;
  • char choix;
  • float val, x;
  • afficherIden();
  • do
  • {
  • afficherMenu();
  • choix = getch();
  • switch ( choix )
  • {
  • case '1':
  • pp=creation(P);
  • getch();
  • break;
  • case '2':
  • afficherPolynome(pp);
  • getch();
  • break;
  • case '3':
  • cout<<"Donnez la valeur de X: ";
  • cin>> x;
  • val = x_Polynome( pp, x );
  • cout<<"\nP("<<x<<")= "<<val;
  • getch();
  • break;
  • case '4':
  • cout<<"Donnez le polynôme Q: \n";
  • qq = creation(Q);
  • cout<<"La somme des deux polynômes est:\n";
  • afficherPolynome( somme( pp, qq ) );
  • getch();
  • break;
  • case '5':
  • cout<<"Donnez le polynôme Q: \n";
  • qq = creation(Q);
  • cout<<"Le produit des deux polynômes est:\n";
  • afficherPolynome( produit(pp, qq) );
  • getch();
  • break;
  • case '6':
  • monome *pq = derivee(pp);
  • cout<<"le polynôme dérivé est:\n";
  • afficherPolynome( pq );
  • getch();
  • break;
  • }
  • }
  • while ( choix != '0' );
  • cout<<"\n ----- LE PROGRAMME TERMINE -----";
  • return 0;
  • }
#include<iostream.h> //cout<< , cout>>
#include <conio.h>  //getch ()
#include <stdlib.h> 
#include <math.h> //pow(x,n)

//_______________________________________________________________

struct monome               //la déclaration ...
{
  int coef;
  unsigned exp;
  monome *suivant;
};

/*#############################################################*/

monome * creation(monome * poly) //pour saisir un polynome
{
poly = new monome;
cout<<"\nCoefession = ";  cin>> poly->coef;
cout<<"\nExposant = ";  cin>> poly->exp;
poly->suivant = NULL;
monome *p = poly;

int k;
cout<<"------------------------------";
cout<<"\nContinuer ... 0/1 :"; cin>> k;

while (k != 0)
	{
	monome *q = new monome;
	cout<<"\nCoefession = ";  cin>> q->coef;
	cout<<"\nExposant = ";  cin>> q->exp;
	q->suivant = NULL;
	p->suivant = q;
	p = q;
	cout<<"------------------------------";
	cout<<"\nContinuer ... 0/1 :"; cin>> k;
	}
	return poly;
}

/*#############################################################*/

void afficherPolynome(monome * poly) //pour afficher le polynome
{
  cout<<"\nP= ";

  if ( poly == NULL )
  {
	 cout<<"Le polynôme n'est pas défini";
	 exit (0);
  }

  else
   {
	 if (( poly->coef > 0 )||( poly->coef < 0 ))     
          cout<<poly->coef<<"X^"<<poly->exp;
          
     poly = poly->suivant;
          
  while ( poly != NULL )
       {
	     if ( poly->coef < 0 )
              cout<<" "<<poly->coef<<"X^"<<poly->exp;
	     else
		    if ( poly->coef > 0 )
               cout<<" +"<<poly->coef<<"X^"<<poly->exp;

	       poly = poly->suivant;
       }
   }
}
/*#############################################################*/

float x_Polynome(monome *poly, float x) //calculer f(x)
{
  float resulta=0;
  while (poly != NULL)
  {
		  resulta = resulta + poly->coef * pow(x, poly->exp);
		  poly = poly->suivant;
  }
  return resulta;
}

/*#############################################################*/

monome * somme(monome *P, monome *Q) //la somme des deux polynomes
{
  monome *grand ,*petit;
  monome *S = new monome;
  S->suivant = NULL;
if (P->exp >= Q->exp){
		S->exp  = P->exp;
		S->coef = P->coef;
		grand = P;
		petit = Q;
  }
else {
		S->exp  = Q->exp;
		S->coef = Q->coef;
		grand = Q;
		petit = P;
  }
  
 int d = (S->exp)- 1;
 monome *ss = S;
 monome * position0 = grand;
 
 for (int i=d;i>=0;i--){
	 monome *nouveau = new monome;
	 nouveau->exp = i;
	 nouveau->coef = 0;
	 nouveau->suivant = NULL;
	 ss->suivant = nouveau;
	 ss = nouveau;

  while (grand != NULL){
	  if (i == grand->exp)
          ss->coef = grand->coef;

	grand = grand->suivant; 
 }
    grand = position0;
}

while (petit != NULL) 
   {
             for (ss = S;ss != NULL; ss=ss->suivant)
                  if (petit->exp == ss->exp)
                      ss->coef = ss->coef + petit->coef;
   
   petit = petit->suivant;
   }
      
 return S;
}

/*#############################################################*/

monome * produit(monome * P, monome * Q) //le produit des deux polynomes
 {      
       monome *T = new monome;
       T->exp = P->exp + Q->exp;
       T->coef = 0;
       T->suivant = NULL;
       monome *t_fin = T;
  int v = 0;
 for (monome *pp = P; pp!=NULL; pp = pp->suivant)
   for (monome *qq = Q ; qq!=NULL; qq = qq->suivant) {
    int exp0 = 0; int v = 1;
    
      exp0 = pp->exp + qq->exp;
      
      for (monome *tt = T; tt!=NULL; tt = tt->suivant) 
          if (exp0 == tt->exp)
          {
                   tt->coef =  tt->coef + pp->coef * qq->coef;
                   v = 0;
                   break;
          }
        
    if (v == 1){
          monome *nouveau = new monome;
          nouveau->exp = pp->exp + qq->exp;
          nouveau->coef = pp->coef * qq->coef;
          nouveau->suivant = NULL;
          t_fin->suivant = nouveau;
          t_fin = nouveau;        
         } 
 }

return T;
}                    
      
/*#############################################################*/

monome * derivee (monome * poly)  //la dérivation d'un polynome
{
		 monome *derive = new monome;
		 monome * nouveau;
		 derive->exp = (poly->exp)-1;
		 derive->coef = (poly->coef)*(poly->exp);
		 derive->suivant = NULL;
		 monome *d = derive;
		 monome * p = poly->suivant;
  
 while (p != NULL)
  {
       nouveau = new monome;
       nouveau->exp = (p->exp) - 1;
       nouveau->coef = (p->exp)*(p->coef);
       nouveau->suivant = NULL;
       d->suivant = nouveau;
       d = nouveau;
       p = p->suivant;
  }
 return derive;
}

/*#############################################################*/

void afficherIden(void)
{
  cout<<"\n\n#####################################################";
  cout<<"\n\n      |=========================================|\n";
  cout<<"      |  Realiser par MISSOUM Abdelkader        |\n";
  cout<<"      |           en 17/12/2007                 |\n";
  cout<<"      |  Age : 18                               |\n";
  cout<<"      |  Nationnalite : Algerien (K.E.B)        |\n";
  cout<<"      |  Niveau : 2eme Annee universite         |\n";
  cout<<"      |                                         |\n";
  cout<<"      |         www.kader.missoum@yahoo.fr      |\n";
  cout<<"      |=========================================|\n\n";
}

/*#############################################################*/

/*#############################################################*/

void afficherMenu(void)     //Affichage de MEnu
{
  cout<<"\n\n#####################################################";
  cout<<"\n\n      |======================================|\n";
  cout<<"      |  1- Saisir le polynôme.              |\n";
  cout<<"      |  2- Afficher le polynôme.            |\n";
  cout<<"      |  3- Calculer P(X).                   |\n";
  cout<<"      |  4- Somme de deux polynômes.         |\n";
  cout<<"      |  5- Produit de deux polynômes.       |\n";
  cout<<"      |  6- Pôlynome dérivé                  |\n";
  cout<<"      |  0- Quiter.                          |\n";
  cout<<"      |======================================|\n\n";
}

/*#############################################################*/

int main(){

  monome *P, *Q, *pp, *qq;

  char choix;
  float val, x;
  
afficherIden();

  do
{
afficherMenu(); 
 choix = getch();
	 switch ( choix )
	 {
		case '1':
		pp=creation(P);
		getch();
		break;

		case '2':
		  afficherPolynome(pp);
		  getch();
		  break;

		case '3':
		  cout<<"Donnez la valeur de X: ";
		  cin>> x;
		  val = x_Polynome( pp, x );
		  cout<<"\nP("<<x<<")= "<<val;
		  getch();
		break;

		case '4':
		  cout<<"Donnez le polynôme Q: \n";
		  qq = creation(Q);
		  cout<<"La somme des deux polynômes est:\n";
		  afficherPolynome( somme( pp, qq ) );
		  getch();
		break;

		case '5':
		  cout<<"Donnez le polynôme Q: \n";
			qq = creation(Q);
		  cout<<"Le produit des deux polynômes est:\n";
		  afficherPolynome( produit(pp, qq) );
		  getch();
		break;

		case '6':
		monome *pq = derivee(pp);
		  cout<<"le polynôme dérivé est:\n";
		  afficherPolynome( pq );
		  getch();
		break;
	 }
  }
  while ( choix != '0' );

cout<<"\n         ----- LE PROGRAMME TERMINE -----";

return 0;
}

 Conclusion

merci cppfrance


 Sources du même auteur

CONVERSION D'UNE IMAGE
SYSTEM EXPERT

 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,593 sec (3)

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