Solved

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

Posted on 1997-12-11
9
193 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
ID: 1175891
Not without knowing what the program is or what it does wrong.
0
 

Expert Comment

by:miredo
ID: 1175892
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
ID: 1175893
/* 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1175894
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1175895
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
ID: 1175896
Quel est le problème?
(il y a un français dans la salle)
0
 

Author Comment

by:Vampire
ID: 1175897
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
ID: 1175898
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
ID: 1175899
Thanks folks!! Merci!! :))
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 67
Getting IP address 8 79
object oriented programming comparison 5 71
Embarcadero C++ Builder XE10.1 Berlin red arrow Indicator 2 36
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 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