Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Corriges Divers TD TP GI 2012

# Corriges Divers TD TP GI 2012

Ratings:
(0)
|Views: 1,432|Likes:

### Availability:

See more
See less

09/27/2013

pdf

text

original

ENSEM Le 05/04/2012Deprt MATHS & INFO CORRIGE C++/POO 1
ière
GIMme OUAZZANI F.Z
Série de TD n°1 C++/POO
Exercice I
/* fichier header file t_date.h */ #include<iostream.h>class t_date{ private :int j;int m;int a;public:void init_date(int, int, int);void affiche_date(void);}; /* fichier source c++ date.cpp */ #include<iostream.h>#include<conio.h>#include"t_date.h"void t_date ::init_date(int jour, int mois, int an){ j=jour;m=mois;a=an;}void t_date::affiche_date(void){ cout<<" la date entree est : "<<j<<" / "<<m<<" / "<<a;}
int main(void){ t_date dat;dat.init_date(20,2,2012);dat.affiche_date();getch();}

Exercice II
#include<iostream.h>#include<conio.h>class pointt{ int x, y ;public :void initialise(int ,int);void deplace(int, int);void affiche();};void pointt::initialise(int abs, int ord){ x=abs; y= ord;}void pointt::deplace(int dx, int dy){ x += dx ; y+= dy ;}void pointt::affiche(void){ cout<<"je suis en ( "<<x<<" , "<<y<<" )" ;cout<<endl;}int main(void){ pointt a, b;a.initialise(1,4);a.affiche();a.deplace(3,2);a.affiche();getch();b=a;b.deplace(5,4);b.affiche();getch();}
Exercice II-1
/* fichier header pointt.h */ #include<iostream.h>#include<conio.h>class pointt{ int x, y ;public :void initialise(int ,int);void deplace(int, int);void affiche();};void pointt::initialise(int abs, int ord){ x=abs; y= ord;}void pointt::deplace(int dx, int dy){ x += dx ; y+= dy ;}void pointt::affiche(void){ cout<<"je suis en ( "<<x<<" , "<<y<<" )" ;cout<<endl; } /* pointt1.cpp */ #include<conio.h>#include"pointt.h"void test(void){pointt u;u.initialise(1,4);u.affiche();u.deplace(3,2);u.affiche();}
int main(void){ test();getch();}Exercice II-2
/* fichier header pointt.h */ #include<iostream.h>#include<conio.h>class pointt{ int x, y ;public :void initialise(int ,int);void deplace(int, int);void affiche();};

ENSEM Le 05/04/2012Deprt MATHS & INFO CORRIGE C++/POO 1
ière
GIMme OUAZZANI F.Zvoid pointt::initialise(int abs, int ord){ x=abs; y= ord;}void pointt::deplace(int dx, int dy){ x += dx ; y+= dy ;}void pointt::affiche(void){ gotoxy(x,y);cout<<"je suis en ( "<<x<<" , "<<y<<")"<<endl; } /* pointt2.cpp */ #include<iostream.h>#include<conio.h>#include"pointt.h"void test(pointt &u){u.initialise(1,4);u.affiche();u.deplace(3,2);u.affiche();}
int main(void){ pointt a;test(a);getch();}Exercice II-3
/* fichier header pointt.h */ #include<iostream.h>#include<conio.h>class pointt{ int x, y ;public :void initialise(int ,int);void deplace(int, int);void affiche();};void pointt::initialise(int abs, int ord){ x=abs; y= ord;}void pointt::deplace(int dx, int dy){ x += dx ; y+= dy ;}void pointt::affiche(void){ cout<<"je suis en ( "<<x<<" , "<<y<<" )" ;cout<<endl; } /* pointt3.cpp */ #include<conio.h>#include"pointt.h"pointt test(void){ pointt u;u.initialise(1,4);u.affiche();return(u); }
int main(void){ pointt v;v=test();v.deplace(3,2);v.affiche();getch();}Exercice II-4
/* heather file modifie pointt.h */ #include<iostream.h>#include<conio.h>class pointt{ int x, y ;public :pointt();pointt(int ,int);~pointt();void deplace(int, int);void affiche();};pointt::pointt(void){ x=1 ; y= 1; }pointt::pointt(int abs, int ord){ x=abs; y= ord;}pointt::~pointt(){ cout<<" votre programme est termine !! abientot ";}void pointt::deplace(int dx, int dy){ x += dx ; y+= dy ;}void pointt::affiche(void){ cout<<"je suis en ( "<<x<<" , "<<y<<" )" ;cout<<endl; } /* pointt4.cpp */ #include<iostream.h>#include<conio.h>#include"pointt.h"
int main(void){ pointt a(1,4);pointt b;a.affiche();a.deplace(3,2);a.affiche();getch();b=a;b.deplace(5,4);b.affiche();getch();}

ENSEM Le 05/04/2012Deprt MATHS & INFO CORRIGE C++/POO 1
ière
GIMme OUAZZANI F.Z
Exercice IIIExercice IV
#include<iostream.h>#include<conio.h>#include<stdio.h>class date{ private:int j;int m;int an;public :date(){j=1 ; m=1 ; an= 2011 ;}date(int, int, int) ;date(int jj, int mm) {j=jj ; m=mm ; an=0 ;}date(int z) { j=z ; m=3 ; an=2011 ;}void saisie(){ cout<<endl<<endl<<"entrez la date jj mmaa : " ;cin>>j>>m>>an;}int bissextile();date lendemain();void affiche(){ cout<<"\n\n\t"<<j<<" / "<<m<<" / "<<an; } //destructeur montrant l ordre de destructiondes objets~date(){ cout<<"\n\tdestruction de l objet";affiche();getch();} };int k;date::date(int jj, int mm, int aa){ j=jj; m= mm; an= aa ;}int date::bissextile(){ if(((an%4==0) &&(an%100!=0))||(an%400==0))return(1);else return(-1); }date date::lendemain(){ date t;if(m==3 || m==5 || m==7 || m==8 || m==10){ if ( j==31){ t.j=1; t.m=m+1;t.an=an;}else {t.j = j+1; t.m=m; t.an=an;}}else { if( m==4 || m==6 || m==9 || m==11){ if(j==30){ t.j=1; t.m= m+1 ; t.an=an;}else {t.j= j+1 ;t.m=m; t.an=an;}}else {if(m==12){ if(j==31){ t.j=1; t.m=1; t.an=an+1;}else {t.j=j+1; t.m=m; t.an=an;}}else { if(m==2){ if(k==1) // annee bissextile{ if(j==29){t.j=1; t.m=m+1; t.an=an;}else {t.j=j+1; t.m=m; t.an=an;}}else if(j==28) //non bissextile{t.j=1; t.m=m+1; t.an=an;}else{t.j=j+1; t.m=m; t.an=an;}} } } }return(t);}void main(){ date d;date x(15) ;date y(6, 7, 2010) ;char choix;do{ d.affiche() ; x.affiche() ; y.affiche() ;d.saisie();k=d.bissextile();if( k==1)cout<<" \ncette annee est bissextile\n";elsecout<<" \ncette annee est nonbissextile\n";x=d.lendemain();cout<<" \n\nla date aujourdhui est : \n\n";d.affiche();cout<<"\n la date du lendemain est :\n\n ";x.affiche();cout<<endl<<endl<<"\n\nvoulez voussaisir une autre date O/N : ";fflush(stdin);cin>>choix ;}while(choix=='O');getch();}