#1 

03-08-2007 07:22:01

simpat
Membres
Date d'inscription:
Messages: 2
IP: 41.205.21.194
Courriel

bonjour,

je suis etudiant en genie informatique/ genie logiciel à Laval. je suis encore
debutant sur le c++. je vous en prie j'ai un probleme. j'ai un exercice qui me
casse la tete. il s'agit en fait de deux main deja implementé et qu'il ne faut
pas du tout modifier. tu dois enfait te servir des affichages et du main pour
implementer les fichiers .h et . cpp que tu aura jugé par toi meme
indispensable pour l'affichage.

voici le premier main:



#include "Dessin.h"
#include <iostream>
using namespace std;
main()
{
Dessin bonhomme(20,30);
bonhomme(6 ,25) = 'O';
bonhomme(14,25) = 'O';
bonhomme(10,15) = 'V';
bonhomme(4 ,6 ) = '\\\\';
bonhomme(16,6 ) = '/';
bonhomme(5 ,5 ) = '\\\\';
bonhomme(15,5 ) = '/';
for(int i=6;i<=14;i++) bonhomme(i,5) = '_';
cout << bonhomme;
return 0;
}


on devrai avoir cet affichage:






O O









V








\\ /
\\_________/






voici le deuxieme main:


#include "Graphe.h"

#include <iostream>

using namespace std;

main()
{
Graphe a(50,30);
Dessin &d = a; // Ceci est juste pour vérifier que vous avez
// bel et bien dérivé Graphe de Dessin.
a.cercle(15,15,14,'a');
a.cercle(15,14,12,'b');
a.cercle(15,13,10,'.');
a.cercle(15,12,8,'!');
a.cercle(15,11,5);
a.cercle(15,10,2);

a.rectangle(40,0,49,9);
a.ligne(40,0,49,9);
a.ligne(49,0,40,9);

cout << a;
return 0;
}



on devrai avoir aussi cet affichage:



aaaaaaa
aaa aaa
aa aa
aa bbbbbbb aa
a bbb bbb a
a bb bb a
aa b ....... b aa
a b ... ... b a
a bb .. .. bb a
a bb . !!!!! . bb a
a b . !! !! . b a
a b . ! ! . b a
a bb . ! ! . bb a
a b .. ! ..... ! .. b a
a b . ! .. .. ! . b a
a b . ! . . ! . b a
a b . ! .. .. ! . b a
a b . ! . ... . ! . b a
abb. ! . .. .. . ! .bba
a b..! . . . . !..b a
a b . ! .. .. .. .. ! . b a ..........
abb. ! . ... . ! .bba .. ..
aabb. ! .. .. ! .bbaa . . . .
a b . ! ..... ! . b a . . . .
a b ..!! !!.. b a . .. .
aabb...!!!!!...bbaa . .. .
aabbb.......bbbaa . . . .
aaabbbbbbbaaa . . . .
aaaaaaa .. ..
..........




voici ce que j'ai fais pour le premier main:



*********************************fichier Dessin.h *************************



#include<iostream>

class Dessin {
private:
char * tableau;
unsigned int width, height;

public:
Dessin(unsigned int x, unsigned int y); // taille du dessin
~Dessin();

char& operator() (unsigned int row, unsigned int col); // surcharge de
l'opérateur //() pour faire : //"bonhomme(6 ,25) = 'O';"
char operator() (unsigned int row, unsigned int col) const;


// pour faire "cout << bonhomme;"
friend std::ostream& operator<<(std::ostream &os, const Dessin &dessin);

};








********************************fichier Dessin.cpp***************************




#include<iostream>
#include"Dessin.h"



Dessin::Dessin(unsigned int x, unsigned int y):tableau(NULL), width(x),
height(y)
{
tableau = new char[width*height];
memset(tableau, 0, sizeof(char)*width*height);
}





Dessin::~Dessin()
{

if(tableau)
{
delete [] tableau;
tableau = NULL;
}
}



char& Dessin::operator() (unsigned int row, unsigned int col)
{
return tableau[col*width+row];
}




char Dessin::operator() (unsigned int row, unsigned int col) const
{
return tableau[col*width+row];
}



std::ostream& operator<<(std::ostream &os, const Dessin &dessin)
{
for(unsigned int j=dessin.height-1;j>0;j--)
{
for(unsigned int i=0;i<dessin.width;i++)
os << dessin(i, j);
os << std::endl;
}
os << std::endl;

return os;
}




tout marche bien main le deuxieme main me bloque. il s'agit de l'affichage d'un
cercle dont les parametres sont, les cordonnees du centre, le rayon et le
caractere pour le dessin. pouvez vous m'aider?

merci


Hors ligne


#2 

06-08-2007 07:08:58

simpat
Membres
Date d'inscription:
Messages: 2
IP: 41.205.21.194
Courriel

mon probleme en fait c'est la methode cercle. qu'est ce qu'elle doit retourner? comment devrai je l'implementer?

merci


Hors ligne


#3 

06-08-2007 13:57:05

izguit
Administrateurs
Avatar de izguit
Date d'inscription:
Messages: 306
IP: 83.154.10.34
Courriel  Site web

Yop,
Içi tu es sur un forum irrlicht et là il y a pas un brin de 3D smile Donc postes plutôt sur un forum C++ (developpez.net ou cppfrance.com par ex.)
A part ça je vois pas trop ce que t'arrives pas à faire
Mais à première vue la méthode cercle doit faire un style de :

if ((x-xCentre)²+(y-yCentre)² == rayon²)
    tableau[x][y]  = caractere

(cf équation de cercle et produit scalaire)
Le tout dans une boucle itérative

Mais par pitié poste sur un forum C++ smile


Athlon 64 3000+ // 1Go RAM // Geforce 6600GT 128Mo
Turion 64 X2 // 1Go RAM // ATI X1250

Hors ligne


Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
154 invités en ligne
membre en ligne: -
RSS Feed