Vous êtes sur la page 1sur 3

Cours c++

#include <iostream>

#include <iomanip>

using namespace std;

struct point{ /* déclaration "classique" des données */

int x , y ;

/* déclaration des fonctions membres (méthodes) */

void intialise (int, int) ;

void deplace (int, int) ;

void affiche () ;

};

void point::intialise (int abs,int ord){

x= abs ;

y= ord ;

void point:: deplace (int dx, int dy){

x+=dx;

y+=dy;

void point:: affiche(){

cout<< "Je suis en " << x << " " << y << "\n" ;

/* run this program using the console pauser or add your own getch, system("pause") or input loop
*/

int main(int argc, char** argv) {

struct point p1;


p1.intialise(5,2);

p1.affiche();

return 0;

Les classe :
#include <iostream>

#include <iomanip>

using namespace std;

class point {

private :

int x ;

int y ;

public :

void intialise (int, int );

void deplace (int, int);

void affiche ();

int Getx();

void Set (int val);

void Sety (int b){

y=b;

};

void point::intialise(int abs,int ord)

x=abs;

y=ord;

void point::deplace(int dx, int dy){

x=x+dx;

y=y+dy;
}

int point::Getx(){

return x;

void point::Set(int v){

x=v;

void point::affiche(){

cout << "Je suis en " << x << " " << y << "\n" ;

main (){

point a, b ;

a.intialise (5, 2) ; a.affiche () ;

a.deplace (-2, 4) ; a.affiche () ;

b.intialise (1,-1) ; b.affiche () ;

b.Set(8);

cout<<a.Getx();

Vous aimerez peut-être aussi