Hi, I successfully made my first programme with a CLASS. The code is separated by main.cpp / Fusee.cpp / Fusee.h. Now I want to had a function f.allume(); int eh main.cpp. Basicaly the function is suppose to ignite a rocket for take off. So the only thing the function should do is to change this display / \ to /WW\
#include <ostream>
#include <string>
#ifndef FUSEE_H
#define FUSEE_H
using std::ostream;
class Fusee
{
int m_numEtage;
int nLargeur;
int nHauteur;
public:
Fusee(int numEtage);//constructor qui ressoit le nombre d'étage de la fusée
void largeur(int nLargeur);//nouvelle largeur d'un étage
void hauteur(int nHauteur);//nouvelle hauteur d'un étage
void allume();
void dessinerFusee(ostream& out, Fusee& f);
friend ostream& operator<<(ostream& out, Fusee& f);
};
#endif
Fusee::Fusee(int numEtage)
{
nLargeur = 8;
nHauteur = 4;
m_numEtage = numEtage;
}
void Fusee::largeur(int largeur)
{
nLargeur = largeur;
}
void Fusee::hauteur(int hauteur)
{
nHauteur = hauteur;
}
void Fusee::allume()
{
}
void Fusee::dessinerFusee(ostream& out, Fusee& f)
{
int i, j, k = 0;//////////////debut affichage CARGO
for (i = 1; i <= nHauteur; i++) // lignes
{
out << " ";
// Esapces du milieu
for (j = i; j <= nHauteur; j++)
{
out << " ";
}
// affiche des /
while (k != (2 * i - 1))
{
if (k == 0 )
{
out << "\/";
}
else
{
out << " ";
}
if (k == 2 * i - 2)
{
out << "\\";
}
k++;
;
}
k = 0;
out << endl; // prochaine ligne
}
// affiche la derniere ligne du CARGO
out << " ";
out << "\/";
for (i = 0; i < 2 * nHauteur; i++)
{
out << "_";
}
out << "\\";
out << endl;//////////////fin de l'affichage du CARGO
for (int i = 0; i < m_numEtage; i++)//////////////début affichage du RÉSERVOIR
{
for (int i = 1; i < nHauteur; i++)
{
out << " ";
out << "|";
for (int j = 0; j < nLargeur; j++)
{
out << " ";
}
out << "|\n";
}
out << " ";
out << "|";
for (int i = 1; i <= nLargeur; i++)
{
out << "_";
}
out << "|";
out << "\n";
}
}
ostream& operator<<(ostream& out, Fusee& f)
{
f.dessinerFusee(out, f);
return out;
}
You have to call the function somewhere. If not in main, you need to call it from something called by main.
You can do weird stuff that would avoid an explicit call -- like calling it from the constructor or having an event driven program of some sort --- but calling it from the constructor is not a good design for this, and the other ways to do it are advanced and use nonstandard language extensions.