Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 19/09/2008, à 17:19

suez

compilation + affichage

bonsoir à tous,

je commence à apprendre le c++ dont les classes,
lorsque je compile et execute il ne m affiche rien:

merci d avance


thomas@thomas-laptop:~/C++$ g++ test.cxx -o test.o
Dans le fichier inclus à partir de /usr/include/c++/4.2/backward/iostream.h:31,
          à partir de test.cxx:2:
/usr/include/c++/4.2/backward/backward_warning.h:32:2: attention : #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
thomas@thomas-laptop:~/C++$ test
thomas@thomas-laptop:~/C++$

voici mon code source:

#include<stdlib.h>
#include<iostream.h>

class eleve
{
    private:
	char * nom;
	char *prenom;
	char classe;
	float pnt1;
	float pnt2;
	float pnt3;
    public:
	eleve(void);//constructeur
	~eleve();//destructeur
	char * getNom();
	char *getPrenom();
	char getClasse();
	void setPnt1(float a);
	void setPnt2(float a);
	void setPnt3(float a);
	float getPnt1();
	float getPnt2();
	float getPnt3();
	float moyenne(float a, float b, float c);
	void affiche();
};

eleve::eleve(void)
{
	nom=new char[1];
	nom='\0';
	prenom=new char [1];
	prenom='\0';
	classe='X';
	pnt1=pnt2=pnt3=0;
	cout<<"constructeur:ok"<<endl;
}

eleve::~eleve()
{
	if(nom)
	{
		cout<<"le destructeur a detruit: "<<nom<<prenom<<endl;
		delete nom;
		delete prenom;
	}
}

char * eleve::getNom(){return nom;}
char * eleve::getPrenom(){return prenom;}
char eleve::getClasse(){return classe;}

void eleve::setPnt1(float a)
{
	pnt1=a;
}

void eleve::setPnt2(float a)
{
	pnt2=a;
}

void eleve::setPnt3test(float a)
{
	pnt3=a;
}

float eleve::getPnt1(){return pnt1;}
float eleve::getPnt2(){return pnt2;}
float eleve::getPnt3(){return pnt3;}
float eleve::moyenne(float a, float b, float c){return ((a+b+c)/3);}
void eleve::affiche()
{
	cout<<"nom: "<<getNom()<<endl;
	cout<<"prenom: "<<getPrenom()<<endl;
	cout<<"classe: "<<getClasse()<<endl;
	cout<<"interro_1: "<<getPnt1()<<endl;
	cout<<"interro_2: "<<getPnt2()<<endl;
	cout<<"interro_3: "<<getPnt3()<<endl;
	cout<<endl<<"moyenne: "<<moyenne(pnt1, pnt2, pnt3)<<endl;
}

int main()
{
	cout<<"constructeur + affichage"<<endl<<endl;
	eleve ele;
	ele.affiche();
	return 0;
}

Hors ligne

#2 Le 19/09/2008, à 18:26

suez

Re : compilation + affichage

Quelqu'un aurait il une solution a mon probleme?merci

Hors ligne

#3 Le 19/09/2008, à 19:28

telliam

Re : compilation + affichage

dans ta ligne de compilation ton exécutable s'appelle test.o et non pas test.
pour info le mot clé 'test' est aussi une commande built-in du shell c'est pour ça qu'il ne t'indique pas qu'il ne trouve pas ton executable.


"- Un intellectuel assis va moins loin qu'un con qui marche."
Maurice Biraud - Un Taxi pour Tobrouk
Michel Audiard

Hors ligne

#4 Le 19/09/2008, à 21:12

tiky

Re : compilation + affichage

Et pour retirer le warning à la compilation remplace:

#include <iostream.h>

par

#include <iostream>

Conseil d'expert: il vous faut un dentifrice adapté...

Hors ligne