Solved

An easy program...homework...but I don't know how to develop it...please help me!!

Posted on 1997-12-11
9
189 Views
Last Modified: 2010-04-10
Can someone help me to debug my program...???
0
Comment
Question by:Vampire
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Not without knowing what the program is or what it does wrong.
0
 

Expert Comment

by:miredo
Comment Utility
Give us all the details: What the program is supposed to do, what you have done with it so far (cut and paste the code here!),  what you feel the problem is.  We can perhaps help you over the hurdles without doing the assignment for you.  Before you debug, you first want to know if you're on the right track.  It's very important that we see your code.

--M
0
 

Author Comment

by:Vampire
Comment Utility
/* Figure.cpp

      Par Sebastien Bigras en date du 8 decembre 1997

      Ce programme permet a l'usager de choisir une figure geometrique, d'entrer
      une description ainsi qu'une identification de celle-ci, ensuite d'entrer
      ses mesures pour pouvoir proceder aux calculs, soit celui du perimetre et
   celui de la surface.

*/

#include <math.h>
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <stdio.h>
#include <classlib\arrays.h>

#define Pi = 3.1416

void Afficher_Menu();
void Quitter();

class TFigure
      {
      public:
                    TFigure() {};
                    virtual void Lire(){};
                    virtual void Afficher(){};
                    virtual float CalculerSurface(){};
                    virtual float CalculerPerimetre(){};

      protected:
                        float surface;
                        float perimetre;
       };

/* TISArrayAsVector */
typedef TISArrayAsVector<TFigure> TListe;


class TRectangle: public TFigure
       {
       protected:
              float longueur;
              float largeur;
       public:
              TRectangle(){};
              void Lire();
              void Afficher();
              float CalculerSurface();
              float CalculerPerimetre();
       };

void TRectangle::Lire()
{
            clrscr();
            cout << "Entrez la longueur du rectangle: ";
            cin >> longueur;
            cout << endl;
            cout << "Entrez la largeur du rectangle: ";
            cin >> largeur;

}

void TRectangle::Afficher()
{
       clrscr();
       cout << "La longeur du rectangle est de: " << longueur << endl;
       cout << "La largeur du rectangle est de: " << largeur << endl;
       cout << "La surface du rectangle est de: " << surface << endl;
       cout << "Le perimetre du rectangle est de: " << perimetre << endl;
}

float TRectangle::CalculerSurface()
{

      surface = longueur * largeur;

      return (surface);
}

float TRectangle::CalculerPerimetre()
{

      perimetre = ((2 * longueur) + (2 * largeur));

      return (perimetre);
}


class TCarre: public TFigure
       {
       protected:
              float cote;
       public:
              TCarre() {};
              void Lire();
              void Afficher();
              float CalculerSurface();
              float CalculerPerimetre();
       };

void TCarre::Lire()
{
      clrscr();
      cout << "Entrez la dimension du cote: ";
      cin >> cote;

}

void TCarre::Afficher()
{
      clrscr();
      cout << "Le cote du carre est de: " << cote << endl;
      cout << "Le perimetre du carre est de: " << perimetre << endl;
      cout << "La surface du carre est de: " << surface << endl;

}
float TCarre::CalculerSurface()
{

  surface = cote * cote;

  return (surface);
}
float TCarre::CalculerPerimetre()
{

  perimetre = 4 * cote;

  return (perimetre);
}

/*
class TTriangle: public TFigure
       {
            protected:
                  float hypotenuse;
                  float base;
                  float hauteur;
                  float cote;

            public:
                  TTriangle() {};
                  void Lire();
                  void Afficher();
                  float CalculerSurface();
                  float CalculerPerimetre();

       };

void TTriangle::Lire()
{
      clrscr();
      cout << "Entrez l'hypotenuse: ";
      cin >> hypotenuse;
      cout << endl;
      cout << "Entrez la base: ";
      cin >> base;
      cout << endl;
      cout << "Entrez la hauteur: ";
      cin >> hauteur;
      cout << endl;
      cout << "Entrez le cote: ";
      cin >> cote;

}

void TTriangle::Afficher()
{
  clrscr();
  cout << "L'hypotenuse est de: " << hypotenuse << endl;
  cout << "La base est de: " << base << endl;
  cout << "La hauteur est de: " << hauteur << endl;
  cout << "Le cote est de: " << cote << endl;
  cout << "Le perimetre est de: " << perimetre << endl;
  cout << "La surface est de: " << surface << endl;

}

float TTriangle::CalculerSurface()
{
      surface = 1/2 (base * hauteur);

      return (surface);
}

float TTriangle::CalculerPerimetre()
{
      perimetre = base + hauteur + cote;

      return (perimetre);

}


class TEllipse: public TFigure
       {
            protected:
                  float a;
                  float b;

            public:
                  TEllipse() {};
                  void Lire();
                  void Afficher();
                  float CalculerSurface();
                  float CalculerPerimetre();

       };

void TEllipse::Lire()
{
      clrscr();
      cout << "Entrez la dimansion du cote A: ";
      cin >> a;
      cout << endl;
      cout << "Entrez la dimension du cote B: ";
      cin >> b;

}

void TEllipse::Afficher()
{
      clrscr();
      cout << "La dimension du cote A est de: " << A << endl;
      cout << "La dimension du cote B est de: " << B << endl;
      cout << "Le perimetre est de: " << perimetre << endl;
      cout << "La surface est de: " << surface << endl;
}

float TEllipse::CalculerSurface()
{
      surface = Pi * a * b;

      return (surface);

}

float TEllipse::CalculerPerimetre()
{
      perimetre = 2 * Pi ( sqrt(1/2 * ( (a * a) + (b * b) ) ) );

      return (perimetre);
}


class TCercle: public TFigure
       {
       protected:
              float rayon;

       public:
              TCercle() {};
              void Lire();
              void Afficher();
              float CalculerSurface();
              float CalculerPerimetre();

       };

void TCercle::Lire()
{
      clrscr();
      cout << "Entrez le rayon du cercle: ";
      cin >> rayon;

}

void TCercle::Afficher()
{
      clrscr();
      cout << "Le rayon du cercle est de: " << rayon << endl;
      cout << "Le perimetre du cercle est de: " << perimetre << endl;
      cout << "La surface du cercle est de: " << surface << endl;

}

float TCercle::CalculerSurface()
{
      surface = Pi * ( rayon * rayon );

      return (surface);
}

float TCercle::CalculerPerimetre()
{
      perimetre = 2 * Pi * rayon;

      return (perimetre);
}

class TLosange: public TFigure
       {
       protected:
              float Diagonale;
              float diagonale;

       public:
              TLosange() {};
              void Lire();
              void Afficher();
              float CalculerSurface();
              float CalculerPerimetre();

       };

void TLosange::Lire()
{
      clrscr();
      cout << "Entrez la dimension de la grande diagonale: ";
      cin >> Diagonale;
      cout << endl;
      cout << "Entrez la longueur de la petite diagonale: ";
      cin >> diagonale;

}

void TLosange::Afficher()
{
      clrscr();
      cout << "La dimension de la grande diagonale est de: " << Diagonale << endl;
      cout << "La dimension de la petite diagonale est de: " << diagonale << endl;
      cout << "Le perimetre du losange est de: " << perimetre << endl;
      cout << "La surface du losange est de: " << surface << endl;

}

float TLosange::CalculerSurface()
{
      surface = Diagonale * diagonale;

      return (surface);
}

float TLosange::CalculerPerimetre()
{
      perimetre =

}
*/

void Afficher_Menu()
{
      clrscr();

      /* Afficher le menu des figures */
      cout << "1- Rectangle " << endl;
      cout << "2- Carre " << endl;
      cout << "3- Triangle " << endl;
      cout << "4- Ellipse " << endl;
      cout << "5- Cercle " << endl;
      cout << "6- Losange " << endl;
      cout << endl << endl;
      cout << "0- Quitter ";
      cout << endl << endl;

}

void Quitter()
{
      clrscr();
      gotoxy(15,12);
      cout << "Ce programme vous a ete presenter par Sebastien Bigras";
}

void main (void)
{
      /* Definir une variable pointeur de la classe figure */
      TFigure *Figure;

      /* definir les variables */
      int choix = 1; // Pour retourner le choix de la figure

      /* Afficher le menu et demander le type de figure */
      while(choix != 0)
      {
      clrscr();
      Afficher_Menu();
      /* Entrez le choix de l'usager */
      cout << "Entrez votre choix: ";
      cin >> choix;

      switch (choix)
      {
            case 1:      Figure = new TRectangle;
                              break;

            case 2:  Figure = new TCarre;
                              break;

/*            case 3:      Figure = new TTriangle;
                              break;

            case 4:      Figure = new TEllipse;
                              break;

/*            case 5:      Figure = new TCercle;
                              break;

            case 6:      Figure = new TLosange;
                              break;
*/
            case 0:      Quitter();
                              break;

            default: cout << "Vous avez fait un choix invalide !";
                              getch();
                              break;
      }

      if( ((choix>=1) && (choix <= 6)) && (Figure != NULL) )
            {
            /* Identification */
            /* Description */
            Figure -> Lire();
            Figure -> CalculerPerimetre();   /* Calculer la surface de la figure */
            Figure -> CalculerSurface();     /* Calculer le perimetre de la figure */
            Figure -> Afficher();            /* Afficher les resultats */
      // Liste.Add(Figure);                              /* Ajouter la figure a la liste */
            getch();
            }

 } // fin de while choix != 0

} // fin du main

0
 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
A description in English of what the program is supposed to do and what is ACUTALLY happenning that makes you think there is a bug would be a help !!

Roger

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
After having a read though (and with my poor knowledge of French) the code looks OK (nothing stands out as obvious).

What problem are you having?

0
 
LVL 2

Expert Comment

by:AlFa
Comment Utility
Quel est le problème?
(il y a un français dans la salle)
0
 

Author Comment

by:Vampire
Comment Utility
Alfa: Quand je run le programme, il bloque sur les float de la classe TEllipse, TTriangle...pourtant elle sont identiques aux autres....
0
 
LVL 2

Accepted Solution

by:
AlFa earned 50 total points
Comment Utility
modifications apportées

#define Pi  3.1416
il ne faut pas de = (ce n'est pas du pascal)




float TTriangle::CalculerSurface()
{
      surface = 1.0 / 2.0 * (base * hauteur); /* la multiplication n'est pas implicite; 1/2 ==> division entière (résultat 0 */
      return (surface);
}

void TEllipse::Afficher()
{
      clrscr();
      cout << "La dimension du cote A est de: " <<a << endl;  /* le C(++) est case sensitive => A n'est pas a */
      cout << "La dimension du cote B est de: " << b << endl;
      cout << "Le perimetre est de: " << perimetre << endl;
      cout << "La surface est de: " << surface << endl;
}

float TEllipse::CalculerPerimetre()
{
perimetre = 2 * Pi *( sqrt(1.0/2.0 * ( (a * a) + (b * b) ) ) );
/* même remaque que pour triangle */
return (perimetre);
}
/*.....*/      
     
TFigure *Figure = NULL;  /* pour ne pas planter au 1er tour */

/* definir les variables */
int choix = 1; // Pour retourner le choix de la figure

/* Afficher le menu et demander le type de figure */
while(choix != 0)
{
      clrscr();
      Afficher_Menu();
      /* Entrez le choix de l'usager */
      cout << "Entrez votre choix: ";
      cin >> choix;
      
      if(Figure!=NULL) delete Figure;  /* il faut déalouer la mémoire */

0
 

Author Comment

by:Vampire
Comment Utility
Thanks folks!! Merci!! :))
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now